function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
motti10motti10 

How can I create a new Contact with REST call?

I am trying to create a Contact in SFDC without assigning it an Account or anything else.

I want to create it and then assign it to a case or Asset , etc

 

Any ideas?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

You should be using POST, not PATCH. (23.9 was a typo, which i fixed, its 23.0, but 20.0 should work as well)

All Answers

SuperfellSuperfell

send a POST to /services/data/v23.0/sobjects/contact the payload should be a json or xml document with the fields you want to set, e.g.

 

{ "FirstName" : "Simon", 

  "LastName" : "Fell" }

 

see the REST API docs for more details.

motti10motti10

Hi Simon,

 

Thanks for the response

 

That is what I have been trying, (Code is in Groovy)

 

contact= [
"FirstName":"FName",
"LastName" : "LName"]

def jsonString = JSONObject.fromObject(contact).toString(2)

 

http.request( POST ) {
contentType = JSON
    uri.path = '/services/data/v20.0/sobjects/contact/'
uri.query = [_HttpMethod:'PATCH']
 
 send JSON, jsonString
  headers.'Authorization' = "OAuth $accessToken"
 
 }
}

 

I get a "Method Not Allowed" error. When I use your version v23.9 I get "Not Found"

SuperfellSuperfell

You should be using POST, not PATCH. (23.9 was a typo, which i fixed, its 23.0, but 20.0 should work as well)

This was selected as the best answer
motti10motti10

You are the bomb!!! It works great

 

Thank you so much..