A question from @epkpej was asked on another of my Articles
Using the REST Generator (Response Content) in Workflow 7.6
https://www.symantec.com/connect/articles/using-rest-generator-response-content-workflow-76
They wanted to get the "Response Header" from a POST Request.
Unfortunately this isn't possible using the REST Generator. It isn't exposed in the components that are generated by the tool.
Please vote on the Idea/Feature Request:
As an alternative you can swap to a Code (Script) Component
- https://www.symantec.com/connect/articles/code-script-component
- https://www.symantec.com/connect/content-external/workflow-id_LogicBase....
Now we need to add a couple of Inputs
1. Inputs
- URL -Text
- HeaderValue - Text
2. Result Variable
- Result Variable Type - Text
- Result Variable Name - Header
3. Source Code
Namespaces
- System.Net
- System.IO
Now for the code
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.ServicePoint.Expect100Continue = false;
request.ContentType = "application/json";
using (WebResponse response = request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
//responseString = reader.ReadToEnd();
string header = response.Headers[HeaderValue];
return header;
}
}
As you can see the URL is being used in the first line
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
And the Header in a few down
string header = response.Headers[HeaderValue];
This makes the code a little more resuable but there is lots more you can do.
4. Test Page
Now we need an API to test
If we test it in Postman
https://swapi.co/api/people/1
There are a number we can chose from, lets use Etag.
Etag | 145c70f4eca80b4752674d42e5bf1bcf |
Now you might wish to return the collection of headers and loop through them and find the value you wish either in code or with other WF components.
---
If you do need to work with REST the Generator should cover most scenarios and I've written a set of Articles:
Workflow - REST Generator
https://www.symantec.com/connect/articles/workflow-rest-generator
- Workflow - REST Generator
- Using the REST Generator in Workflow 7.6
- Using the REST Generator (GET) in Workflow 7.6 with Mobility Suite
- Using the REST Generator (Headers) in Workflow 7.6 with Mobility Suite
- Using the REST Generator (POST) in Workflow 7.6 with Mobility Suite
- Using the REST Generator (Response Content) in Workflow 7.6
- Using the REST Generator (PATHs) in Workflow 7.6
- Workflow - Read Write JSON
- Workflow - REST - Response Header