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
forceDeveloperforceDeveloper 

Integration issue Salesforce Rest Api -POST Call

Hi to All,

I am new in SF Integration. I am making a POST call using REST Api and getting the error.

My Code:
global class AccountMagentoSync{
    
   @future(callout=true)
    public static void AccountUpdate(String id,String firstName,String lastName,String email){

        if(consumerKey!=null){

            //String endPoint='https://requestbin.fullcontact.com/12k5hkb1/';
            String endPoint='https://pro-stage.cdeuat.com/rest/V1/customers/';
            String jsonstr='{"email":"'+email+'","firstName":"'+ firstName +'","lastname":"'+ lastName +'","storeId":"'+ Integer.ValueOf('1') +'","websiteId":"'+ Integer.ValueOf('1')+'"}';
   
            System.debug('###jsonstr:::'+jsonstr);
            Http h2= new Http();
            HttpRequest req2= new HttpRequest();
            req2.setHeader('Authorization','Bearer ' + consumerKey);
            req2.setHeader('Content-Type','application/json');            
            req2.setHeader('Accept','application/json');
            req2.setBody(jsonstr);
            req2.setMethod('POST');
            req2.setEndpoint(endPoint);
            HttpResponse res2=h2.send(req2);
            System.debug('###req2:::'+req2);
            System.debug('###Res2:::'+res2);
            
            if (res2.getStatusCode() == 200) {
                System.debug('The status code returned as expected: ' +
                             res2.getStatusCode() + '---' + res2.getStatus());
            }

        }
    }
    }

Error I am getting :
10:59:32.14 (14718389)|CODE_UNIT_STARTED|[EXTERNAL]|01p0x000000FRwF|AccountMagentoSync.AccountUpdate(String, String, String, String)
10:59:32.14 (15381092)|USER_DEBUG|[15]|DEBUG|###jsonstr:::{"email":"try@gmail.com","firstName":"userFirstName","lastname":"userLastName","storeId":"1","websiteId":"1"}
10:59:32.14 (296125668)|USER_DEBUG|[25]|DEBUG|###req2:::System.HttpRequest[Endpoint=https://pro-stage.cdeuat.com/rest/V1/customers/, Method=POST]
10:59:32.14 (296169241)|USER_DEBUG|[26]|DEBUG|###Res2:::System.HttpResponse[Status=Bad Request, StatusCode=400]

Please help to resolve this issue

Any help is highly appreciated