You need to sign in to do that
Don't have an account?

JSON token
Hi All,
I am trying to update the info on a Visualforce page from the REST API from the site. I was given a bearer token and I used Postman to get the access token. I am confused because there are no errors, but the code isn't working. How do I make this code work?
I am trying to update the info on a Visualforce page from the REST API from the site. I was given a bearer token and I used Postman to get the access token. I am confused because there are no errors, but the code isn't working. How do I make this code work?
public class AccountShippingController { public String trackingnumber {get;set;} public String shipmentStatus {get;set;} public String shipperAddr {get;set;} public String consigneeAddr {get;set;} public AccountShippingController(ApexPages.StandardController stdController){ Account account =(Account)stdController.getRecord(); account = [SELECT Id, XPO_Tracking__c FROM Account WHERE Id =:account.Id]; String accountTracking = account.XPO_Tracking__c; String apiKey = 'XXXXXXXX'; String requestEndpoint = 'https://api.ltl.xpo.com/tracking/1.0/shipments/shipment-status-details'; requestEndpoint += '?referenceNumbers[]=' + accountTracking; requestEndpoint += '&APPID=' + apiKey; Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(requestEndpoint); request.setMethod('GET'); HttpResponse response = http.send(request); if (response.getStatusCode() == 200) { Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody()); trackingnumber = String.valueOf(results.get('referenceNumbers')); Map<String, Object> shipmentStatusDtlsResults = (Map<String, Object>)(results.get('shipmentStatusDtls')); shipmentStatus = String.valueOf(shipmentStatusDtlsResults.get('shipmentStatus')); shipperAddr = String.valueOf(shipmentStatusDtlsResults.get('shipperAddr')); consigneeAddr = String.valueOf(shipmentStatusDtlsResults.get('consigneeAddr')); } else { ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'There was an error retrieving the information. Double check the Tracking Number, then contact a system administrator.'); ApexPages.addMessage(myMsg); } } }
<apex:page standardController="Account" extensions="AccountShippingController" showHeader="false" sidebar="false"> <apex:pageBlock title="Shipping Information"> <apex:pageBlockSection > <apex:pageMessages /> <apex:outputText label="Shipping Status" value="{!shipmentStatus}"/> <apex:outputText label="Shipper Information" value="{!shipperAddr}"/> <apex:outputText label="Consignee Information" value="{!consigneeAddr}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:page>
For every request you make to that API, you will have to pass that token in the header of the request.
Token is nothing but the sessionId which gets generated when you login in to your account of that website.
Every token has a certain has time limit before it expires. Once expired, you will have to either refresh your token using a refresh token URL, or you can simply do OAuth process login to get a new token.
I hope I'm able to explain myself.
Let me know if there is any doubt.
Thanks!
All Answers
I think you have to pass the access token in the header while making API requests.
Try using this code: Please make sure you are passing the right token in the request header.
That should do the trick.
Let me know if it helps
Thanks
For every request you make to that API, you will have to pass that token in the header of the request.
Token is nothing but the sessionId which gets generated when you login in to your account of that website.
Every token has a certain has time limit before it expires. Once expired, you will have to either refresh your token using a refresh token URL, or you can simply do OAuth process login to get a new token.
I hope I'm able to explain myself.
Let me know if there is any doubt.
Thanks!