I am trying to get my request header details by inserting it as a "log__c" (which is nothing but another form of System.debug)record as seen below
@RestResource(urlMapping='/Project/*')
global class ProjectCalloutService {
@future(callout=true)
public static void doCallout(Id oid)
{
Opportunity o = [SELECT ID,Name,Account.Name,CloseDate,Amount FROM Opportunity WHERE Id = :oid];
ServiceTokens__c s = ServiceTokens__c.getValues('ProjectServiceToken');
String jsonInput = '{\n' +
' "opportunityId" : "'+o.Id+'",\n'+
' "opportunityName" : "'+o.Name+'",\n'+
' "accountName" : "'+o.Account.Name+'",\n'+
' "closeDate" : "'+String.ValueOf(o.CloseDate).mid(0,10)+'",\n'+
' "amount" : '+o.Amount+'\n'+
'}';
HTTPRequest req = new HTTPRequest();
req.setEndPoint('callout:ProjectService');
req.setMethod('POST');
req.setHeader('Authorization', 'Bearer ' + s.Token__c);
req.setHeader('Content-Type', 'application/json');
//req.setHeader('Authorization',s.Token__c);
req.setBody(jsonInput);
HTTP h = new HTTP();
HTTPResponse res = h.send(req);
//System.debug(res);
Log__c l = new Log__c(LogText__c = String.ValueOf(res));
insert l;
Log__c l1 = new Log__c(LogText__c = jsoninput);
insert l1;
Log__c l2 = new Log__c(LogText__c = String.ValueOf(req));
insert l2;
}
@InvocableMethod
public static void postOpportunityToPMS(List<Id> oids){
doCallout(oids[0]);
}
}
As seen from the above code, I am setting the authorization in the header via req.setHeader('Authorization', 'Bearer ' + s.Token__c);
There is value (s.Token__c
) in that custom setting record.
But for some reason when I check the "log__c" record I get the following
System.HttpRequest[Endpoint=callout:ProjectService, Method=POST]
As can be seen there is no authorization (token missing from the request) seen in the request even though I package it in my request.
Can someone tell me what I am missing ?