Skip to content

Add contact

rudwan97 edited this page Jun 20, 2018 · 12 revisions

Authentication

To use the actions that have been published by team IFTTT-CM you will need certain information to perform the actions without any issues. CM requires a certain amount of data to successfully send an SMS via the Action Send SMS action. And IFTTT requires a IFTT-Service-Key to use their API, once you register your own applet, you should recive an unique IFTTT-Service-Key. For local testing, we will use the 12345 IFTTT-Service-Key just like we did in subsection 1.2.

1. General

The action 'Add contact' is used for adding a contact to the address book of CM. The address book on CM can be used to easily send multiple SMS's. An user is able to find the address book on the website of CM. As mentioned before, the API made by the IFTTT-CM will 'translate' the data, and finally the translated information will be sent to the API of CM.

2. Explaining the add contact endpoint

As mentioned in the introduction of this wiki, all of the explanation will be in the context of testing locally. The endpoint of the address book v2 is:

localhost:3000/api/ifttt/v1/actions/add_contact

We will also need the following header:

Content-Type: application/json
IFTTT-Service-Key: 12345

3. Posting from IFTTT to this API

The add contact action is a bit different than all of the other actions. The endpoint can be adjusted, depending on multiple information. A full CM endpoint URL with all of the information, looks like this:

https://api.cmtelecom.com/addressbook/v2/accounts/${accountID}/groups/${groupID}/search?query=${queryString}

As you can see, there are three variables that are required for the endpoint of CM: accountID, groupID and queryString. This information can be obtained via the body that has been sent from IFTTT. This is a correct body:

{
  "actionFields": {
    "email": "fake",
    "firstName": "fake",
    "lastName": "fake",
    "insertion": "fake",
    "groupID": "fake",
    "phoneNumber": "0031612345678",
    "accountID": "fake",
    "token": "fake"
  },
  "user": {
    "timezone": "America/Los_Angeles"
  },
  "ifttt_source": {
    "id": "7fb8cb36024a2a4b",
    "url": "http://example.com/7fb8cb36024a2a4b"
  }
}

4. Conversion of the data on the IFTTT-CM API

Before we convert the data to be ready to be send to the CM The cmContact that will look like this:

email: contact.email,
firstName: contact.firstName,
lastName: contact.lastName,
insertion: contact.insertion,
groupID: contact.groupId,
phoneNumber: contact.phoneNumber

5. The request to CM

Finally, the request to CM will look like this:

    request({
        url: `https://api.cmtelecom.com/addressbook/v2/accounts/${accountID}/groups/${groupID}/contacts`,
        headers: {
            "X-CM-PRODUCTTOKEN": token,
        },
        method: "POST",
        json: true,
        body: contact

§1 Introduction

§2 Actions

Credits

The Team

Clone this wiki locally