Skip to main content

Extensibility and Integration

 

OutSystems

Consume a REST API

When you need to retrieve or manipulate information from another system, and that system provides REST APIs for that effect, you can consume a REST API in your application.
Start by looking into the documentation of the REST API you want to use and understand how it works. You will need to gather the following information:

  • Base URL;
  • Security / Authentication requirements;
  • Methods definition (HTTP Method, URL Path, response format).

Security

Each REST API will have their own model of security and authentication process, which may imply the creation of an account, the registration for an API key or the usage of tokens. To consume a REST API in OutSystems you must understand and follow the provider’s security model.

Define the REST API and REST API Method

After gathering all the information you need from the REST API documentation, do the following to consume a method of the REST API:

  1. In the Logic tab, open the Integrations folder;
  2. Right-click on the REST element and select Consume REST API...:

    REST-consume-1.png
     
  3. In the displayed dialog, choose to add a single method:
    ​​​​​​
    REST-consume-2.png

    If the REST API you want to consume is compliant with the Swagger specification, you will be able to add all the API methods in one step by choosing ADD ALL METHODS. Otherwise, you need to add each method individually.
     
  4. Fill the information about the Method URL. You can include parameters in braces in the URL for the method’s input parameters;

    Examples:
    GET https: //api.example.com/Portal/rest/Contacts/GetAll
    GET https: //api.example.com/Portal/rest/Contacts/Get?Id={Id}
    POST https: //api.example.com/Portal/rest/Contacts/Create
     
  5. If the REST API you are consuming requires authentication or specific headers, open the Headers / Auth tab and fill the needed information:

    REST-consume-3.png
     
  6. Fill the information about the Request and the Response. The easiest way to do this is to perform a test to the API and use the test result - alternatively, you can add the JSON structure or plain text example directly in the Request and Response fields in the Body tab. Open the Test tab. If you have parameters in your Method URL, you need to insert the parameter values to execute the test:

    REST-consume-4.png

    For manipulation methods, such as POST or PUT, fill the Request of the Body Content with the corresponding request structure:

    REST-consume-5.png
     
  7. Click Test. If the test is successful, you will see the method’s response in the Response area of Test tab. Use that information to fill in the Response in the Body tab by clicking COPY TO RESPONSE BODY in the Response area. Leave only the needed fields. For manipulation methods (such as POST or PUT), do the same for the Request, by pressing COPY TO REQUEST BODY in the Request area:

    REST-consume-6.png

    Usually, the most common fields are obtained this way. To know in full detail all the available fields, check the API documentation;
     
  8. Check if the Request and Response information is correct in the Body tab and click OK:

    REST-consume-7.png

 

In the Logic tab, open the Integrations folder and REST element. OutSystems does the following for you:

  • Creates the REST API;
  • Creates the REST API Method with the corresponding input and output parameters;
  • Creates the Structures to hold the corresponding input and output parameters;
  • Maps the REST Data Types into OutSystems Data Types.

Use the REST API Method in your Application

OutSystems translates the methods exposed by a REST API into OutSystems actions, with the same semantics as any action created by you in Service Studio.

REST-consume-8.png

You can now use the newly created method in your application the same way you use the remaining Server Actions:

  1. Go to the action flow where you want to use the REST API Method;
  2. In the Logic tab, open the Integrations folder and REST element;
  3. Open the REST API and drag the REST API Method into your action flow:

    REST-consume-9.png
     
  4. Use the method's output parameters as you do for any other action:

    REST-consume-10.png

 

 

  • Was this article helpful?