Currency Converter - Auto Update FX Rates

Hi all,

I’m having ongoing issues with making HTTP requests in SugarCRM for a custom package that updates currency rates. Below is a summary of what I’ve tried and the problems I’ve encountered. I’m looking for advice on what’s permissible or alternative approaches within Sugar's environment.

I Created the module in Sugar and added 3 currencies: dollars, pounds and euro. Dollars is set to my base currency and ive entered incorrect values to the conversion rate field for euro and pounds hoping it will update when the scheduler runs but nothing changes.

Attempts Made:

  1. Initial Attempt with ExternalResourceClient:

    • I started with Sugar's built-in ExternalResourceClient for making HTTP requests. However, it wasn’t reliable, and data fetching failed intermittently.
  2. Switch to Guzzle HTTP Client:

    • I moved to Guzzle due to its robust HTTP handling capabilitie
    • Code:
      php
      use GuzzleHttp\Client; class CurrencyUpdater { private $client; public function __construct() { $this->client = new Client(['timeout' => 10.0]); } public function updateCurrencyRates() { $response = $this->client->request('GET', 'https://example.com/api'); // Additional code to process response } }
    • Issues Faced:
      • Errors from SugarCloud due to denylisted functions (fwrite, curl_*, etc.).
      • Despite attempts to restructure the package and adhere to Sugar policies, Guzzle files were consistently blocked.
  3. Switch Back to SugarHttpClient:

    • I reverted to using SugarHttpClient in hopes it would bypass the restrictions.
    • Code:
      php
      use Sugarcrm\Sugarcrm\Util\SugarHttpClient\SugarHttpClient; class CurrencyUpdater { private $client; public function __construct() { $this->client = new SugarHttpClient(); } public function updateCurrencyRates() { $response = $this->client->get('https://example.com/api', ['headers' => ['Accept' => 'application/json']]); // Additional code to process response } }
    • Issues Faced:
      • Still experiencing challenges in getting a consistent and reliable response from the API.

Summary of Challenges:

  • Encountered policy restrictions on SugarCloud that prevented using common HTTP request libraries.
  • Frequent issues with denylisted functions, blocked file types, and unauthorized autoload methods.
  • Adjustments to the package structure did not resolve the core issues, and error handling remains a significant challenge.

I’m looking for guidance on:

  • SugarCRM-approved methods for making HTTP requests.
  • Any way to configure Guzzle or another library within Sugar’s allowed parameters.
  • Recommendations on reliable HTTP client usage within Sugar’s constraints.

I have attached the files and folder structure I've been using.SugarClub_CurrencyConverterV1.zip

Thanks in advance for your help! Any suggestions or insights would be greatly appreciated.

Parents Reply Children
No Data