Workflow and ServiceDesk Community

 View Only

Using the REST Generator (Response Content) in Workflow 7.6 

Dec 16, 2015 03:18 PM

In this Article I will explain how to use the REST Generator (Response Content) within Workflow 7.6.

Other articles

 

New to me with build Symantec.Workflow.Setup.7.6.4383.504 the REST Generator has been updated to generate Response Content in a third manner - "Create From Sample".
7.6.4383.479 was the first build to have this
With Response Content there were two ways to create the Data Type you need to work with.
  • Create Manually
  • Create From Request
Create Manually was a lot of work but was handy when the Generator can't authenticate against the API or you used a method that wasn't possible.
 
The Create From Request is the easiest as it does it all for you.
 
There is a new one
  • Create From Sample
 
REST Generator - 2 Components - Response Content.png
 
Grab your JSON and paste it in, most APIs have this documented or you could run it through POSTMAN and grab the output
 
REST Generator - 2 Components - Response Content - Create from Sample.png
 
Hit Next
 
REST Generator - 2 Components - Response Content - Create from Sample - Data Type.png
 
There you have your DataType to work with.
 

This should also pull in the headers and map those, I've yet to test this out.

Statistics
0 Favorited
7 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Feb 12, 2018 10:17 AM

Works perfect, I modified the code a bit as I had to create a POST with a JSON object containing "UserName" and "Password" to retrieve the the session token "X-Auth-Token" from the Response Header.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.ServicePoint.Expect100Continue = false;
request.Method = "POST";
request.ContentType = "application/json";

using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
	string json = "{" + "\"UserName\":\""+Username+"\","+"\"Password\":\""+Password+"\"}}";

       streamWriter.Write(json);
       streamWriter.Flush();
       streamWriter.Close();
}

using (WebResponse response = request.GetResponse())
{
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        string sessionToken = response.Headers["X-Auth-Token"];
        return sessionToken;
    }
}

Many thanks for your help.

 

Feb 09, 2018 10:55 AM

Untested but you should be able to do something like

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(newURL);
request.Method = "GET";
request.ServicePoint.Expect100Continue = false;
request.ContentType = "application/x-www-form-urlencoded";

using (WebResponse response = request.GetResponse())
{
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        responseString = reader.ReadToEnd();
        string limit = response.Headers["X-RateLimit-Limit"];
    }
}

Replace "X-RateLimit-Limit" with your Header string you need.

Feb 09, 2018 10:15 AM

According to Symantec there is no possibilities to extract the Response Header with the REST Generator, so to do that I must use a script component. I will add this as a feature request/idea. 

Feb 06, 2018 03:31 AM

I will create a support case for this and I will keep you posted about their response.

Besides this I found another issue as this REST API is SSL encrypted and I have choosen to "Ignore Certificate Warnings" under Machine Settings - Remote Connections on the Workflow Server. With this enabled I don't get any warnings, and thats fine but I wont't get the correct status code result: 201 Created, instead I get 308 which indicates certificate problems. So I will raise a ticket for this as well.

Thanks, I appreciate all help I can get.

 

 

   

Feb 05, 2018 01:25 PM

I don’t remember seeing Response Headers just Request Headers when I wrote up https://www.symantec.com/connect/articles/using-rest-generator-headers-workflow-76-mobility-suite
I think we might have to use a scripting component for now
Maybe the ‘Get HTTP Request Value’ might be able to grab something
I’ll have a look into some options.
I think it would be useful to raise a support ticket as you could get it added as a feature request (add an Idea too)

Feb 05, 2018 11:08 AM

Hi,

I am struggling to get the REST Generator working for a "POST" where I am trying to create a session towards a REST API that will return the session token in the Response Header and not in the JSON response. I can get this to work when using Postman but I do not see how I could retrieve the "Response Header" data from the REST Generator. Anyone have any ideas on how to deal with this?

BR /// Per-Erik

 

   

 

Related Entries and Links

No Related Resource entered.