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
Michael MMichael M 

Composing sample JSON for post request

I am new to integrations, so this may be a very basic question. I need to create a mock up of JSON of a sample Salesforce record, to ultimately be able to post to an external API. My question is: is there any required context for constructing the JSON? E.g. do the field names need to equal the API names in salesfroce (e.g. {
  "Lead" : [ {
    "bed_count__c" : 55}]}

Or- can I assign the fields any name I want? Apologies if this is very basic, but your assitance is greatly helpful. 
Best Answer chosen by Michael M
sachinarorasfsachinarorasf
Hi Michael,

You have to use API names of fields related to object to create, update, delete or any other operation which you want to do using integration.

To write a new Salesforce record, we use a POST request:

https://<yourInstance>.salesforce.com/services/data/v<version>/sobjects/<objectName>/

In the body of the POST request, provide the record data in application/json format:

{
    <field1ApiName>: <field1Value>,
    <field2ApiName>: <field2Value>,
    ...
}

You do not need to provide an ID field to Salesforce when creating records, as Salesforce will generate a unique ID value and return it in the response.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
www.sachinsf.com
 

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Michael,

If I get the question right you want to understand "if you can give any name to the fields or if you will have to use the api names"

To my knowledge you will have to use API names of the fields so that the system can identify the fields when you are doing the operations using the integrations.

Hope I have answered your query please close the thread by marking a best answer so that it would help in keeping our community clean and it might help other people in the future.

Regards,
Anutej.
sachinarorasfsachinarorasf
Hi Michael,

You have to use API names of fields related to object to create, update, delete or any other operation which you want to do using integration.

To write a new Salesforce record, we use a POST request:

https://<yourInstance>.salesforce.com/services/data/v<version>/sobjects/<objectName>/

In the body of the POST request, provide the record data in application/json format:

{
    <field1ApiName>: <field1Value>,
    <field2ApiName>: <field2Value>,
    ...
}

You do not need to provide an ID field to Salesforce when creating records, as Salesforce will generate a unique ID value and return it in the response.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
www.sachinsf.com
 
This was selected as the best answer
Michael MMichael M
THank you both for your replies. What I need to do is move data that's already in Salesfroce (on the Lead object), and we will be pushing this data to outside of Salesforce. For that JSON, would the same apply- for example would I need to write custom fields with "__c" at the end? 

Also, how would I write files that are attached to the record into the JSON?