Skip to main content

Sparkcentral CRM API v2

Sparkcentral CRM integration allows you to pull customer contact data from CRMs or other internal business applications into Sparkcentral. To integrate your CRM with Sparkcentral, you need to provide an HTTPS endpoint for lookups. You can also provide an optional HTTPS endpoint for handling write back requests and an HTTP endpoint Sparkcentral to send notifications from our application to your CRM.

Webhooks​

Webhook authentication​

When receiving data from Sparkcentral, we provide two authentication options. Both mechanisms are in place so that you can make sure the request originates from Sparkcentral.

Shared secret​

If you choose the shared secret authentication method, a secret will be generated for you. This secret allows you to calculate the signature to verify that the call originated from Sparkcentral. With this mechanism, every single request from Sparkcentral contains the X-Hootsuite-Signature header. Here's an example of a request:

curl -X POST https://my-webhook-url \
-H 'content-type : application/json' \
-H 'accept: application/json' \
-H 'X-Hootsuite-Signature: e6f93239a06e46ae9654fc9ad2fb4e1cc4eb213830a0d94e711570c047e43c57' \
-d '{
"version": 2,
"contactProfile": {
"id": "a7a20053-9c54-11eb-a89f-47717a44c639"
},
"contactAttributes": [
{"attribute": "email", "value": "fj@example.com"}
]
}'

The signature is generated using the HMAC-SHA256 algorithm with the shared secret and the request body. Use your secret to calculate the signature and compare with the given signature. Both the secret key you received and the signature are encoded as hexadecimal strings. Make sure to convert the shared secret from its hexadecimal representation to its binary format before using it. Most languages come with libraries out of the box to verify this signature. For example, here's how it looks in JavaScript:

const crypto = require("crypto");
const hootdeskSecret = "..."; // do not share!
const expectedSignature = request.headers["X-Hootsuite-Signature"];
const actualSignature = crypto
.createHmac("sha256", Buffer.from(hootdeskSecret, "hex"))
.update(request.body, "utf-8")
.digest("hex");
if (actualSignature !== expectedSignature) {
throw new createError.Unauthorized("X-Hootsuite-Signature wrong");
}
console.log(JSON.parse(request.body).email);

OAuth​

If your endpoints support OAuth2, you can configure your client credentials, a Token URL, and, optionally, a Scope in Sparkcentral.

We use the OAuth2 Client Credentials flow to authenticate against your CRM. The Token URL is the endpoint where we can authenticate with these credentials and retrieve an access token. To do the actual lookup, write back, or notification requests, we use the token in the Authorization Header to authenticate.

Contact attribute lookup​

Sparkcentral CRM integration allows you to pull customer contact data from CRMs or other internal business applications into Sparkcentral. To integrate your CRM with Sparkcentral, you need to provide an HTTPS endpoint for lookups.

Create contact attributes​

  1. In Sparkcentral, go to Admin settings, expand Agent Workspace, select Contact attributes, and then select Add attribute.

  2. Select Managed by CRM.

    The CRM is the source of truth for these attributes. After they are imported into Sparkcentral, they only change when the value changes in the CRM.

  3. Identify lookup attributes by selecting Use as lookup attribute.

    These are used by the CRM to find a customer's data. For example, if you want to find a customer by email address, create an attribute called "Email" and designate it as a lookup. When the request is made from Sparkcentral to your CRM, the lookup fields are included in the request body.

  4. In the Unique identifier box, enter an alias for the lookup attribute.

    This is used to map the response from your system to the attribute.

Configure integration URL​

To pull data from your CRM into Sparkcentral, you need to implement a POST endpoint that accepts a JSON request and returns a JSON response. The request contains the lookup attributes, and the response should contain the contact data from your CRM.

After the endpoint is implemented, configure it as the lookup URL:

  1. Go to Admin settings.
  2. Expand Integration and APIs.
  3. Select CRM.

Handle the request​

When the endpoint in your system is ready and configured in Sparkcentral, and one or more lookup attributes have been identified, you can make a request via the Lookup button in the conversation view. This triggers the CRM attribute lookup event.

After you've done the lookup in your system, pass attributes back to Sparkcentral as a JSON response. The keys in the attributes object correspond to the aliases that were previously added in Sparkcentral. If a CRM managed attribute is missing from the object or the key has a null value, its value is deleted in Sparkcentral. Sparkcentral expects the response in this format:

{
"autoConfirm": false,
"contactAttributes": [
{"attribute": "email", "value": "fj@example.com"},
{"attribute": "id", "value": "98765432"},
{"attribute": "first_name", "value": "Fred"},
{"attribute": "last_name", "value": "Jones"},
{"attribute": "last_order_number", null}
]
}

