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
kallam salesforce1kallam salesforce1 

I am trying to insert multiple contact records by using RESTAPI Post Method. Getting error after sending request.

Can some one help me error in Code.

 @HttpPost
    global static String CreateContacts(){
        RestRequest request = RestContext.request;
        String requestBody = request.requestBody.toString();
       
       list<Contact> listcon = (List<Contact>) JSON.deserialize(requestBody, contact.class);
       if(!listcon.isEmpty()){
        insert  listcon;
        return 'SUCCESS';
       }
       else{
           return 'Failed';
       }
    }

REquest Body >>

[{
  "FirstName" : "Test2",
  "LastName"  : "Vasu"
},
{
  "FirstName" : "Test3",
  "LastName"  : "Vasu"
}
]

Getting error 

 APEX_ERROR
message: System.JSONException: Json Deserialization failed on token 'null' and has left off in the middle of parsing a row. Will go to end of row to begin parsing the next row Class.System.JSON.deserialize: line 15, column 1 Class.AccountManager.CreateContacts: line 59, column 1 

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Kallam,

Can you check if below answer helps you to resolve your issue.

https://stackoverflow.com/questions/55620069/how-to-pass-multiple-records-in-rest-api-post-method-using-json-body

If this solution helps, Please mark it as best answer.

Thanks,