ServiceRequestJSON

Initiates a service request to either retrieve, update, write, or delete JSON data through a RESTful API.

Syntax

ServiceRequestJSON( RequestURI, Method, PostData, Token, CustomHeaders, TimeOut, SendHeaderFirst );

Parameters

Parameter Name Type Description Optional? Default Value
RequestURI String The full URI of the intended JSON data. No n/a
Method String

Determines the type of request made. This must be one of the following:

  • GET - Fetches existing data.
  • POST - Overwrites existing data.
  • PUT - Adds new data.
  • DELETE - Deletes existing data.
No n/a
PostData String JSON data to be passed to the service. Only required if Method is set to either POST or PUT. Yes ""
Token String An authorisation token for the intended API, if required. Yes ""
CustomHeaders String Custom headers to include in the request. Headers must use the format Header~Value and if multiple headers are needed, they must be separated using a pipe symbol (|). Yes ""
Timeout Integer The maximum number of seconds the operation has to complete before it times out. Yes 5
SendHeaderFirst Boolean Determines whether the request initially sends header information ahead of the full data set. Some services require this, but it can be switched off if not needed. Yes 1

Depending on the service and the type of request, some of the optional parameters will require values for the request to be successful.

Output

Whether or not the request is successful, the function will return a string based on the server's response.

Use Case

The LifeTracker productivity site uses sunrise and sunset data from an API. The following expression uses the GET method to fetch the necessary data, and assigns the resulting string to the VARSunriseJSON variable:

VARSunriseJSON:= ServiceRequestJSON( "http://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400", "GET" );

The value assigned to the variable will look something like this:

{"results":{"sunrise":"5:07:16 AM","sunset":"7:21:00 PM","solar_noon":"12:14:08 PM","day_length":"14:13:44","civil_twilight_begin":"4:38:10 AM","civil_twilight_end":"7:50:07 PM","nautical_twilight_begin":"4:02:24 AM","nautical_twilight_end":"8:25:53 PM","astronomical_twilight_begin":"3:23:29 AM","astronomical_twilight_end":"9:04:48 PM"},"status":"OK"}