VMware Cloud Community
jonathanvh
Enthusiast
Enthusiast
Jump to solution

GET with custom header

Hi all,

I have an issue with doing a GET REST operation with a custom header.

I need to add a session key to it, called "X-HP3PAR-WSAPI-SessionKey" and the value is something like this: "0-267b643cc41e8d26788851b0d911f609-0511165d"

I am able to get a Session key, but adding it as custom header isn't working.

I already modified the worklfows "Invoke a REST operation", "Invoke a REST operation with dynamic params", ...

I've added "request.setHeader(customHeaderName, customHeaderValue);"

But each time I execute it I get this error: {"code":6,"desc":"invalid session key"}

This is working via Postman.

So I know that the custom header isn't added via Orchestrator.

Something else I did was creating a Transient RestHost but also no success

Create Transient RESTHost and RESTOperation.

Can somebody help me with this please?

Thanks in advance!

Tags (2)
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

I added request.setHeader("X-HP3PAR-WSAPI-SessionKey", "0-267b643cc41e8d26788851b0d911f609-0511165d"); to "Invoke a REST operation" workflow and ran it against a simple Spring Boot REST endpoint. The header value arrived safely,

Tested it on vRO 7.5. Seems that GET operations with custom header work as expected.

Could you show the exact scripting code with your modifications?

View solution in original post

0 Kudos
10 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

I added request.setHeader("X-HP3PAR-WSAPI-SessionKey", "0-267b643cc41e8d26788851b0d911f609-0511165d"); to "Invoke a REST operation" workflow and ran it against a simple Spring Boot REST endpoint. The header value arrived safely,

Tested it on vRO 7.5. Seems that GET operations with custom header work as expected.

Could you show the exact scripting code with your modifications?

0 Kudos
jonathanvh
Enthusiast
Enthusiast
Jump to solution

Hi,

This is my code.

var inParamtersValues = [];

Server.log(restOperation.getHeaderParameters());

//restOperation.addMandatoryHeaderParameter("X-HP3PAR-WSAPI-SessionKey");

var request = restOperation.createRequest(inParamtersValues, content);

//set the request content type]

request.contentType = "application/json";

//System.log(" SET headers: " + customHeaderName + " : " + customHeaderValue);

//request.setHeader(customHeaderName, customHeaderValue);

System.log(" SET headers: " + "X-HP3PAR-WSAPI-SessionKey" + " : " + "0-1685dbdefcff4e11f4fe267c778b4d2f-b50c175d");

request.setHeader("X-HP3PAR-WSAPI-SessionKey", "0-1685dbdefcff4e11f4fe267c778b4d2f-b50c175d");

System.debug ("Request contentType: " + request.contentType);

System.log("Request: " + request);

System.log("Request URL: " + request.fullUrl);

var response = request.execute();

System.log("Response: " + response);

statusCode = response.statusCode;

statusCodeAttribute = statusCode;

System.log("Status code: " + statusCode);

contentLength = response.contentLength;

headers = response.getAllHeaders();

contentAsString = response.contentAsString;

System.log("Content as string: " + contentAsString);

[2019-06-29 09:01:34.652] [I]  SET headers: X-HP3PAR-WSAPI-SessionKey : 0-1685dbdefcff4e11f4fe267c778b4d2f-b50c175d

[2019-06-29 09:01:34.653] [D] Request contentType: application/json

[2019-06-29 09:01:34.655] [I] Request: DynamicWrapper (Instance) : [RESTRequest]-[class com.vmware.o11n.plugin.rest.Request] -- VALUE : com.vmware.o11n.plugin.rest.Request@4be6b27c

[2019-06-29 09:01:34.656] [I] Request URL: https://*.*.*.*:8080/api/v1/volumes/ (removed the IP)

[2019-06-29 09:01:34.735] [I] Response: DynamicWrapper (Instance) : [RESTResponse]-[class com.vmware.o11n.plugin.rest.Response] -- VALUE : com.vmware.o11n.plugin.rest.Response@721e0714

[2019-06-29 09:01:34.736] [I] Status code: 403

[2019-06-29 09:01:34.737] [I] Content as string: {"code":6,"desc":"invalid session key"}

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

The code looks okay to me.

Do you get the same error if you omit this header at all, or if you set with some arbitrary/incorrect value?

Several things come in mind:

  • try with a newer build of REST plug-in, if you have an older version (tech preview builds are available for download from this forum)
  • check if 3PAR system has log files, and if there is more info about the request
  • use some kind of network monitoring tool to capture network traffic between vRO and 3PAR to check the request and its headers
jonathanvh
Enthusiast
Enthusiast
Jump to solution