Asynchronous Response​

You can also return a 200 OK back without a body and call our REST api to send back the result of the lookup request. Call the following REST endpoint:

curl --request PUT 'https://platform.hootsuite.com/hootdesk/v2/contact/{contactProfileId}/contact-attributes' \
--header 'content-type: application/json' \
--header 'Authorization: BEARER <token>' \
--data-raw '{
"autoConfirm": false,
"contactAttributes": [
{"attribute": "email", "value": "fj@example.com"},
{"attribute": "id", "value": "98765432"},
{"attribute": "first_name", "value": "Fred"},
{"attribute": "last_name", "value": "Jones"},
{"attribute": "last_order_number", null}
]
}'

Confirm your attributes​

The CRM attributes sent back in the response must be confirmed before they are saved in Sparkcentral. There are two ways to do that:

  • Select the Confirm button when you see the CRM attributes displayed in Sparkcentral after the lookup request.
  • Add an autoConfirm field to the response.

The autoConfirm field tells Sparkcentral to automatically save the attributes without having to use the Confirm button.

AUTHORIZATIONS: (Oauth2ClientCredentials) OR (SharedSecret)

REQUEST BODY SCHEMA: application/json

property name*string

Responses​

200 Returns the attributes to be updated in Sparkcentral.​

RESPONSE SCHEMA: application/json

autoConfirmboolean
Tells Sparkcentral to automatically save the attributes without having to use the Confirm button.
contactAttributesArray of objects
Array of JSON objects containing the lookup attributes
4xx Lookup failed​
5xx Lookup failed​

Request samples​

Content type: application/json

{
"my-customer-id": "123"
}

Response samples​

200

Content type: application/json

{
"autoConfirm": true,
"contactAttributes": [
{
"attribute": "email",
"value": "fj@example.com"
},
{
"attribute": "id",
"value": "98765432"
},
{
"attribute": "first_name",
"value": "Fred"
},
{
"attribute": "last_name",
"value": "Jones"
},
{
"attribute": "last_order_number",
"value": null
}
]
}

Contact attribute lookup error notifications event​

When attribute update validation errors occur, Sparkcentral sends a request to the configured notification URL.

Configure notification URL​

When you send your CRM managed contact attributes, Sparkcentral does some validation on the response. To see validation errors, we've provided a way to send notifications from Sparkcentral to your system. You need to provide a POST endpoint that accepts a JSON request body. Configure a notification URL on the same screen where you configured a lookup URL:

  1. Go to Admin settings.
  2. Expand Integration and APIs.
  3. Select CRM.

Handle the request​

When validation errors occur, Sparkcentral sends a request to the configured notification URL. A request looks like this. [link missing]

The request contains these two fields:

  • eventType
  • messages: an array of explicit error messages

The following are the event types that can be sent by Sparkcentral.

Event typeDescription
DATA_IMPORT_ERRORError occurred while pulling data from the CRM to Sparkcentral.

The response to this request can be a 204. Sparkcentral does not expect anything in the response body.

AUTHORIZATIONS: (Oauth2ClientCredentials) OR (SharedSecret)

REQUEST BODY SCHEMA: application/json

timestampstring <date-time>
versioninteger
eventTypestring
Value: "DATA_IMPORT_ERROR"
messagesArray of strings
An array of explicit error messages

Responses​

204 To indicate that the notification was received successfully​
4xx Could not process notification​
5xx Could not process notification​

Request samples​

Content type: application/json

{
"timestamp": "2019-08-24T14:15:22Z",
"version": 2,
"eventType": "DATA_IMPORT_ERROR",
"messages": [
"testMessage1 key:testKey1 value:testValue1",
"testMessage2 key:testKey2 value:testValue2"
]
}

CRM write back event​

You can be notified whenever a conversation has taken place in Sparkcentral (CONVERSATION_RESOLVED) or an agent has set a current conversation to Pending (CONVERSATION_SET_TO_PENDING). This allows you to save conversation details to your existing CRM system. Other use cases include triggering CSAT surveys, case creation, and expanded customer insights from social media profiles.

Configure write back URL​

To push data from Sparkcentral into your CRM, you need to implement a POST endpoint that accepts a JSON request and returns a JSON response. The request contains write back payload, and the response's status code represents your ability to parse the payload and the CRM's ability to ingest the data.

Configure the endpoint as the Write Back URL:

  1. Go to Admin settings.
  2. Expand Integration and APIs.
  3. Select CRM.

Handle the request​

