Message Boards Message Boards


[✓] Include "Authorization: Bearer ..." in a URL execute?

Posted 1 month ago
4 Replies
3 Total Likes

I am trying to access the Asana api. In order to do that I need to send http requests of the form

https://api end point "Authorization: Bearer 0/123456789abcdef"

I have tried setting Authetication -> <|"Authorization" -> Bearer... |> but that just brings up the asana sign in box. I also tried "Headers" -> "Authorization: Bearer..." |> but that throws the error

HTTPRequest::nvldheaders: -- Message text not found -- (Join[{user-agent->Wolfram HTTPClient 12.},Authorization: Bearer ...

What is the correct way to include the Authorization header request in the message?

4 Replies
Posted 1 month ago


HTTP headers have to be passed as a list. Try this

HTTPRequest[API_ENDPOINT_URL, <|"Headers" = {"Authorization: Bearer ACCESS_TOKEN"}|>]
Posted 1 month ago

Thanks for your suggestion, sadly I am still doing something wrong.

This curl command works correctly curl -H "Authorization: Bearer 0/123456789abcdef"

I am trying to reproduce that in WL. My current attempt is: header = <|"Headers" -> {"Authorization: Bearer 0/123456789abcdef"}|> URLExecute["", header]

Can you see anything wrong with my code, and also is there a way to get Mathematica to show me exactly what it is sending to Asana?


The format for a curl command of

curl -H "Authorization: Bearer 0/123456789abcdef"

should be

  "url goes here", <|
   Method -> "POST",
   "Headers" -> {"Authorization" -> 
      "Bearer 0/123456789abcdef"},
   "Body" -> {"username" -> "myusername", "password" -> "mypwd"}

This assumes that there is a need for a username and pwd, You may not need a body if you don't need the login.

I hope this helps.



Posted 1 month ago

That's fantastic. Problem solved, thank you very much.

For anyone who finds this thread whilst trying to contact Asana, the following works:

req = HTTPRequest[ "", <|Method -> "Get", "Headers" -> {"Authorization" -> "Bearer 0/abc123"}|>]


Please note, Asana requires a Get rather than a Post, hence the change to Neil's code. Also, using the Personal Access Token (PAT) means that you don't need to send the username and password

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract