wdesk
Hello, I am trying to use the API token to retrieve list of tests. I use the following code to get the token which works successfully but I am not sure what I am doing wrong in supplying the token to the command.
token=`curl -X POST -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8"client_id=5e1abd&client_secret=7b810c2a&grant_type=client_credentials' https://api.app.wdesk.com/iam/v1/oauth2/token`
I removed most of my actual id and secret of course but that was the format.
I then get response like this, again with most of the token deleted.
{"token_type":"Bearer","expires_in":600,"access_token":"eyJhb2sysnDHlju8WDek026kztPSyeEjbi0lWVnoBraXDSHMWD_orRJlPw","scope":"data_tables|r data_tables|w audit_api|r audit_api|w graph_api|r graph_api|w scim|r dataentity|r activity:read file:read file:write graph:read graph:write organization:read task:read task:write"}
I assign that to a variale called token and then try to run this to use the token
curl -X GET https://api.app.wdesk.com/platform/v1/testForms -H 'Accept: application/json' -H "Authorization: Bearer $token"
no matter if I assign just the actual access token or the entire thing in {} above I get
{"message": "No valid API token provided", "code": "401Unauthorized"}
I think I am just not supplying it correctly. Any help?
-
Official comment
Hi, Jason.
You should only need to include the value of the "access_token" field from within your saved "token" variable. So, instead of including the whole json object after "Bearer ", just include, for example, "eyJhb2sysnDHlju8WDek026kztPSyeEjbi0lWVnoBraXDSHMWD_orRJlPw...".
Best,
ColleenHi Jason,
Here are a couple suggestions. First, make sure that your OAuth2 Grant has the Graph Read scope assigned to it. Add this scope if it does not already have it and then try again.
Next, make sure that the value of access_token from the IAM response is correctly assigned to your $token variable.
Finally, you can use the following cURL command in Command Prompt to test the request. The following request includes testPhases as an example expand query parameter value. Adjust this as needed for your test. Verbose mode is included to assist with troubleshooting. You will also need to replace <valid_token> with a valid bearer token.
curl -v --location "https://api.app.wdesk.com/platform/v1/testForms?%24expand=testPhases" --header "Accept: application/json" --header "Authorization: Bearer <valid_token>"
0Please sign in to leave a comment.
Comments
2 comments