About Contacts

About Contacts

Contents

Introduction

For all the API calls, first create an object of the SDK class so that you can access the SDK functions.

To create an object of the SDK class, pass the following information to the SDK constructor:

  • clientKey - obtained when you created an application in Key Management
  • clientSecret - obtained when you created an application in Key Management
  • callbackUrl - HTTP callback address where the user can access the application. Your app must specify it exactly as you have entered it in Key Management as it is case sensitive.
$sdk = new Thingspace\Cloud\Sdk(clientKey,clientSecret,callbackUrl);

Examples

Create Contact

createContacts creates a new contact.

Request Parameters

  • createContacts - Request object to create a contact.

Code Sample

try {
		$response = $sdk->createContacts($jsonContactInfo);
	} catch (Exception $e) {

	 	try
		{
	  	   return $e->getResponse();	
		}
		finally {
		   if(is_object($e->getResponse()))
			{
		   		return $e->getResponse()->getBody()->getContents();
			}
			else
			{
				return false;
			}
		}
	} 
	return $response;

Example Return Response

{
	"version": 0,
	"id": "string"
}

Delete Contact

deleteContact deletes the specified contact.

Request Parameters

  • contactID - Unique ID related to a specific contact.

Code Sample

try {
	$response = $sdk->deleteContact($contactId);
	$response = json_decode($response->getBody()->getContents(),true);
	
	} catch (Exception $e) {
	 	try
		{
	  	   return $e->getResponse();	
		}
		finally {
		   if(is_object($e->getResponse()))
			{
		   		return $e->getResponse()->getBody()->getContents();
			}
			else
			{
				return false;
			}
		}
	} 
	return $response;

Retrieve Contacts

getContactInfo retrieves all contacts of the logged-in user.

Request Parameters

  • query - Contains the value of a field that is stored in contacts which can be used to search for a specific contact or set of contacts. Supported fields are:
    • address
    • email
    • id
    • im
    • name
    • tel
    • field-tag.type, such as address.home
    • address.type.subfield, such as address.home.street
  • sort - Specifies the sort order for the response. Syntax is: {field}+{asc or desc}. Valid values for field are:
    • created
    • favorite
    • firstname
    • id
    • lastname
    • modified
    • version
  • page - Page number to return, for paginated responses. Defaulted to 1.
  • count - Maximum items to include in a paginated response. Default is 200.

Code Sample

try {
	$response = $sdk->getContactInfo($query,$sort,$page,$count);
	$response = json_decode($response->getBody()->getContents(),true);
	} catch (Exception $e) {
	 	try
		{
	  	   return $e->getResponse();	
		}
		finally {
		   if(is_object($e->getResponse()))
			{
		   		return $e->getResponse()->getBody()->getContents();
			}
			else
			{
				return false;
			}
		}
	}
	return $response;

Example Return Response

{
	"contactsResponse": {
		"account": {
			"userid": "string",
			"addrbook": {
				"updated": "string",
				"contacts": {
					"itemcount": 0,
					"contact": [{
						"firstname": "string",
						"lastname": "string",
						"source": "string",
						"note": "string",
						"created": "string",
						"modified": "string",
						"incaseofemergency": true,
						"favorite": true,
						"tel": [{
							"type": "string",
							"indx": 0,
							"number": "string",
							"preference": "string"
						}],
						"email": [{
							"type": "string",
							"indx": 0,
							"address": "string",
							"preference": "string"
						}],
						"address": [{
							"type": "string",
							"indx": 0,
							"pobox": "string",
							"street": "string",
							"city": "string",
							"zipcode": "string",
							"country": "string",
							"preference": "string"
						}],
						"im": [{
							"type": "string",
							"address": "string",
							"preference": "string"
						}],
						"version": 0,
						"id": "string"
					}]
				}
			}
		}
	}
}

NOTE: This SDK returns a maximum of 200 contacts in a successful response.

Update Contact

updateContact updates the specified contacts.

Request Parameters

  • updateContact - Request object to update a specific contact. Version is the madatory field.

Code Sample

try {
		$response = $sdk->updateContact($contact_id,$jsonContactInfo);
	} catch (Exception $e) {

	 	try
		{
	  	   return $e->getResponse();	
		}
		finally {
		   if(is_object($e->getResponse()))
			{
		   		return $e->getResponse()->getBody()->getContents();
			}
			else
			{
				return false;
			}
		}
	} 
	return $response;

Example Return Response

{
	"version": 0,
	"id": "string"
}

Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.