Please rate how useful you found this document: 
No votes yet

The executeRestConnector() Function

To execute a connector from a process, it is necessary to call the connector with the executeRestConnector function. This function executes the connector created by the user.

array executeRestConnector(string connectorName, array overwriteParams, array pathParameters, array queryParameters, array requestBody, array configuration)

Parameters:

  • string connectorName: The unique name of the connector.
  • array overwriteParameters: (Optional) Overwrite any of the headers configuration parameters.
  • array pathParameters: (Optional) The path parameters, which are variable values that are embedded in the URL path.
    For example, in the URL of the Execute Trigger endpoint PUT /cases/{app_uid}/execute-trigger/{tri_uid}, there are two path parameters: app_uid, which is the unique ID of the case, and tri_uid, which is the unique ID of the trigger to execute.
  • array queryParameters: (Optional) Query parameters, which are a set of rules separated from the URL path by the question mark (?) used to narrow the request response, sort, filter or search information.
  • array requestBody: (Optional) List of parameters defined in JSON format, usually required for POST and PUT requests.
  • array configuration: An array with the parameter 'bodyType', which can be 'form-data' or 'json'.

Examples

Uploading a File to Drive

The following trigger uploads a local file to a Google Drive account. Two calls are made to the Google Drive service. In the first call, the file is uploaded. In the second call, the file is renamed and added to a folder.

//This parameter overwrites any OAuth configurations set in the connector configuration.
//In this case overWriteParameters replaces the variable with the email address of a user in the domain. The ID to be used is the email address (this is just for Google Drive endpoints.)
$overWriteParameters = ['sub' => 'john@example.com'];

//If the configured connector has some path parameters, they should be configured in this array.
$pathParameters = [];

//If the endpoint needs query parameters (the ones that are after the url’s question mark) they should be added in this array.
//In this case is needed to send ?uploadType=multipart
$queryParameters = ["uploadType" => "multipart"];

//The body to send to the endpoint. If the body type is JSON a simple associated array is sent.
//In this case the connector has a body type of form-data, so an array of arrays is sent. Change the file parameter to one existing in the server.
$requestBody = [
    ['name'=>'uploadType', 'contents'=>'file', 'type'=>'text'],
    ['name'=>'title', 'contents'=>'test', 'type'=>'text'],
    ['name'=>'file', 'contents'=>'/home/john/Downloads/contract.pdf', 'type'=>'file']
    ];

//In this array any additional configuration parameter must be sent. In this case the config variable sends the body type.
$config = ['bodyType' => 'form-data'];

//The uploadFileToDrive function with all our previous parameters is executed.
$response = executeRestConnector('uploadFileToDrive', $overWriteParameters, $pathParameters, $queryParameters, $requestBody, $config);

//Google will return the file ID of the uploaded file in the response variable. This ID will be stored in the uploadedFileId variable.
$uploadedFileId = $response->message->id;

//This is the name that the file will have.
$fileName = 'MyUploadedFile.pdf';

//This is the directory ID (of Google Drive) where the file will be stored.
//Get this ID by going inside the directory and copying the last part of the URL, for example: https://drive.google.com/drive/u/0/folders/0B6sVMFnKbbFRQVZnSjdTY1dNdkk
$directoryId = '0B6sVMFnKbbFRQVZnSjdTY1dNdkk';

//The updated file is called to change the name and add the file to some directory.
$overWriteParameters = ['sub' => 'john@example.com'];

$pathParameters = [
    "fileId" => $uploadedFileId
];

//This query parameter adds the file to the Google Drive folder. To move the file to a new directory, change here the directoryId variable.
$queryParameters = [
    "addParents" => $directoryId
];

//In this call the body is the default (JSON) so a simple associated array is sent.
$requestBody = [
    "name" => $fileName
];
$response2 = executeRestConnector('updateFile', $overWriteParameters, $pathParameters, $queryParameters, $requestBody);

Response:

If the trigger is executed successfully, the code of the reponse is 200 and the following message is returned.

stdClass Object (
    [code] => 200
    [contentType] => Array (
        [0] => application/json;
        charset=UTF-8
    )
    [message] => stdClass Object (
        [kind] => drive#file
        [id] => 0B2amqXoRjLvyTjk0U2dNWDZKdHc
        [name] => Untitled
        [mimeType] => application/pdf
    )
    [rawBody] => {
        "kind": "drive#file",
        "id": "0B2amqXoRjLvyTjk0U2dNWDZKdHc",
        "name": "Untitled",
        "mimeType": "application/pdf" }
    )

