VMware Cloud Community
orian
Hot Shot
Hot Shot

Rest Operation with headers

Hi,

I try to run a workflow in other program (not VRO).

With postman program I successfully run the relevant workflow, but in order to run it, I have to add two headers:

Content-type - application/Json

X-CSRF-Token - long id number

How can I with VMware Orchestrator to run a Rest Operation with multiple headers?

I only find a workflow which allows me to add only the Content-Type

Thanks!

0 Kudos
7 Replies
iiliev
VMware Employee
VMware Employee

Hi,

You need to obtain the request object, and then use its setHeader() method to add additional headers.

There are several ways to obtain the request object; eg. RESTOperation has method createRequest() that creates a request out of the operation. So it depends on your code.

0 Kudos
orian
Hot Shot
Hot Shot

Hi,

I'm not sure I understand where I need to do all these things...

Thanks!

0 Kudos
iiliev
VMware Employee
VMware Employee

How do you run the REST operation? Via scripting code, or using the workflow 'Invoke a REST operation'? If via workflow, you may need to extend id (to add additional headers via code, the same way as the workflow adds the headers mandatory for the REST operation). Or you can modify the REST operation by calling its setManadatoryHeaderParameter() method; this change can be done in the same place where you create the operation, or in other places in your workflow where you have access to operation object.

0 Kudos
orian
Hot Shot
Hot Shot

Hi,

I use the Invoke a REST operation with dynamic params

I added the following code:

request.setHeader("X-CSRF-TOKEN", generationNumber);

The generationNumer is received from the user when running the workflow.

However, I still receive status error 500.

Through postman program it works fine.

Thanks!

0 Kudos
iiliev
VMware Employee
VMware Employee

Checked the same in my environment, and it works - my REST controller method received x-csrf-token header and it value.

Error 500 is a server-side error. Could you check what exact application error is thrown in your environment? Also, add some logging to your workflow to dump the value of gnerationNumber variable before you call setHeader() to verify that it is not null/empty at that point.

0 Kudos
orian
Hot Shot
Hot Shot

yes, the gnerationNumber  is not empty.

However, I think the header is not added to my request\response.

I use "Invoke a REST operation with dynamic params" workflow

This worflow I duplicated and add the following code:

request.setHeader("X-CSRF-TOKEN", generationNumber);

At the end of the workflow I check the headers from the response, but the X-CSRF-TOKEN header does not appears...

Any idea?

Thanks!

0 Kudos
iiliev
VMware Employee
VMware Employee

I used this workflow, too, and all the expected headers were there.

Setting this header in the request does not mean it will automatically appear in the response.

Could you provide the output of executing this request with curl (with verbose option) to verify that this header appears in both request and response?

0 Kudos