Contacts Quick Links

Contacts API

The client SDK is a JavaScript library that has to be included in your app.

We provide an API that lets you save information about your app users. API calls need to go through your own server. This is necessary because of the use of secret keys for validating, reading and generating JSON Web Tokens. You can use our server SDK to do API calls to our server and to validate, read and generate JSON Web Tokens. For more information and examples, have a look at the Server part of the SDK documentation.

Builder.postContact(url, contact, onSuccess, onError)

Posts a contact. You can also use this function to include more (not change) data to an existing contact. When a new user is created, the SDK will create a cookie with the user id. When a user revisits the website, it will be automatically added to any postContact call.

Parameters

Name Type Description
url String The endpoint of your server that handles the posting a contact.
contact Object The contact object. (see example)
onSuccess Function On success callback function.
onError Function On error callback function.

Example

Builder.postContact() example

const url = 'https://yourserver.com/api/contacts/post'

// Structure of a contact object
const contact = {
   "name":"John Doe",
   "phone":"978978978",
   "company":"Aqua Inc.",
   "email":"johndoe@webmail.com",
   "addresses": [
      {
         "address":"100 Quarter Blvd",
         "address2":"",
         "city":"Ayer",
         "state_code":"MA",
         "state":"Massachusetts",
         "postal_code":"01432",
         "country_code":"US"
      },
      {
         "address":"51 Mystic Place",
         "address2":"Apt 39B",
         "city":"Houston",
         "state_code":"TX",
         "state":"Texas",
         "postal_code":"77001",
         "country_code":"US"
      }
   ]
}

const onSuccess = (response) => {
  console.log(response)
}

const onError = (response) => {
  console.log(response)
}

Builder.postContact(url, contact, onSuccess, onError)

Builder.getContacts(url, scope, offset, limit, onSuccess, onError)

Gets contacts.

Parameters

Name Type Description
url String The endpoint of your server that handles getting contacts.
scope String The scope of the contacts. This can be ‘app’ or ‘site’.
offset String Set an email as an offset for the contacts to get.
limit Number Limit the number of contacts to get (<= 1000, default = 50)
onSuccess Function On success callback function.
onError Function On error callback function.

Example

Builder.getContacts() example

const url = 'https://yourserver.com/api/contacts/get'

const scope = 'app'

const offset = <contact email address>

const limit = 50

//Structure of returned contacts

[
   {
      "name":"James Jacob",
      "phone":"978678945",
      "company_name":"Beta Inc.",
      "email":"jjacob@web.com",
      "created_on":"2018-08-21T16:47:10.0549203"
      "addresses": [
         {
            "address":"75 Parker Road",
            "address2":"",
            "city":"Los Angeles",
            "state_code":"CA",
            "state":"California",
            "postal_code":"90005",
            "country_code":"US"
         }
      ]   
   },
   {
      "name":"John Doe",
      "phone":"978978978",
      "company_name":"Aqua Inc.",
      "email":"johndoe@webmail.com",
      "created_on":"2018-08-22T16:47:10.0549203",
      "modified_on":"2018-08-22T16:47:10.0549203",
      "addresses": [
         {
            "address":"100 Quarter Blvd",
            "address2":"",
            "city":"Ayer",
            "state_code":"MA",
            "state":"Massachusetts",
            "postal_code":"01432",
            "country_code":"US"
         },
         {
            "address":"51 Mystic Place",
            "address2":"Apt 39B",
            "city":"Houston",
            "state_code":"TX",
            "state":"Texas",
            "postal_code":"77001",
            "country_code":"US"
         }
      ]   
   }
]

const onSuccess = (reponse) => {
  console.log(response)
}

const onError = (response) => {
  console.log(response)
}

Builder.getContacts(url, scope, offset, limit, onSuccess, onError)