Search code examples
phpjsonheaderhttp-headersapi-key

I am trying to pass the headers into my HTTP get Json request. the api key documentation has given me a format for the api key


This is their format:

 response = requests.get(PAPERQUOTES_API_ENDPOINT, headers= 
 {'Authorization': 'TOKEN {}'.format(TOKEN)})

And now this is mine, I need to make it equivalent somehow (except I'm not sure what is being implied by the brackets and the function format):

$headers = array(
'Authorization: ' . 
'keyid' . 
 '{}.format(keyid' .
   'keyid)',
'Content-Type: application/json',

);

I'm almost sure that there should be some sort of variable creation and method call. Don't know exactly what is needed. Need to translate the first code into my personal second one.

Thanks for any help.


Solution

  • You are trying apply Python code as PHP code, check PHP example above in PaperQuotes API Documentation.

    Your code should be:

    $token = 'yourTokenHere-asfjaieuhkjhdfkjhaslkgjhaksdgj';
    $headers = array(
     "Authorization: Token $token",
     'Content-Type: application/json',
    );
    

    But documentation using custom pseudo-marking code for token variable which is not precise, maybe right variant is:

    "Authorization: Token {{$token}}",
    

    Just try it.