Note: This article applies to Genesys Cloud for Salesforce.

A feature described on this page is coming soon. For more information, see the release notes.

You can use our SDK in the managed package to call the Genesys Cloud Platform API in Salesforce. The SDK uses the Salesforce Apex programming language. 

Note: This advanced customization article is intended for developers who are familiar with Salesforce.

Prerequisites

You can call any Platform API that is not tied to a specific user context and that the permissions in your OAuth client allow. The OAuth client is the OAuth client that you created for the Authentication settings in Salesforce. For more information, see Authentication.

Access our SDK through the Rest class under the purecloud.SDK.Rest namespace. For examples that access our SDK through the Rest class, see Genesys Cloud for Salesforce SDK Examples (GitHub).

Rest class

Contains methods that act on the Genesys Cloud Platform API through Genesys Cloud for Salesforce. 

Namespace

purecloud.SDK.Rest

Usage

Use these methods to GET, PATCH, POST, PUT, or DELETE data with the Platform API through Genesys Cloud for Salesforce.

Rest methods

The following methods are available for the Rest class.

Sends an HTTP GET request to a Platform API endpoint.

Parameters

Name Data type Required or optional Description
url String Required Path for a Platform API, for example, /api/v2/users/{userId}.
headers Map<String, String> Optional Custom data added to HTTP headers. 

Return value

Data type Description
HttpResponse Returns native Salesforce HttpResponse.

Example

The following example returns information about a particular user and sends a custom header with the /api/v2/users/{userId} endpoint.

HttpResponse response = purecloud.SDK.Rest.get('/api/v2/users/6a50987a-f00c-4b10-b627-4a677f9f0263', new Map<String, String>{'CustomHeaderValue' => 'Foo'});

Sends an HTTP PATCH request to a Platform API endpoint.

Parameters

Name Data type Required or optional Description
url String Required Path for a Platform API, for example, /api/v2/users/search.
body String Required Serialized JSON object.
headers Map<String, String> Optional Custom data added to HTTP headers. 

Return value

Data type Description
HttpResponse Returns native Salesforce HttpResponse.

Example

The following example modifies attributes on a chat participant with the /api/v2/conversations/chats/{conversationId}/participants/{participantId}/attributes endpoint. The request body is formatted as { “attributes”: { “attrib1”: “John Doe”, “attrib2”: “Foo” }}.

Map<String,Object> attributes = new Map<String,Object> { 
    'attrib1' => 'John Doe',
    'attrib2' => 'Foo'
};
Map<String,Object> body = new Map<String,Object> { 
    'attributes' => attributes 
};
HttpResponse response = purecloud.SDK.Rest.patch('/api/v2/conversations/chats/42a09688-c7e2-4d49-b9b8-8667d321a6f7/participants/5ad38568-9b97-4db6-850b-48b750566b06/attributes', JSON.serialize(body), new Map<String, String>{'CustomHeaderValue' => 'Foo'});

Sends an HTTP POST request to a Platform API endpoint.

Parameters

Name Data type Required or optional Description
url String Required Path for a Platform API, for example, /api/v2/users/search.
body String Required Serialized JSON object.
headers Map<String, String> Optional Custom data added to HTTP headers. 

Return value

Data type Description
HttpResponse Returns native Salesforce HttpResponse.

Example

The following example searches users by name and sends a custom header with the /api/v2/users/search endpoint. The example uses two mapped objects to generate a JSON string. The request body is formatted as { “query”: [{ “fields”: [“name”], “value”: “John Doe”, “type”: “CONTAINS” }] }

Map<String,Object>query=new Map<String,Object>{
    'fields'=newList<String>{'name'},
    'value'=>'John Doe',
    'type' =>'CONTAINS'
};
Map<String,Object>body=newMap<String,Object>{
    'query' => new List<Object>{ query }
};
HttpResponse response = purecloud.SDK.Rest.post('/api/v2/users/search', JSON.serialize(body), new Map<String, String>{'CustomHeaderValue' => 'Foo'});

Sends an HTTP PUT request to a Platform API endpoint.

Parameters

Name Data type Required or optional Description
url String Required Path for a Platform API, for example, /api/v2/users/{userId}/callForwarding.
body String Required Serialized JSON object.
headers Map<String, String) Optional Custom data added to HTTP headers. 

Return value

Data type Description
HttpResponse Returns native Salesforce HttpResponse.

Example

The following example updates the call forwarding settings for a particular user and sends a custom header with the /api/v2/users/{userId}/callForwarding endpoint. 

String body = '{ "enabled": true, "phoneNumber": "+13175550123" }';
HttpResponse response = purecloud.SDK.Rest.put('/api/v2/users/6a50987a-f00c-4b10-b627-4a677f9f0263/callForwarding', body, new Map<String, String>{'CustomHeaderValue' => 'Foo'});

Sends an HTTP DEL request to a Platform API endpoint.

Parameters

Name Data type Required or optional Description
url String Required Path for a Platform API, for example, /api/v2/users/{userId}/station/associatedStation.
headers Map<String, String> Optional Custom data added to HTTP headers. 

Return value

Data type Description
HttpResponse Returns native Salesforce HttpResponse.

Example

The following example deletes the association between a station and a user and sends a custom header with the /api/v2/users/{userId}/station/associatedstation endpoint.

HttpResponse response = purecloud.SDK.Rest.del('/api/v2/users/6a50987a-f00c-4b10-b627-4a677f9f0263/station/associatedstation', new Map<String, String>{'CustomHeaderValue' => 'Foo'});

For more information, see SDK in Genesys Cloud for Salesforce.

For more information about the integration, see About Genesys Cloud for Salesforce.