1
  1. I have to get the token by sending a request to a specified address. I used

    $ curl $ curl -XPOST -H "Content-Type: application/json" -d '{ "client_id": "xxx", "client_secret": "11111111", "grant_type": "client_credentials", "scope": "public" }' "https://example.com/auth/token"
    
  2. I got the token abcdefg12345

  3. Now I have to use that token to make a request to this url endpoint (which includes params as seen below):

    $ curl -XGET -H "Authorization: Bearer {access_token}" "https://example.com/api/vacations/search?country=us&locale=en-US&price=affortable"
    

Im not too familiar with api requests but tried to research it so what I was trying to do is:

http.get("https://example.com/api/vacations/search?country=us&locale=en-US&price=affortable"+"&token=abcdefg12345")

Unfortunately that doesn't work and I get this: "access token not authorized" Could anyone help? Im also not quite sure if a Bearer token is anyhow different from a 'regular'token and the request has to be different? Also not sure if it was right to leave the params in the url endpoint or should I specify them like that:

http.get("https://example.com/api/vacations/search?"+params+"&token=abcdefg12345", {params:country='us', price:affordable})

Thanks a lot!

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
javascripting
  • 1,135
  • 4
  • 25
  • 46
  • You probably need to put the token in the request headers: `Authorization: Bearer ` or something similar. Check the docs of the api you are using, and the docs of the clas you are using to do the get to see how to add headers. – RichGoldMD Jul 28 '17 at 20:08
  • Possible duplicate of [Set HTTP header for one request](https://stackoverflow.com/questions/11876777/set-http-header-for-one-request) – maximede Jul 28 '17 at 20:09

1 Answers1

1

You would use

$ curl -H "Authorization: Bearer abcdefg12345" "https://example.com/api/vacations/search?country=us&locale=en-US&price=affortable"

Did you try this? What was the result?

B Seven
  • 44,484
  • 66
  • 240
  • 385