api integration php curl

12,762

HTTP headers need to be specified using a colon as the separator between the key and the value, not an equal sign. Try this:

$header = array('Content-Type: application/xml', 'API-KEY: 1a2b3c4d5e6f7g8h9i', 'API-LOGIN: 1a2b3c4d5e6f7g8h9i');
Share:
12,762
spiderling
Author by

spiderling

Updated on June 29, 2022

Comments

  • spiderling
    spiderling almost 2 years

    I am trying to integrate an API, and in the API integration instructions it shows the following:

    GET /offers.json or /offers.xml
    Headers: API-KEY={your_key}, API-LOGIN={your_login}
    

    CURL Example:

    curl https://api.thewebsite.com/v1/offers.json -H 'API-KEY:
    1a2b3c4d5e6f7g8h9i' -H 'API-LOGIN: 1a2b3c4d5e6f7g8h9i'
    

    I've tried using the cURL code below without success. As for the GET method, I'm not sure how to pass the API KEY & API LOGIN as headers.

    $header = array('Content-Type: application/xml', 'API-KEY=1a2b3c4d5e6f7g8h9i', 'API-LOGIN=1a2b3c4d5e6f7g8h9i');
    $url = "https://api.thewebsite.com/v1/offers.xml";
    
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    $xml = curl_exec($curl);
    curl_close($curl);
    
    print $xml;