Get_rest_api

Use this function to recieve data from an external API.

Syntax

json_object get_rest_api(string $baseUri, json_object $uriParameters, boolean $throwOnError)

Parameters

$baseUri: The URI (Uniform Resource Identifier) for the API’s GET request. Parameters are usually defined like ?=parameter but in this function, it is defined: ?={parameterKey} like in string_interpolate where parameter key is defined in the $uriParameters JSON object.

$uriParameters: The parameters that should be inserted in the GET request $baseUri are defined as a JSON object. This object would be defined like { "parameterKey": "parameter"}.

$throwOnError: A true or false value (boolean) that determines, in case of an error, whether the error response should be shown in the transformation result or if it should return null.

Example

{
    "employeeNo": 123456
}
{
    apiResult: get_rest_api("https://exampleservice.com/api/get-employee?id={userId}", {"userId": employeeNo},`true`)
}
{
    "apiResult": {
        "name": "Hans Hansen",
        "phone": 87654321,
        "email": "hans@hansen.dk"
    }
}