VMware Cloud Community
Czernobog
Expert
Expert
Jump to solution

vRA 8.3 - Error in vRO script: A Valid Xsrf Token header must be provided with the Http Request

I've originaly posted this in the NSX forum, but could not find a way to crosspost here: Link 

I want to automate processes in NSX-T, using vRO actions.

The issue a REST request against the NSX-T REST API, you are required to add a header containing a XSRF token.

This works fine when using curl or the vs code rest client:

GET https://ip_of_manager/api/v1/logical-ports
X-XSRF-TOKEN: 8f82b10a-a72b-4a3a-a2bc-5512edf4ad0a

I add the XSRF token (and other parameters) when constructing the REST request in vRO similar to this:

request.setHeader("X-XSRF-TOKEN: 8f82b10a-a72b-4a3a-a2bc-5512edf4ad0a");

Executing the request fails with error 400 and a message appears:

response = request.execute();

error_message: A Valid Xsrf Token header must be provided with the Http Request.

How can I add the XSRF token to the rest request for this operation to work?

0 Kudos
1 Solution

Accepted Solutions
eoinbyrne
Expert
Expert
Jump to solution

Hi

You're almost there, your issue is this line

request.setHeader("X-XSRF-TOKEN: 8f82b10a-a72b-4a3a-a2bc-5512edf4ad0a");

The correct line is with two parameters for (name, value)

request.setHeader("X-XSRF-TOKEN", "8f82b10a-a72b-4a3a-a2bc-5512edf4ad0a");

 

View solution in original post

2 Replies
eoinbyrne
Expert
Expert
Jump to solution

Hi

You're almost there, your issue is this line

request.setHeader("X-XSRF-TOKEN: 8f82b10a-a72b-4a3a-a2bc-5512edf4ad0a");

The correct line is with two parameters for (name, value)

request.setHeader("X-XSRF-TOKEN", "8f82b10a-a72b-4a3a-a2bc-5512edf4ad0a");

 

Czernobog
Expert
Expert
Jump to solution

Yess, this works. I though only the "Authorization" headers have to be split like this. Thanks!

0 Kudos