When the endpoint in your system is ready and configured in Sparkcentral, and relevant events occur within Sparkcentral, requests are sent to the configured endpoint. All decoded write back payloads have the following fields:

  • type: A string that defines what kind of write back request is being processed. Used to suggest the structure of the data field.
  • version: A number designating the version of the type of request. Used to mark changes to the data field structure.
  • idempotencyKey: A string that uniquely identifies each event to write back. Used to help ensure that each request is processed only once.
  • data: An object that contains structured data for the specific type of write back. For example, a CONVERSATION_RESOLVED type event has fields such as medium, channel, messages*, notes, topics, contactProfile*, attributes*, and agent, among others.

* Applies to all mediums except Twitter. Twitter handle, tweets, and direct message transcripts, and Twitter medium contact attributes (Twitter name, number of followers, etc.), are not sent in the payload, to conform to Twitter's data use policies.

CONVERSATION_RESOLVED and CONVERSATION_SET_TO_PENDING events​

Events with a type of either CONVERSATION_RESOLVED or CONVERSATION_SET_TO_PENDING have the structure defined.

Write back retry​

If the write back request times out or the endpoint returns a non-success (2XX) status code, Sparkcentral retries with exponential backoffs. The requests are sent again with a delay of 1, 2, 4, 8, 16, and 32 hours after each retry (a total of 6 requests), as long as the request does not succeed. If the request still has not succeeded after 6 requests, we store the failed request details for future reference. We recommend that you inspect the endpoint logs regularly to ensure that write back requests are properly processed the first time. To distinguish between unique events, each request is given an Idempotency key.

Idempotency key​

The write back requests from Sparkcentral make use of an Idempotency key, which allows the write back endpoint to ensure it processes each request once. This key helps when requests are sent multiple times during the retry schedule, so the endpoint can handle requests in an idempotent way. The key is unique per request.

AUTHORIZATIONS: (Oauth2ClientCredentials) OR (SharedSecret)

REQUEST BODY SCHEMA: application/json

timestampstring <date-time>
idempotencyKeystring
A string that uniquely identifies each event. Used to help ensure that each request is processed
versioninteger
A number designating the version of the type of request. Used to mark changes to the data field structure.
typestring
Enum: "CONVERSATION_RESOLVED" "CONVERSATION_SET_TO_PENDING"
dataobject

Responses​

2xx The response status code represents your ability to parse the payload and the CRM's ability to ingest the data.​
4xx The response status code represents your ability to parse the payload and the CRM's ability to ingest the data. Any non-2XX response status code will be retried.​
5xx The response status code represents your ability to parse the payload and the CRM's ability to ingest the data. Any non-2XX response status code will be retried.​

Request samples​

Content type: application/json

{
"timestamp": "2022-03-28T09:43:26.635984618Z",
"idempotencyKey": "6ebc6a78-d9e9-48be-b172-51eda40b7af8",
"version": 1,
"type": "CONVERSATION_RESOLVED",
"data": {
"conversation": {},
"medium": {},
"channel": {},
"agent": {},
"contactProfile": {},
"statusUpdatedReason": "5fd023f6-2e66-11eb-be07-092841b0717d - Response Not Required",
"statusUpdatedComment": "not a question",
"messages": [],
"contactAttributes": [],
"notes": [],
"topics": []
}
}

REST API​

If you want to update contact attributes asynchronously, you'll need to call the Contact API. When calling the Contact API, the client needs to be authenticated.

The REST API authentication section contains more details on how to authenticate your client. [add link]

Set contact attributes​

Update the contact attributes of a contact profile.

AUTHORIZATIONS: Bearer token

PATH PARAMETERS​
contactProfileIdrequired
string
Id of the contact profile that you want to update.
REQUEST BODY SCHEMA: application/json​
autoConfirmboolean
The autoConfirm field tells Sparkcentral to automatically save the attributes without having to use the Confirm button.
contactAttributesArray of objects
Array of JSON objects containing the lookup attributes

Responses​

200 Success​

RESPONSE SCHEMA: application/json object

400 The request is malformed.​
401 Unauthorized: when using an invalid or expired access token.​
404 Contact profile not found in organization​

URI​

PUT /hootdesk/v2/contact/{contactProfileId}/contact-attributes

Request samples​

Content type: application/json

{
"autoConfirm": true,
"contactAttributes": [
{
"attribute": "email",
"value": "fj@example.com"
},
{
"attribute": "id",
"value": "98765432"
},
{
"attribute": "first_name",
"value": "Fred"
},
{
"attribute": "last_name",
"value": "Jones"
},
{
"attribute": "last_order_number",
"value": null
}
]
}