You need to sign in to do that
Don't have an account?
khaviya G Senthilkumar
{"message":"Missing Authentication Token"}
Hello,
I am trying to do a POST request. But I keep getting this message in my endpoint. My code shows no error and the JSON is getting printed in the debug window. but I don't know what am doing wrong.
Please help me with this.
public with sharing class SageAPIController extends TriggerHandler {
@future (callout=true)
public static void getCustomerId(String acc)
{
HttpRequest req = new HttpRequest();
req.setEndpoint(' xxxxxxx ');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json;charset=UTF-8');
req.setBody(acc);
Http h = new Http();
HttpResponse response = h.send(req);
String str = response.getBody();
if (response.getStatusCode() != 200)
{
System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus());
}
else
{
System.debug(response.getBody());
}
}
public override void beforeInsert() {
for(Account Acc_record : (List<Account>) Trigger.new) {
String jsonString = '{"name": "'+Acc_record.Name+'", "display_contact": { "print_as": "'+Acc_record.Name+'","company_name": "'+Acc_record.Name+'", "email1": "'+Acc_record.McLabs2__Email__c+'" ,"fax": "'+Acc_record.Fax+'","first_name": "'+Acc_record.Owner_Name__c+'","phone1": "'+Acc_record.Phone+'","mailaddress": { "address1": "'+Acc_record.BillingStreet+'", "city": "'+Acc_record.BillingCity+'", "state": "'+Acc_record.BillingState+'" }"} }';
System.debug('jsonString'+jsonString);
getCustomerId(jsonString);
}
}
}
I am trying to do a POST request. But I keep getting this message in my endpoint. My code shows no error and the JSON is getting printed in the debug window. but I don't know what am doing wrong.
Please help me with this.
public with sharing class SageAPIController extends TriggerHandler {
@future (callout=true)
public static void getCustomerId(String acc)
{
HttpRequest req = new HttpRequest();
req.setEndpoint(' xxxxxxx ');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json;charset=UTF-8');
req.setBody(acc);
Http h = new Http();
HttpResponse response = h.send(req);
String str = response.getBody();
if (response.getStatusCode() != 200)
{
System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus());
}
else
{
System.debug(response.getBody());
}
}
public override void beforeInsert() {
for(Account Acc_record : (List<Account>) Trigger.new) {
String jsonString = '{"name": "'+Acc_record.Name+'", "display_contact": { "print_as": "'+Acc_record.Name+'","company_name": "'+Acc_record.Name+'", "email1": "'+Acc_record.McLabs2__Email__c+'" ,"fax": "'+Acc_record.Fax+'","first_name": "'+Acc_record.Owner_Name__c+'","phone1": "'+Acc_record.Phone+'","mailaddress": { "address1": "'+Acc_record.BillingStreet+'", "city": "'+Acc_record.BillingCity+'", "state": "'+Acc_record.BillingState+'" }"} }';
System.debug('jsonString'+jsonString);
getCustomerId(jsonString);
}
}
}