Skip to content
Issues with Accessing a Remote API in Drupal7
August 08 2018

Recently, we ran into a bizarre issue with a Drupal7 installation that we work on, but don’t fully control. A module was pulling a remote JSON API and presenting it inside the Drupal application. To retrieve the API, we were using drupal_http_request. Things were fine until the response of the API grew in size. (And not to a large size. The issue appeared when there were about 15 records returned.) At this point, all of the JSON wasn’t returned by the http request. Then, the text that was available wasn’t valid JSON, and the information display failed. This issue only appeared on the staging and production systems, which made debugging difficult.

After some troubleshooting, the best fix was determined to be a workaround. Rather than continuing to use drupal_http_request, the code was modified to use the php function curl_exec. This didn’t have issues in the remote environments, and all the JSON was retrieved, even for the problematic large requests.

There are a couple of takeaways from this experience.

  • Sometimes the perfect is the enemy of the good. Yes, it would have been preferable to solve the issue at the root level and continue to use the drupal API. But the workaround was just as effective in solving the problem and more time efficient.
  • Software is more than just the code you write. The environment in which it executes fundamentally affects the software, often in subtle ways.
  • You should have a staging system that is as close as possible to your production system in every way. Without that, some issues will simply have to be debugged on your production systems, which is not kind to your reputation nor to your users.

Culture Foundry is a digital experience agency that helps our clients elevate their impact with beautiful technology. We provide the expertise and insight at every layer that makes a great digital experience for websites and applications possible. If you're committed to elevating your digital experience, contact us and we'd be happy to schedule a chat to see if we're a fit.

(Psst! We also happen to be a great place to work.)

Back To Top