Api-Key header not supported for getting an icon by id?


#1

I try to get an icon by ID using the description from https://developers.icons8.com/docs/icons#get-publicApi-icons
For searching I use the “Api-Key” header, but that doesn’t seem to work when getting an icon. If I add the API key as “token” to the URL it works fine.

Any reason why this is not supported for icons?

Thanks
Daniel


#2

Could you please clarify which of the following methods is not working for you? If you want to use the first method, you need to include your API key in your request as well.

image

Maybe you could give us an example of a failed request? That would be great.


#3

Here is a simplyfied PHP script:

<?php

function getIcon($id) {
    $url = "https://api-icons.icons8.com/publicApi/icons/icon?id=" . $id;

    //  If I pass this token parameter, it works.
    //  $url .="&token=MY_API_KEY";

    // create curl resource
    $cURL = curl_init();

    // set url
    curl_setopt($cURL, CURLOPT_URL, $url);

    // add the authorization header
    // This doesn't work for getting an icon but works for searches
    curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Api-Key: MY_API_KEY'));

    //return the transfer as a string
    curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);

    // $output contains the output string
    $output = curl_exec($cURL);

    // close curl resource to free up system resources
    curl_close($cURL);     

    return $output;
}

header('Content-Type: application/json');
echo getIcon(80624);

?>

#4

Hi! Please contact our support. You have a problem with your API key, probably.


#5

Hmm… that does not make much sense to me.
If my API key works when used as “token” in the a GET parameter but does not when used as “Api-Key” in the header, my key seems to be fine. And as all other API request work with the “Api-Key” header only, but not in the “icon” route, I think this is an issue with the API.

As I can use the token argument and get what I want, I have a working solution. I just wanted to point you to a probably missing or broken implementation or documentation and that I would prefer using the new header authorization only.

Cheers
Daniel


#6

It was hard to find your real account and token, but we fixed it, now you can use both query or header param :slight_smile: check it, please.


#7

Works. Thanks a lot!