Dynamic http-connector header

I am passing an access token as part of the input variables in the beginning while starting the process. It is a basic string set up right now similar to eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ4ajZiVE9JeUE2NTBQLWJWM1lZSUtraF83aW0zcWdEaFgxODQ4RVV6YUZrIn0.eyJqdGkiOiI3ZTA5NzVhMi0xMWFiLTQ0MzYtYWY5My05NDk2MWE1Yjg5NTciLCJleHAiOjE1Mzc5MDEzMjUsIm5iZiI6MCwiaWF0IjoxNTM3OTAxMDI1LC…

I have 3 service tasks and they are all set up with http-connectors. I have tested the url and the system without authentication, and it works. Now, I have added another key/value pair to the header of each http connector which looks like: “Authorization: ${accessToken}”

accessToken is an input variable which is set up like a script, and does the following:
var token=execution.getVariable(“accessToken”); //accessToken is the input string while starting
accessToken="Bearer "+token;

When I try to start my process, I get SPIN-01004 No matching data format detected. However, I know that my previous http-connector set up is correctly working and I am not using spin in the authorization part, so I’m not sure where I’m going wrong.

I would really appreciate any help! Thanks!

The spin error is coming from you parsing your Json response from the http request? If yes, remove the spin and just return the string and confirm you are getting valid Json

It’s not from the response. I’ve tested the workflow without the authorization plugins, and the response from the http-connector url works correctly.

I added a new feature where I pass a token as an input variable in the forms at the beginning of the process instance. Then, similar to your SMS Twilio http-connector example, I added the dynamic authorization header. Instead of the encoding script you wrote in the I/O part, I just wrote

var token=execution.getVariable(“accessToken”); //accessToken is the input string while starting
accessToken="Bearer "+token;

I have two variables I pass when starting the process instance: country and accessToken.

Both are strings, and I am not using any spin functionality on the new script I added which is why I am very confused about where the error is coming from.

can you share your bpmn

parallelCWFE.bpmn (11.0 KB)

This is the one. Hopefully it makes sense.

You have multiple uses of S() in your bpmn

one of these look to be failing. Wrap your S() with a Try/Catch and do a print to console to determine which is failing.

parallel.bpmn (9.7 KB)
This is the same file without the accessToken code added, and this works. All the spin functionality comes from this one actually. As you can see, I’m not adding any spin functionality to the accessToken stuff.

Correct, what is probably happening is when you are adding your access token something weird is being returned in the response. You need to confirm the exact values that are being returned in your response. The best way to do this is to return as a String (when using the access token) and manually view the response body.

Also take a look at using: Replacing Http-Connector with Jsoup usage
which will give you some more control to test and handle responses.

So I tried accessing the same URL with the settings on Postman, and I get the right JSON object back.

Any other ideas because I’m still getting the No matching data format detected error code despite being able to get the right response externally. Do you think it could be how I’m accessing and manipulating the token in the I/O script variable? Because I don’t see where else the problem is.

Before we go to any other problem solving, wrap the S() in try/catch and when it fails sys print the raw String response, and eval that the data is the same as being returned by postman

Tried that, and the data is the same object. I tried it for the file with no authentication

You tried it using Authentication?

Yes, and I got the same error request where it refused to start.

Hi @A.Gupta ,
Able to find the answer ? I’m getting the same error now.