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!

2
  • You probably need to put the token in the request headers: Authorization: Bearer <token> 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. Commented Jul 28, 2017 at 20:08
  • Possible duplicate of Set HTTP header for one request Commented Jul 28, 2017 at 20:09

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.