How to use REST API from your Script Apps
This guide shows how to use REST API resources directly from your Script Apps.
Requisites
Steps
1. Go to Admin > Developer > App Builder
2. Create a new app by clicking on +App
3. Select Click Scripts or Web Service Scripts according to your needs.
4. Select + Click Script or + Script depending on your previous selection.
5. Go to Edit to open the script editor and start developing your script.
Inside the editor, you can see the http resources on the right.
Examples: using a REST resource within the script
POST
- Encapsule your REST resource to use in your script, inside the http.POST container.
- POST(strURL, strContentType, strHeaders, strBody)
http.POST('https://yourserver.com/comGpsGate/api/v.1/applications/<app_id>/tokens','application/json','','{"password": "demo","username": "demo"}');
- To make it easier find the parameters, you could use the help of the REST API GUI interface as described here.
GET - obtain an address from coordinates (reverse geocoding)
- Encapsule your REST resource to use in your script, inside the http.GET container.
For example, to obtain a user Custom Field we will use this method from the right of the editor:
- GET(strURL, strQS, bURLEncoding, strHeaders)
http.GET('http(s)://yourserver.com/comGpsGate/api/v.1/applications/<app_id>/reversegeocode?','lat=<lat>&lon=<lon>','','Authorization:<your_authorization_key>');
log(http.response)
GET - obtain a user Custom Fields
- Encapsule your REST resource to use in your script, inside the http.GET container.
For example, to obtain a user Custom Field we will use this method from the right of the editor:
- GET(strURL, strQS, bURLEncoding, strHeaders)
http.GET('http(s)://yourserver.com/comGpsGate/api/v.1/applications/<app_id>/users/<user_id>/customfields','','','Authorization:<your_authorization_key>');
log(http.response)
- To make it easier find the parameters, you could use the help of the REST API GUI interface as described here.