# ClickSend Cloud Mode Integration

After you have successfully instrumented ClickSend as a destination in RudderStack, follow this guide to correctly send your events to ClickSend in [cloud mode]({{< ref "/destinations/rudderstack-connection-modes.md#cloud-mode" >}}).

Find the open source transformer code for this destination in the [GitHub repository](https://github.com/rudderlabs/rudder-transformer/tree/main/src/cdk/v2/destinations/clicksend).

## Identify

You can use the [`identify`]({{< ref "event-spec/standard-events/identify.md" >}}) call to [create a new contact or update an existing one](https://developers.clicksend.com/docs/rest/v3/#create-new-contact) in ClickSend.

A sample `identify` call is shown:

```javascript
rudderstack.identify("userId123", {
  "email": "alex@example.com",
  "firstName": "Alex",
  "lastName": "Keener",
  "phone": "1234567890",
  "address": {
    "city": "New York",
    "country": "USA",
    "pinCode": "123456"
  },
  "integrations": {
    "All": true
  },
  "externalId": [{
    "type": "CLICKSEND_CONTACT_LIST_ID",
    "id": "<dummy-id>"
  }]
}
});
```

### Supported mappings

RudderStack maps the following `identify` fields to the corresponding ClickSend properties:

| RudderStack event/property | ClickSend event/property | Note |
| :---- | :----| :---- |
| `message.traits.phone`<br />`context.traits.phone` <br/> <span style="color: #4D4DFF;font-size:12px;">Required, if `fax_number` and `email` are absent.</span> | `phone_number` | Phone number in [E.164](https://en.wikipedia.org/wiki/E.164) format. |
| `traits.email`<br />`context.traits.email` <br/> <span style="color: #4D4DFF;font-size:12px;">Required, if `fax_number` and `phone_number` are absent.</span> | `email` | - |
| `traits.fax_number`<br />`context.traits.fax_number` <br/> <span style="color: #4D4DFF;font-size:12px;">Required, if `email` and `phone_number` are absent.</span> | `fax_number` |- |
| `CLICKSEND_CONTACT_LIST_ID` from `externalId` <span style="color: #4D4DFF;font-size:12px;">Required</span> | Sent as a part of the API URL. | Rudderstack uses this `list_id` to create contacts in it. |
| `traits.firstName`<br />`context.traits.firstName` | `first_name` | - |
| `traits.address`<br />`traits.address_line_1`<br />`context.traits.address`<br />`context.traits.address_line_1` | `address_line_1` | - |
| `traits.address_line_2`<br />`context.traits.address_line_2` | `address_line_2` | - |
| `traits.address.city`<br />`context.traits.address.city` | `address_city` | - |
| `traits.address.state`<br />`context.traits.address.state` | `address_state` | - |
| `traits.address.address_postal_code`<br />`context.traits.address.address_postal_code` | `address_postal_code` | - |
| `traits.country`<br />`context.traits.country` | `address_country` | - |
| `traits.organization_name`<br />`context.traits.organization_name` | `organization_name` | - |
| `traits.lastName`<br />`context.traits.lastName` | `last_name` | - |
|  `CLICKSEND_CONTACT_ID` from `externalId` | `contact_id` | Use this property to send the `contact_id` if you want to update an existing contact. <br /> If absent, Rudderstack creates a new contact which can lead to the duplication. |


## Track

You can use the [`track`]({{< ref "event-spec/standard-events/track.md" >}}) call to send text messages to ClickSend.

A sample `track` call to trigger an SMS campaign for the entire list:

```javascript
rudderanalytics.track(
  "event1", {
    "name": "new campaign",
    "body": "message",
    "from": "alex@example.com",
    "from_email": "keener@sample.com"
  }, {
    externalId: [{
      type: 'CLICKSEND_CONTACT_LIST_ID',
      id: '12345',
    }, ],
  }
  () => {
    console.log("track call");
  }
);
```

A sample `track` call to send SMS to a single contact:

```javascript
rudderanalytics.track("event1", {
    "name": "new campaign",
    "body": "message",
    "from": "alex@example.com",
    "from_email": "keener@sample.com",
    "custom_string": "test string"
  },
  () => {
    console.log("track call");
  }
);
```

### Supported mappings

RudderStack maps the following `track` fields to the corresponding ClickSend properties:

| RudderStack property | ClickSend property | Note |
| :---- | :---- | :---- |
| `externalId.clicksend.From`<br />`config.defaultSenderEmail` <br /><span style="color: #4D4DFF;font-size:12px;">Required</span> | `from` | Sender ID.|
| `context.traits.phone` <br /><span style="color: #4D4DFF;font-size:12px;">Required</span> | `to` | Recipient's phone number in [E.164](https://en.wikipedia.org/wiki/E.164) format. |
| `properties.body` <br /><span style="color: #4D4DFF;font-size:12px;">Required</span> | `body` | Your message. |
| `properties.channel`<br />`config.channel` | `channel` | Method of sending the text message. For example, wordpress, php, c#, etc. |
| `properties.schedule`<br />`config.schedule` | `schedule` | Schedule time in [UNIX format](http://help.clicksend.com/what-is-a-unix-timestamp). Set it as `0` for immediate delivery. |
| `properties.custom_string` | `custom_string` | Your reference which is passed back with all the replies and delivery reports. |
| `externalId.clicksend.list_id` | `list_id` | List ID if sending to a whole list. You can use this instead of `context.traits.phone`. <br/><br/> **If using this, ensure that a particular list does not exceed 20000 contacts.** |
| `context.traits.country` | `country` | ISO alpha-2 character country code. For example, `US` - It is used to format the recipient number if it's not in international format. |
| `properties.from_email` | `from_email` | Email address to send the reply. If omitted, the reply is emailed back to the user who sent the outgoing SMS. |
