+ Start a Discussion
Satyavathi PolepallySatyavathi Polepally 

How to pass multiple records in REST API POST method using JSON body

Hi I have a requirement where I need to create multiple records in my custom object using REST API POST method.
Now the problem is I am able to create one record at a time and I am not able to create multiple records in one REST API call. I have found on net by passing JSON request body i will be able to create multiple records. 
I am completely new to integration and don't understand how to create mutilple records in one REST API call and how can i pass JSON request body in my REST API.

Can somebody help me in achiving my requirement please.
Here I am posting my code for reference: 
@HttpPost
    global static ID createListofAddresses(String Address, String City, String CompanyName, String CountryCode, String FirstName,
                                      String LastName, String Phone, String PostalCode, String StateCode, String Email
                                       ) {
        //First find the contact id matching the email.
        String ContactId = [SELECT Id
                              FROM Contact
                              WHERE Email = :Email].Id;
        //Second post the new ListofAddresses to the owner of the email.                                 
        List_of_Address__c thisListofAddress = new List_of_Address__c(
            Contact__c=ContactId,
            Address__c=Address,
            City__c=City,
            Company_Name__c=CompanyName,
            Country_Code__c=CountryCode,
            First_Name__c=FirstName,
            Last_Name__c=LastName,
            Phone__c=Phone,
            Postal_Code__c=PostalCode,
            State_Code__c=StateCode
        ); 
              /* List<List_of_Address__c> result = [SELECT Address__c, City__c, Company_Name__c,
                                Country_Code__c, First_Name__c, Last_Name__c, Phone__c, Postal_Code__c, State_Code__c
                                   FROM List_of_Address__c
                                WHERE Contact__c = :ContactId];                          
           if(result.size() > 0){
            return null;
             }else{*/
          insert thisListofAddress;
          return thisListofAddress.Id;
          
             }
Saravanan RajarajanSaravanan Rajarajan
Hi Satyavathi,

in your JSON request body Please add another record like this
{
  "name" : "Wingo Ducks 1",
  "phone" : "801-555-8989",
  "website" : "www.Test1.com"
},
{
 "name" : "Wingo Ducks 2", 
"phone" : "707-555-1234", 
"website" : "www.Test2.com"
},
{
 "name" : "Wingo Ducks 3", 
"phone" : "111-555-1111", 
"website" : "www.Test3.com"
}
Saravanan RajarajanSaravanan Rajarajan
Add Mulitple Record

},

Cont with comma
Satyavathi PolepallySatyavathi Polepally
Hi Saravanan,

I have tried passing JSON request body like above but, its giving me an error. Means it is not accepting multiple records. I feel like I need to change my code in REST API. I dont understand how to do that. Can you please help me in that context.