About Contacts

About Contacts

Contents

Introduction

Java SDK allows you to retrieve, create, update, and delete contacts. The following examples will help you to get started with contacts.

Examples

Creating a Contact

createContact method allows you to create a new contact in the user’s Personal Cloud Storage account.

Code Sample

public void createContact(OAuthToken token) throws IOException, CloudHttpException
{
	CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
	CloudClientContext context = new CloudClientContext(app, token);
	CloudClient client = new CloudClient(context);
	    
	Contact contact = new Contact.Builder().firstName("ryan").favorite(true).build();
	
	contact = cloudClient.createContact(contact);
}

Deleting a Contact

deleteContact method deletes a contact stored in the user’s Personal Cloud Storage account.

Code Sample

public void deleteContact(OAuthToken token) throws IOException, CloudHttpException
{
	CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
	CloudClientContext context = new CloudClientContext(app, token);
	CloudClient client = new CloudClient(context);
	    
	// contact object returned from getContacts, createContact, or updateContact method
	client.deleteContact(contact);
	
	String contactId = contact.getId();
	
	// contacts can also be deleted by id
	client.deleteContact(contactId);
}

Retrieving Contacts

getContacts method retrieves contacts stored in the user’s Personal Cloud Storage account.

Code Sample

public void contacts(OAuthToken token) throws IOException, CloudHttpException
{
    CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
    CloudClientContext context = new CloudClientContext(app, token);
    CloudClient client = new CloudClient(context);

    // retrieve the first 50 contacts whose last name begins with 'A', sorted by last name.
    Contacts contacts = client.getContacts("lastname:A*", "lastname+asc", 1, 50);
    for (Contact contact : contacts.getContacts())
    {
        // print the contact's name and mobile number.
        for (ContactTelephone tel : contact.getTels())
        {
            if ("mobile".equals(tel.getType()))
                System.out.println(contact.getFirstName() + " " + contact.getLastName() + "'s mobile phone: " + tel.getNumber());
        }
    }
}

Updating Contacts

updateContact method allows you to update an existing contact stored in the user’s Personal Cloud Storage account.

Code Sample

public void updateContact(OAuthToken token) throws IOException, CloudHttpException
{
	CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
	CloudClientContext context = new CloudClientContext(app, token);
	CloudClient client = new CloudClient(context);
	    
	// contact object returned from getContacts, createContact, or updateContact method
	
	contact.setFirstName("mike");
	contact.setFavorite(false);
	contact = cloudClient.updateContact(contact);
}

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

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