stdClass Object (
    [code] => 200
    [contentType] => Array (
        [0] => application/json;
        charset=UTF-8
    )
    [message] => stdClass Object (
        [kind] => drive#file
        [id] => 0B2amqXoRjLvyTjk0U2dNWDZKdHc
        [name] => MyUploadedFile.pdf
        [mimeType] => application/pdf
    )
    [rawBody] => {
        "kind": "drive#file",
        "id": "0B2amqXoRjLvyTjk0U2dNWDZKdHc",
        "name": "MyUploadedFile.pdf",
        "mimeType": "application/pdf" }
    )

Listing the Events in a Calendar

The following trigger executes the listEventsMyCalendar connector of the Google Calendar service. This connector uses the "primary" path parameter to retrieve the events of the main calendar of the google account.

$overwriteParams = [
];

$pathParameters = [
    'calendarId' => 'primary'
];
$queryParameters = [
    'showDeleted' => 'false'
];
$requestBody = [];
$configuration = [];

$messageArray = executeRestConnector(
    'listEventsMyCalendar', //name of the connector
    $overwriteParams,
    $pathParameters,
    $queryParameters,
    $requestBody,
    $configuration
);

Response:

If the trigger is executed successfully, the code of the reponse is 200 and the following message is returned.

stdClass Object (
    [code] => 200
    [contentType] => Array (
        [0] => application/json;
        charset=UTF-8
    )
    [message] => stdClass Object (
        [kind] => drive#file
        [id] => 0B2amqXoRjLvyTjk0U2dNWDZKdHc
        [name] => Untitled
        [mimeType] => application/pdf
    )
    [rawBody] => {
        "kind": "calendar#events",
        "etag": "\"p330adk6mv29tc0g\"",
        "summary": "cybil.bennett@example.com",
        "updated": "2017-09-07T20:45:35.752Z",
        "timeZone": "America/New_York",
        "accessRole": "owner",
        "defaultReminders": [
        {
            "method": "popup",
            "minutes": 10
        }
        ],
        "nextSyncToken": "CMCm0Nb4k9YCEMCm0Nb4k9YCGAU=",
        "items": [
        {
            "kind": "calendar#event",
            "etag": "\"2912471672020000\"",
            "id": "238s6rbj2ifq7uabi6sb9dga18",
            "status": "confirmed",
            "htmlLink":  "https://www.google.com/calendar/event?eid=Y...",
            "created": "2016-02-23T13:39:58.000Z",
            "updated": "2016-02-23T13:57:16.010Z",
            "summary": "Meeting",
            "location": "Main Meeting Room",
            "creator": {
            "email": "johnDoe@example.com",
            "displayName": "John Doe"
        },
        "organizer": {
            "email": "johnDoe@example.com",
            "displayName": "John Doe"
        },
        "start": {
            "dateTime": "2016-02-23T16:00:00-04:00"
        },
        "end": {
            "dateTime": "2016-02-23T17:00:00-04:00"
        },
        "iCalUID": "238s6rbj2ifq7uabi6sb9d@google.com",
        "sequence": 0,
        "attendees": [
        {
            "email": "johnDoe@example.com",
            "displayName": "John Doe",
            "organizer": true,
            "responseStatus": "accepted"
        },
        {
         ...
        }
       ],
        "hangoutLink": "https://plus.google.com/hangouts/_/johnDoe?hceid=Z2lvdmFt...",
        "reminders": {
            "useDefault": true
        }
        }
        ]
    }
)

Creating a New Event in a Calendar

The following trigger executes the createNewEvent connector of the Google Calendar service. This connector uses the "primary" path parameter to create an event in the main calendar of the google account.

$overwriteParams = [];

$pathParameters = [
    'calendarId' => 'primary'
];

$queryParameters = [
    'sendNotifications' => 'true',
    'maxAttendees' => 2,
    'supportsAttachments' => 'false'
];