If I omit the header, or put a wrong value in it, I always get the same error message back.

I'll try to do the the things that you mentioned also.

My current REST plugin is: REST 2.2.2.9866760

0 Kudos
jonathanvh
Enthusiast
Enthusiast
Jump to solution

Just a quick update, updating the REST plugin didn't resolve the issue.

I am now on REST 2.3.2.12839244

0 Kudos
qc4vmware
Virtuoso
Virtuoso
Jump to solution

How/where are you getting the session key from?  I don't see any code requesting one.  What's the expiration period on one of those keys?

jonathanvh
Enthusiast
Enthusiast
Jump to solution

I found what was wrong!

I generated the session key on my laptop via Postman and then pasted the key manually in the code.

And that didn't work.

After your suggestion from where the session key came from I started thinking and then I let my Orchestrator workflow generate the session key.

And this worked!

So there is a check on the 3PAR system that the originating IP is the same.

My laptop and Orchestrator server are in a separate VLAN/IP range. And that was the issue.

Now it works like a charm!

Thanks for the help and suggestions!

[2019-07-01 10:21:56.260] [I] Setting defaut content type to:  application/json

[2019-07-01 10:21:56.262] [I]  acceptHeaders null

[2019-07-01 10:21:56.264] [I] Request: DynamicWrapper (Instance) : [RESTRequest]-[class com.vmware.o11n.plugin.rest.Request] -- VALUE : com.vmware.o11n.plugin.rest.Request@11e1bac5

[2019-07-01 10:21:56.269] [I] Request URL: https://IP:8080/api/v1/credentials/

[2019-07-01 10:21:56.355] [I] Response: DynamicWrapper (Instance) : [RESTResponse]-[class com.vmware.o11n.plugin.rest.Response] -- VALUE : com.vmware.o11n.plugin.rest.Response@445b67b9

[2019-07-01 10:21:56.356] [I] Status code: 201

[2019-07-01 10:21:56.357] [I] Content as string: {"key":"0-dca68ce8bd7a71cfbb7405c9c869f63f-a4c2195d"}

[2019-07-01 10:21:56.358] [I] ****Headers****

[2019-07-01 10:21:56.359] [I] Mon, 01 Jul 2019 08:21:56 GMT

[2019-07-01 10:21:56.360] [I] no-cache

[2019-07-01 10:21:56.361] [I] /api/v1/credentials/0-dca68ce8bd7a71cfbb7405c9c869f63f-a4c2195d

[2019-07-01 10:21:56.362] [I] hp3par-wsapi

[2019-07-01 10:21:56.363] [I] no-cache

[2019-07-01 10:21:56.364] [I] close

[2019-07-01 10:21:56.365] [I] application/json

[2019-07-01 10:21:56.399] [I] Session Key is: 0-dca68ce8bd7a71cfbb7405c9c869f63f-a4c2195d

[2019-07-01 10:21:56.428] [I]  SET headers: X-HP3PAR-WSAPI-SessionKey : 0-dca68ce8bd7a71cfbb7405c9c869f63f-a4c2195d

[2019-07-01 10:21:56.432] [I] Request: DynamicWrapper (Instance) : [RESTRequest]-[class com.vmware.o11n.plugin.rest.Request] -- VALUE : com.vmware.o11n.plugin.rest.Request@a015506

[2019-07-01 10:21:56.433] [I] Request URL: https://IP:8080/api/v1/volumes/

[2019-07-01 10:21:57.166] [I] Response: DynamicWrapper (Instance) : [RESTResponse]-[class com.vmware.o11n.plugin.rest.Response] -- VALUE : com.vmware.o11n.plugin.rest.Response@79a7cc10

[2019-07-01 10:21:57.168] [I] Status code: 200

[2019-07-01 10:21:57.171] [I] Content as string: {"total":264,"members":[{"id":101,"name":"volume_name","deduplicationState":1,"compressionState":1,"provisioningType":6,"copyType":1,"baseId":101,"readOnly":false,"state":1,"failedStates":[],"...

qc4vmware
Virtuoso
Virtuoso
Jump to solution

Yup.  Security!

0 Kudos
andrewraxter
Contributor
Contributor
Jump to solution

I know, it is an old thread.
I'm trying to figure out how to pull the token out of the response in Orchestrator's rest response so that I can then use the token in the header of my following api calls.

From the post you made, it looks like you have this figured out.

0 Kudos
andrewraxter
Contributor
Contributor
Jump to solution

I found it:

var tokenContent = JSON.parse(response.contentAsString);
System.log(JSON.stringify(tokenContent, null, 2));
var token = tokenContent.access_token;
0 Kudos