I am recieving a 406 error when executing a GET against the vRA 8 REST API.
When executing in POSTman I get a response in JSON and I have set the default content type.
I am passing the bearer token in the headers string array variable and it seems to be accepted.
The 406 error suggests a not acceptable from the sever - what format should the header be in with the bearer token?
Please provide more info - which REST API are you calling, what is the HTTP method, what headers (and their values) are populated in the request, what's the request body (if any), etc.
Error 406 indicates that the server cannot produce a response matching the acceptable formats specified in the request. For example, the particular REST API you are calling can return objects in JSON format but your request has a header like Accept: text/html, which cannot be satisfied by the JSON response payload.
The rest api is the deployments vRA 8 api
GET
Headers
Content-Type application/json - this is being passed as part of the defaultContentType in the operation
"Authorization: Bearer XXX"
Here is the response from the failed job in the logs
2020-03-10 13:36:39.000 -04:00INFO acceptHeaders Authorization: Bearer XXX,Content-Type: application/json
The above is totally wrong.
'Invoke a REST Operation' workflow's second input parameter is labelled 'Accept Headers'. Not 'Authorization', not 'Content-Type'. So please remove what you've set there and provide just the string application/json.
BTW, I tested this workflow with some REST operations that are able to return either JSON or XML responses, and when I provided the values from your run, it indeed failed (although with a slightly different error).
I guess a part of the problem is that semantically the input parameter 'Accept Headers' can be interpreted in two ways, either
The latter if what the stock workflow 'Invoke a REST operation' expects; you can check the scripting code in this workflow to see how the value of input parameter acceptHeaders is processed.
Hey Ilian,
Thanks for responding, I have tried many different formats and I do see that the header for Authorization is being read and I suspect I am not providing it in the way the rest invoke operation workflow expects.
You mentioned looking at the code for the workflow, in previous versions you could look at the script tab, that isn't there in vRO 8 for the invoke rest operation. Can you point me to how I can view the code?
Ignore last post - I found it
Hey Ilian,
I have managed to figure this out.
I ended up cloning the Invoke REST Operation workflow.
In the code there is no place to add an Authorization Header.
I ended up adding an input variable 'token' and then added the line "request.setHeader('Authorization','Bearer ' + token);"
This now operates the way I would expect.
As a side note the acceptHeaders variable is pre-pended with the string "accept" for all strings in the array.
I found I didn't need this variable at all and setting the defaultContentType variable to application/json was good enough.
Thanks,
Daniel