You are here:  » API Feeds That Require API Key in Header Request


API Feeds That Require API Key in Header Request

Submitted by ItsDavid on Tue, 2016-04-05 22:59 in

I have a lot of feeds that i retrieve using API calls and parameters in the URL however, There are a few of my feeds that require that API key to be in the header request and i don't see a way to add the header request when adding a new API feed in the admin panel.

Thanks for any help with this.

Submitted by support on Wed, 2016-04-06 08:24

Hi David,

CURL supports the inclusion of headers in an HTTP request, and a simple format can be derived allowing you to pass in a list of headers after the URL.

First make sure that you are using CURL as your automation handler by changing line 43 of config.advanced.php as follows;

  $config_automationHandler = "curl";

Next, edit includes/automation.php and look for the following code at line 143:

    $ch = curl_init($src);

...and REPLACE with:

    $headers = explode("%HEADER%",$src);
    $src = array_shift($headers);
    $ch = curl_init($src);
    if (count($headers))
    {
      curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
    }

Then to include headers in the request made by an Automation Tool job, include the headers following the URL separated with %HEADER% for example:

http://api.example.com/getFeed?id=1234&aff=5678%HEADER%X-Token: ABCDEFG%HEADER%X-Key: 987654

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ItsDavid on Wed, 2016-04-06 14:09

This works like a charm.

Thank You.

Submitted by augirl on Wed, 2016-06-22 03:41

Hi David

You say First make sure that you are using CURL. Wwhat is curl and how do you know you are using it or not.

Thank you
Annette

Submitted by support on Wed, 2016-06-22 08:42

Hello Annette,

For running Automation Tool jobs, the script has the option to use either PHP's internal file handling functions, (e.g. fopen), or the CURL library, which is not a core part of PHP but is included in most installations. CURL provides more flexibility in making the request, such as in this case the ability to include headers.

There is a setting in config.advanaced.php at line 43 which determines which method to use;

  $config_automationHandler = "auto";

"auto" is the default option and will use CURL if available however you can also specify "php" or "curl", so to use the above modification with headers you can force CURL using:

  $config_automationHandler = "curl";

Cheers,
David.
--
PriceTapestry.com