When you need information from
another system, and that system provides REST APIs for that effect, use
API to retrieve data.
Typically, there are some steps you
always take when adding a REST API method:
- Look into the API documentation. Understand how you can invoke
the REST API method;
- Define the REST API and REST API method. Use the information you
found in the API documentation;
- Understand what is created;
- Use the REST API method in your application.
Imagine you have an external system
for managing tickets (Zendesk). You want to build an application in OutSystems
to list those tickets. Zendesk provides a REST API for that effect.
1. Look Into the API Documentation
Go to the Zendesk API documentation
and understand how their REST API works.
You will find that the REST API Method
to list tickets has the following specifications:
- Requires an account at Zendesk. In this
example, it defines the following base
URL for the REST service: https://osacademy.zendesk.com
- The REST service requires application authentication;
- The REST API method is defined as follows:
- URL Path: /api/v2/tickets.json
- Response: the JSON
structure we want to use is:
2. Define the REST API and REST API Method
Add the REST API and the REST API Method:
- In the Logic layer, expand the Integrations folder;
- Right-click on the REST element and select 'Consume REST API...';
- In the displayed dialog, choose ADD SINGLE METHOD;
- Fill the information about the Method URL: GET
- Go to the Headers/Auth tab, and type your credentials for Zendesk;
- Go to the Test tab and
- In the Response tab, press
COPY TO RESPONSE BODY, leave only the fields we need:
Normally, the most common fields are obtained this way. To know in full
detail all the available fields, check the API documentation.
3. Understand What is Created
Press Ok and the OutSystems Platform does the following for you:
Notice the values in the Name and Base URL
Notice the values in the Name, URL Path,
HTTP Method, and Response Format properties.
- Creates the
that defines the output parameter (response).
Notice the Ticket
structure and its attributes:
- Compare with the JSON of the response;
- TicketItem is used in the GetTicketsResponse
structure that defines the output parameter (response).
Change the name of the REST API to Zendesk.
4. Use the REST API Method in Your Application
You can now list tickets on a
- Use the GetTickets REST API method in the
to get all the tickets;
- Use a table
records to list tickets on the screen:
- Set the GetTickets REST API method as source;
- Add the columns you want to show.
Publish and open
in the browser.
Manipulate Data using REST