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
Kathryn BullockKathryn Bullock 

Do I need the O Auth?

Hi All,

I am trying to bring shipping information from XPO Logistics into Salesforce.  I was given a bearer token and I have to go through Postman to refresh the token every 12 hours.  Will I need to do an OAuth?  If so, will the callback URL be the Postman, the XPO Logistics or Salesforce?  I am very confused about what the callback URL does, and how I would get the callback URL if I need to get one on Postman.  Please help!
v varaprasadv varaprasad
Hi Kathryn,

Please check once below smple code.

If you want to connect other system then they will provide us 
 1. Client id 
2. Client secret
3. Oauth toke url
Using above id nd secret we can generate the access token.
 
String tokenBody = 'grant_type=client_credentials&client_id=ssssssssssssss6&client_secret=Ssssssssssssss';
        
        
        Http http = new Http();
        HttpRequest tokenReq = new HttpRequest();
        tokenReq.setEndpoint('https:/Oauth token URL/oauth/token');        
        tokenReq.setMethod('POST');
        tokenReq.setBody(tokenBody);
        tokenReq.setTimeout(12000);
        tokenReq.setHeader('Content-Type','application/x-www-form-urlencoded');
       
        
        system.debug('### value of tokenReq:::::::'+tokenReq);
        HTTPResponse resp = http.send(tokenReq);
        system.debug('==resp.getStatusCode()=='+resp.getStatusCode());
        if(resp.getStatusCode() == 200 || resp.getStatusCode() == 201){
            system.debug('Token Response >>>>'+resp.getBody());
           //in the body we will get accesstoken
}

Once you get access token using that we can get the details from XPO.
4. Here XPO  again other URL will provide you to get the details
Endpoint url = 'xpo   ppppppppp  '
;req = new HttpRequest();
            req.setMethod('GET');
            req.setBody(jsonBody);
            req.setTimeout(120000);
            req.setHeader('Authorization', 'Bearer '+aToken);
            req.setHeader('Content-Type', 'application/json');
            
            req.setEndpoint(endpoint);
            
            Http htp = new Http();
            
            res = new HttpResponse();
            try{
                res = htp.send(req);
                
                //Helpful debug messages
                System.debug(res.toString());
                System.debug('STATUS:' + res.getStatus());
                System.debug('STATUS_CODE:' + res.getStatusCode());
                String responseXML = res.getBody();
                System.debug('Response:' + responseXML);
            }catch(System.CalloutException e){
               
                system.debug('callout error mesage'+e.getMessage());
                system.debug('callout error mesage'+e.getTypeName());
                system.debug('callout error mesage'+e.getLineNumber());
                system.debug('callout error mesage'+e.getCause());
            }

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com


 
Kathryn BullockKathryn Bullock
Thank you for the fast answer!  Unfortunately, I was not given the client ID or the secret, only the bearer token.  Also, does that make the callback ID Postman?  Really thank you for your help!!!