+ Start a Discussion
srikanth reddy 27srikanth reddy 27 

How to add Contacts in Salesforce via REST API

pconpcon
It's pretty straightforward.  As explained in the REST API Developers guide [1]

You would curl against the Contact endpoint
 
curl https://na1.salesforce.com/services/data/v20.0/sobjects/Contact/ -H "Authorization: Bearer token -H "Content-Type: application/json" -d "@newcontact.json"

with the newcontact.json having the following content
 
{
    "FirstName": "Joe",
    "LastName": "Tester",
    "AccountId": "001D000000IqhSLIAZ"
}


[1] https://www.salesforce.com/us/developer/docs/api_rest/
Pavel OrlovPavel Orlov
Hi, I've been through that documentation back and forth.. but I cannot find this particular endpoint/functionality reference. Would you mind pointing me where it might be?
Thanks
Pavel
Pavel OrlovPavel Orlov
Unless it's outdated now now and things are done differently?
Brian RickardBrian Rickard
Hi Pavel, 

Are you talking about a Contact endpoint specifically, or just this type of curl command? The Examples section has similar commands for Creating (POSTing) and Updating (PATCHing) an Account. 

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_create.htm  (https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_create.htm)
Abhishekh KumarAbhishekh Kumar
you guys can use this code for node js..
you have to pass access token as a input.

const getContact = async (accessToken) => {
  console.log('Retrieving a contact from HubSpot using an access token');
  try {
    const  headers = await {
      Authorization: `Bearer ${accessToken}`,
      'Content-Type': 'application/json'
    };
     const result = await request.get('https://na1.salesforce.com/services/data/v20.0/sobjects/Contact/', 
    {
      headers: headers
    });
    const data = JSON.parse(result);
    console.log(data);
    return Promise.resolve(data);
  } catch (e) {
    console.error('  > Unable to retrieve contact');
    return Promise.reject(data);
  }
};
getContact(access_token);

Thanks 
Abhishekh Kumar