Workflow and ServiceDesk Community

 View Only

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

Dec 01, 2015 02:48 PM

In this Article I will explain how to use POST requests in the REST Generator within Workflow and Mobility Suite.

 

This will assume knowledge of Workflow and REST APIs and it would be helpful to read through the previous articles.

Previous Articles

This is an example of a POST Request using the Login API of App Center

 
From the Documentation:

Symantec Mobility Manager 5.4 API Reference Guide

User Authentication
The API also supports converting username/password credentials into a limited-lifetime API key (token) via a login method.
NOTE: API keys created using the login method will not work with the on_behalf_of parameter.
Login
URL: /api1/login
Methods:
• GET
  o None
• POST
  o Description: Login to receive an API key for subsequent requests.
  o Encoding: application/x-www-form-urlencoded
  o POST parameters:
     username: The Mobility Suite username
     password: The user’s password


• Returns: On success:
  • status: the status “okay”
  • api-key: the temporary API Key (not URL encoded!)
  • expiry: The expiration time as a unit timestamp.

HTTPResponse: 200
{
  "status": "okay",
  "api-key": "<the api key>",
  "expiry": 1412046458
}

• Return-type: application/json
 

• Errors
HTTPResponse: 401
{
  "status": "error",
  "message": "User name or password not valid",
  "code": 105
}

 

HTTPResponse: 403
{
  "status": "error",
  "message": "User does not have permission",
  "code": 0
}

Let's build the REST Generator first:

Add

Change the Method to "POST"

Add your further URL "api1/login"

Give it a name - "Login"

Set the 'Request Content' to "Text"

REST Integration Library - 2 Components.png

Now for the Respone Content choose the Format (JSON)

REST Integration Library - Response Content.png

You may need to create the Response Content "Manually" instead of "Create From Request", it doesn't handle POSTs too well.

Documentation from the API provider comes in handy, just create a Data Type how you would with the INT components and DBDT or DTs.

Give it a name - LoginResponse

REST Integration Library - 2 Components - Data Tyoes - Edit Type.png

Then 3 Properties

  • status
  • api-key
  • expiry

REST Integration Library - 2 Components - Data Tyoes - Edit Property.png

REST Integration Library - 2 Components - Data Tyoes - Edit Property - JSON Options.png

 

Back in Workflow

Add a Code (Script) Component.png Code (Script) Component

Scripted Component Wizard - 1 Input Parameters.png

Map the values from your process

Scripted Component Wizard - 1 Input Parameters (Edit Parameter Mappings).png

Set the output to Text and give it an output of RequestContent

Scripted Component Wizard - 2 Result variable.png

Choose your Language, I've picked VB.NET this time but you could use C#.

Scripted Component Wizard - 3 Source Code.png

Dim escapedUsername As String
Dim escapedPassword As String

escapedUsername = Uri.EscapeDataString(username)
escapedPassword = Uri.EscapeDataString(password)

'return "username=" & username & "&password=" & password
return "username=" & escapedUsername & "&password=" & escapedPassword

Run a test to see the output.

Scripted Component Wizard - 4 Test Page.png

Now add the Login component that you created from the REST Generator.

Pass in your RequestContent

Login Editor.png

Set the StatusCode etc.

Now you can login and get an API key to work with throughout the rest of your Workflow.

 

 

Protirus.png

Statistics
0 Favorited
11 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Dec 01, 2015 05:54 PM

Outstanding. Would love to see what you do with this.

Related Entries and Links

No Related Resource entered.