Last updated on Apr 7

2 min read

Contacts API

Samespace provides an API to manage contacts in your Samespace account. With this API, you can create, delete, and update contacts.

GraphQL Endpoint & Header Details

Endpoint https://clusterid.samespace.com/crm/api
x-api-key XoaFDQ34c@NIs!AvGgCYe2jmCppr43FR

Note: For the Contacts API to work, an API key with type “Voice” is required. Only users with "Admin" access can create the same in the settings section.

Get Contacts

This API enables users to get a list of contacts created in their Samespace account.

Query

query GetContacts($moduleName: String, $payload: GetContactsInput) 
{
  getContacts(moduleName: $moduleName, payload: $payload) 
  {
    _id
    module
    properties
  }
}

Response

{
    "data": {
        "getContacts": [
            {
                "_id": "639ffb55f6157c6ca7d39fb6",
                "module": "6303289128a0e96163bd0dcd",
                "properties": {
                    "firstName": {
                        "value": "Kris",
                        "type": "TEXT"
                    },
                    "lastName": {
                        "value": "Merrier",
                        "type": "TEXT"
                    },
                    "email": {
                        "value": "[email protected]",
                        "type": "EMAIL"
                    },
                    "phoneNumber": {
                        "value": "555-555-5555",
                        "type": "PHONE"
                    },
                    "owner": {
                        "value": "62da90cb9fcc0cfec12a2d80",
                        "type": "REFERENCE"
                    },
                    "createdBy": {
                        "value": "62da90cb9fcc0cfec12a2d80",
                        "type": "REFERENCE"
                    },
                    "createdAt": {
                        "value": "2022-12-19T05:49:09.557Z",
                        "type": "DATE_TIME"
                    }
                }
            }
        ]
    }
}

Create Contacts

This Open API enables you to create contacts.

Mutation

mutation CreateContact($payload: CreateContactInput!) 
{
  createContact(payload: $payload) 
  {
    _id
    module
    properties
  }
}

Payload

{
  "payload": {
    "module": "6303289128a0e96163bd0dcd",
    "properties": [
      {
        "key": "firstName",
        "value": "Sarah"
      },
      {
        "key": "lastName",
        "value": "Taylor"
      },
      {
        "key": "email",
        "value": "[email protected]"
      },
      {
        "key": "phoneNumber",
        "value": "9999999999"
      }
    ]
  }
}

Response

{
    "data": {
        "createContact": {
            "_id": "63f73588fefbc39bcac88af7",
            "module": "6303289128a0e96163bd0dcd",
            "properties": {
                "firstName": {
                    "value": "Sarah",
                    "type": "TEXT"
                },
                "lastName": {
                    "value": "Taylor",
                    "type": "TEXT"
                },
                "email": {
                    "value": "[email protected]",
                    "type": "EMAIL"
                },
                "phoneNumber": {
                    "value": "9999999999",
                    "type": "PHONE"
                },
                "owner": {
                    "value": "6384a0855fab959a1618e103",
                    "type": "REFERENCE"
                },
                "createdBy": {
                    "value": "6384a0855fab959a1618e103",
                    "type": "REFERENCE"
                },
                "createdAt": {
                    "value": "2023-02-23T09:44:40.328Z",
                    "type": "DATE_TIME"
                }
            }
        }
    }
}

Update Contacts

The API uses the Contact ID to update a single contact’s details.

Mutation

mutation UpdateContacts($payload: UpdateContactsInput!)
{
  updateContacts(payload: $payload)
}

Payload

{
  "payload": {
    "module": "6303289128a0e96163bd0dcd",
    "_id": "63f73588fefbc39bcac88af7",
    "properties": [
      {
        "key": "lastName",
        "value": "Jones"
      }
    ]
  }
}

Response

{
    "data": {
        "updateContacts": {
            "success": true,
            "message": "Contact updated"
        }
    }
}

Delete Contacts

This API is used to delete multiple contacts.

Mutation

mutation DeleteContacts($payload: DeleteContactsInput!) {
  deleteContacts(payload: $payload)
}

Payload

{
  "payload": {
    "module": "6303289128a0e96163bd0dcd",
    "_id": "63f73588fefbc39bcac88af7"
  }
}

Response

  {
    "data": {
        "deleteContacts": {
            "success": true,
            "message": "Contact deleted"
        }
    }
}