Workflow and ServiceDesk Community

 View Only

Using the REST Generator (GET) in Workflow 7.6 with Mobility Suite 

May 06, 2015 12:42 PM

In this Article I will explain how to use the REST Generator within Workflow.

 

This builds upon a past article but shows using Parameters to make the component more flexible.

Follow up articles

 

I'm going to be using the RESTful APIs available in to us in the Mobility Suite.

To Test an APIs you could use a Chrome Plugin called PostmanLogo.pngPostman [http://www.getpostman.com/] or on a Mac there is an App you can get called Cocoa Rest Client [http://mmattozzi.github.io/cocoa-rest-client/]

Most APIs will require a Key to use them, make sure you have this to hand but don't share it.

We shall work with the Mobility API.

Login to your Tennant [#.appcenterhq.com/] [https://myappcenterh.appcenterhq.com/admin/landing]

Go to Admin Console. If you are in the App Store click on the top right hand link [Admin Console].

v5.2 - Settings | Mobility Manager configuration | APIs

  (v5.1 Admin | Settings | APIs)

Click on the "Create New Access Key"

Data API.png

Copy this Key as we will be using it soon.

Now go to your Workflow Server.

Open Workflow.png Workflow Manager.

File | New Project and create a new Forms (Web).png Forms (Web) Project.

Give this a name (POC_AppCenter_WEB).

New Project - Forms (Web).png

In the Project Pane click on the top level Project Project.png POC_AppCenter_WEB

Go to the Properties tab and click Add Property, give it a 'name' of API_KEY with the 'value' of the key you copied before.

name API_KEY
value <your api key>

Encode this using either http://meyerweb.com/eric/tools/dencoder/ or in Fiddler [http://www.telerik.com/fiddler] Tools | Text Wizard... (Ctrl+E)

Project - Properties - Add Property.png

This will now be available to you in your Project.

(I like to make these as Profile Properties in Process Manager so they can be shared across Projects)

 

Choose an API you'd like to use. We shall get a list of Apps.

https://<tenant>.appcenterhq.com/api1/apps

 

Now that the Project is set up we can create the Generator.

Back in the main Workflow Manager window click on

File | New Project and create a new Int.png Integration Project.

Give this a name (POC_REST_INT).

New Project - Integration.png

Scroll down to Enterprise Resources and choose the new REST Generator.

Give the Generator a name (AppCenter) and click OK.

Create Generator_0.png

Put in your variables:

Base URL: https://#.appcenterhq.com/
Namespace: AppCenter

* Replace # with your Tenant name

1. REST Service URL_0.png

Click Next.

Now if we choose the API.

Add a NAME, choose your METHOD, and add the API.

Name Apps
Method GET
URL api1/apps?[urlparams]

You need to Save or click Next then Back to make the Properties available.

Click on Properties (along the Top)

Your urlparams will show. give it a Type and be sure to uncheck the URL Encode option.

2. Components.png

Now we want to configure the Response Content.

Click on the ellipse (...)

Choose JSON as the Format and click on 'Create' the 'Create From Request'

2. Components (1)_0.png

Put in your params

start=0&limit=100&api_key=##

*paste in your encoded api_key (we will use the Property later in the WF)

Warning! Passing the API key as a query parameter is not recommended and is deprecated.

Support for passing the key via URL parameters will be removed in the near future.

Click Next.

Request (1).png

It will then show the return.

Request (2).png

It will then be selected as your Data Type.

Response Content.png

Click on the 'Edit' to see the Data Types that have been created.

Data Types.png

Finally click Finish.

OK the next screen then Recompile and Close.

(Add an Icon and any Description etc.)

Help Editor.png

Back to the sample Project.

Add this newly created Library.

Project.png Project | Libraries | Add...

Select the dll, double click or click Add then click OK. (Untick Publish)

Find the Component and add it into your Workflow.

Workflow (1).png

Double Click and add in your Parameters.

start=0&limit=100&api_key=[[ProjectProperties].api_key]

Add a Web Form and display the data.

Workflow (2).png

Run the Form.

Workflow (3).png

Follow up articles

Protirus.png

Statistics
0 Favorited
0 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Dec 02, 2015 03:59 AM

There are components that can build XML in Workflow, I was using JSON as an input but it didn't handle it very well so I just use Text instead and build up the string I needed. I'd just make the generation of the Request Content handle the parameterisation and then pass that complete string over to the Component.

I've created an Article on POST, hope this helps.

https://www-secure.symantec.com/connect/articles/using-rest-generator-post-workflow-76-mobility-suite

 

Dec 01, 2015 10:51 AM

Thanks, Alex!

Ideally, I'm looking to pass in the updated parameters from the GET command. So, this is exactly what I'm looking to do.

I did try to get the Request Content piece working but didn't have any luck. If I want to parameterize the Request Content, do I need to provide the XML structure with brackets (or another delimiter) in place of the values?

Mike

Dec 01, 2015 03:56 AM

I'll look at creating a more in depth article just on POST but the Request Content is what you need to pass the Body to.

Set that to Text and build it manually.

I usually create the string via a Scripting Component.

You could build up the string (XML) and pass in parameters of Ownership (C), Device Friendly name etc to make it more flexible.

Then the Request - Request Content is the parameter you want to pass this string you've built, the previous output.

Set the Method to POST in your Integration Library.

This was originally how I created the Login component until it moved to a header.

Nov 30, 2015 03:06 PM

Alex,

Your guides for REST in Workflow have been very helpful for me. Thanks! I'm currently trying to sort out how to get a REST POST component created and am wondering if you can help.

I'm sucessfully able to generate and use a REST GET against a third party API to get some device detail. I'm working on a project that will utilze the GET information and then update it via a POST. I'm running into difficulty because the API requires some HTML Body parameters in the POST call. I'm not sure how to add them to my REST component. Have you been able to do this?

Here's the API documentation.

API-Documentation1.png

And here's a screengrab of a successful POST call using Postman with a manually entered HTML body.

Postman-WorkingPOST.png

Thanks!

Mike

Related Entries and Links

No Related Resource entered.