How to set contact primary address

Hi all.

I create new Contact, pass to curl following data:

$url = $baseURL . "/Contacts";
$record = array(
"date_entered" => "$dateEntered",
"assigned_user_id" => "$uid",
"created_by" => "$uid",
"team_id" => "1",
"salutation" => "$title",
"first_name" => "$firstName",
"last_name" => "$lastName",
"phone_work" => "$tel",
"phone_fax" => "$fax",
"email" => array(
"email_address" => "$email",
"primary_address" => true
"primary_address_street" => "$address",
"primary_address_city" => "$city",
"primary_address_postalcode" => "$zipcode",
"primary_address_country" => "$country",

Record is created, all the fields, including email (in email_addresses), are populated, EXCEPT the primary address fields - they are all empty.

What do I need to do to set those fields preferably during creating a Contact if possible.

Thanks for your help,


  • Hi Azriel,

    This seems to work fine for me, here is a sample json payload that I used, which is exactly similar like yours:

    "team_id": "1",
    "first_name": "Azriel",
    "last_name": "The Great",
    "email": [
    "email_address": "",
    "primary_address": true
    "primary_address_street": "Azriel Street",
    "primary_address_city": "Azriel City",
    "primary_address_state": "Azriel State",
    "primary_address_country": "Azriel Country"

    You can try checking your contact layout if you are actually displaying the primary address fields or a different set of customized fields. Or - there could also be some logic hooks or code customizations that could be wiping out your value from API. 

  • I would not quote the php variables as you did e.g. here:

        "primary_address_street"     => "$address",
    "primary_address_city" => "$city",
    "primary_address_postalcode" => "$zipcode",
    "primary_address_country" => "$country",

    php interprets the content between the quotes, so if there is some "strange" content it could break.

    Just use

        "primary_address_street"     => $address,
    "primary_address_city" => $city,
    "primary_address_postalcode" => $zipcode,
    "primary_address_country" => $country,

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    SugarCRM Deutschland GmbH