Integrating Salesforce Rest API with SFCC

I

1. The process is to integrate the Sales cloud and commerce cloud using REST API. The aim is to generate leads in the Sales clou1d by making a callout in SFCC.

2. Below is the apex code to generate lead :

   @RESTResource(urlMapping='/LeadCreate/')
global class CreateLeadApi {
@HTTPPost
global static String creatingLeadRecord(){
String fName,lName, comp;
String fieldName, fieldValue;
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String jsonBody=req.requestBody.toString(); //this is the method to get the body
JSONParser parser=JSON.createParser(jsonBody); while(parser.nextToken()!=null){
        if(parser.getCurrentToken()!=JSONToken.END_OBJECT){
            fieldName=parser.getCurrentName();
            fieldValue=parser.getText();
          if(fieldName=='FirstName'){
                fName=fieldValue;  }
             else if(fieldName=='LastName'){
                lName=fieldValue;
            }
              else if(fieldName=='Company'){
                comp=fieldValue;
            }
        }
    }

    Lead l=New Lead(FirstName=fName,LastName=lName,Company=comp);
    insert l;
    return l.Id;
}}

3. Using Postman, the API is tested to check whether leads are getting generated. A token is generated in postman and used in SFCC for authentication while making service call.

About the author

Udayraj Patil
By Udayraj Patil

Category