$requestBody = [
    'summary' => 'Summary Example 2017',
    'location' => '800 Howard St., San Francisco, CA 94103',
    'description' => 'Main event description.',
    'start' => [
        'dateTime' => '2017-10-21T09:00:00-08:00',
        'timeZone' => 'America/Los_Angeles',
    ],
    'end' => [
        'dateTime' => '2017-10-21T17:00:00-08:00',
        'timeZone' => 'America/Los_Angeles',
    ],
    'recurrence' => [
        'RRULE:FREQ=DAILY;COUNT=2'
    ],
    'attendees' => [
        ['email' => 'mail1@example.com'],
        ['email' => 'mail2@example.com']
    ],
    'reminders' => [
        'useDefault' => false,
        'overrides' => [
            ['method' => 'email', 'minutes' => 24 * 60],
            ['method' => 'popup', 'minutes' => 10],
        ],
    ]
];

$configuration = [
    'bodyType' => 'json'
];

$messageArray = executeRestConnector(
    'createNewEvent', //name of the connector
    $overwriteParams,
    $pathParameters,
    $queryParameters,
    $requestBody,
    $configuration
);

Response:

If the trigger is executed successfully, the code of the reponse is 200 and the following message is returned.

stdClass Object (
    [code] => 200
    [contentType] => Array (
        [0] => application/json;
        charset=UTF-8
    )
    [message] => stdClass Object (
        [kind] => calendar#event
        [etag] => "3011833072408000"
        [id] => 59gfdpm4f90mmr4og1hd62v0og
        [status] => confirmed
        [htmlLink] => https://www.google.com/calendar/event?eid=NTlnZmRwbTRm
        [created] => 2017-09-20T14:08:56.000Z
        [updated] => 2017-09-20T14:08:56.261Z
        [summary] => Summary Example 2017
        [description] => Main event description.
        [location] => 800 Howard St., San Francisco, CA 94103
        [creator] => stdClass Object (
            [email] => pmconnectors@project-71075.iam.gserviceaccount.com
            [self] => 1
        )
        [organizer] => stdClass Object (
            [email] => pmconnectors@project-71075.iam.gserviceaccount.com [self] => 1
        )
        [start] => stdClass Object (
            [dateTime] => 2017-10-21T17:00:00Z
            [timeZone] => America/Los_Angeles
        )
        [end] => stdClass Object (
            [dateTime] => 2017-10-22T01:00:00Z
            [timeZone] => America/Los_Angeles
        )
        [recurrence] => Array (
            [0] => RRULE:FREQ=DAILY;COUNT=2
        )
        [iCalUID] => 59gfdpm4f90mmr4og1hd62v0og@google.com
        [sequence] => 0
        [attendees] => Array (
            [0] => stdClass Object (
                [email] => mail1@example.com
                [responseStatus] => needsAction
            )
            [1] => stdClass Object (
                [email] => mail2@example.com
                [responseStatus] => needsAction
            )
        )
        [reminders] => stdClass Object (
            [useDefault] =>
            [overrides] => Array (
                [0] => stdClass Object (
                    [method] => popup
                    [minutes] => 10
                )
                [1] => stdClass Object (
                    [method] => email
                    [minutes] => 1440
                )
            )
        )
    )
    [rawBody] => {
        "kind": "calendar#event",
        "etag": "\"3011833072408000\"",
        "id": "59gfdpm4f90mmr4og1hd62v0og",
        "status": "confirmed",
        "htmlLink": "https://www.google.com/calendar/event?eid=NTlnZmR",
        "created": "2017-09-20T14:08:56.000Z",
        "updated": "2017-09-20T14:08:56.261Z",
        "summary": "Summary Example 2017",
        "description": "Main event description.",
        "location": "800 Howard St., San Francisco, CA 94103",
        "creator": {
            "email": "pmconnectors@project-71075.iam.gserviceaccount.com", "self": true
        },
        "organizer": {
            "email": "pmconnectors@project-71075.iam.gserviceaccount.com",
            "self": true
        },
        "start": {
            "dateTime": "2017-10-21T17:00:00Z", "timeZone": "America/Los_Angeles"
        },
        "end": {
            "dateTime": "2017-10-22T01:00:00Z", "timeZone": "America/Los_Angeles"
        },
        "recurrence": ["RRULE:FREQ=DAILY;COUNT=2" ],
        "iCalUID": "59gfdpm4f90mmr4og1hd62v0og@google.com",
        "sequence": 0,
        "attendees": [
            {
            "email": "mail1@example.com",
            "responseStatus": "needsAction"
            },
            {
            "email": "mail2@example.com",
            "responseStatus": "needsAction"
            }
        ],
        "reminders": {
            "useDefault": false,
            "overrides": [ {
                "method": "popup",
                "minutes": 10
            },
            {
            "method": "email",
            "minutes": 1440
            }
            ]
        }
    }
)