Get contacts

From PokeTALK developers

Jump to: navigation, search

Contents

Description

Returns user contact list

Usage

    ptAddressbook.get_contacts(callback);

or

    var result = ptAddressbook.get_contacts();

Parameters

Required Name Type Description
optional callback function optional callback function to call after execution

Response

object (JSON)

 
    {"result":[
            {"id":integer,
             "contact_name":string,
             "company":string,
             "code":string,
             "value":string,
             "code_1":string,
             "value_1":string,
             "code_2":string,
             "value_2":string,
             "email":string },
            {...},
            {...},
            {...}
        ]
    }
Parameter Type Description
result variable returns user addressbook items array, false otherwise.
Array
Parameter Type Description
id integer contact ID.
contact_name string contact name.
company string contact company.
code string first phone number country prefix.
value string first phone number (landline).
code_1 string second phone number country prefix.
value_1 string second phone number (mobile).
code_2 string third phone number country prefix.
value_2 string third phone number (office).
email string contact e-mail.

Example

Use result object

function print_contacts(){
    var item;
    var html = "";
    // insert user contact list into data object
    var data = ptAddressbook.get_contacts();
    if(!data.result){
        alert('Your addressbook is empty');
        return;
    }
    // get contact list length
    var len = data.result.length;
    // create contact list HTML
    for(var i=0; i<len; i++){
        item = data.result[i];
        html += "Name: "+item.contact_name+" Phone:+"+item.code+"-"+item.value+"<br />";
    }
    // print HTML
    document.write(html);
}

Use callback function

/* insert user contact list into data object */
ptAddressbook.get_contacts(function(data){
    if(!data.result){
        alert('Your addressbook is empty');
        return;
    }
    var item;
    var html = "";
    // get contact list length
    var len = data.result.length;
    // create contact list HTML
    for(var i=0; i<len; i++){
        item = data.result[i];
        html += "Name: "+item.contact_name+" Phone:+"+item.code+"-"+item.value+"<br />";
    }
    // print HTML
    document.write(html);
});