I am working callout to post my JSON. When I test my JSON at PostMan it's all correct but when same JSON with my api, I got ' System.HttpResponse[Status: Forbidden , StatusCode=403 ]' ( 403 Confirmed... ). I'am stuk in this for a long time. Any efrot will be highly appreciated. Here is my POST process.

  public with sharing class LeadPost {

@future (callout=true)
public static void callout( string json_leadID){

    // Test Email address
    string email = 'umer121@gmail.com';

    string parsedID;
    string leadName;
    String leadEmail;
    String leadPhone;

 // Address Array 'addressList' 
    string addressApartment, addressArea, addressBlock, addressBuildingName, addressCity, addressCountry, addressLat, addressLng, addressPostCode, addressState, addressStreet, addressText;

// Vendor Bank Details object fields 'vendorBankDetails'
    string accountName, accountNumber, bic, iban, sortCode, vat;

// Vendor busness info object 'vendorBusiness'
    string cod, companyName, contractEnd, contractOngoing, contractStart, deliveryCharges, industry, invoiceEmail, noOfEmp, paymentTerminal, trialDays;

// Vendor fares info object 'vendorFares'
    string baseFare, dropOff, perKMCharges, pickUp, radius;

// Vendor personal info Object 'vendorPersonal'
    string enabled, firstName, language, lastName, middleName, password, phoneNumber, username;

// END var JSON strings

    // creat JSON
    // creat JSON

        system.debug('LeadPOST JSON: '+json_leadID); // pass // String jsonString

        string leadID = json_leadID;
        system.debug('lad: '+leadID);
        String jsonID = JSON.serialize(leadID);

        JSONParser parser = JSON.createParser(json_leadID);
        while(parser.nextToken()!= null) {
        if(parser.getCurrentToken() == JSONToken.FIELD_NAME) {
            if(parser.getCurrentName() == 'Id') {
                parsedID = parser.getText();
            else if(parser.getCurrentName() == 'Name'){
                leadName = parser.getText();
            else if(parser.getCurrentName() == 'Phone'){
                leadPhone = parser.getText();
            else if(parser.getCurrentName() == 'email'){
                leadEmail = parser.getText();

        //system.debug('This is LEAD ID test: ' +parsedID +' , Lead Name: '+leadName+ ' , Lead Phone Number: ' +leadPhone+' , Lead Email: '+leadEmail);

        string jsonPost='{ "addressList": [ { "addressApartment": "'+addressApartment+'", "addressArea": "'+addressArea+'", "addressBlock": "'+addressBlock+'", "addressBuildingName": "'+addressBuildingName+'", "addressCity": "'+addressCity+'", "addressCountry": "'+addressCountry+'", "addressLat": "'+addressLat+'", "addressLng": "'+addressLng+'", "addressPostCode": "'+addressPostCode+'", "addressState": "'+addressState+'", "addressStreet": "'+addressStreet+'", "addressText": "'+addressText+'" },\n'+
                                        '{ "addressApartment": "'+addressApartment+'", "addressArea": "'+addressArea+'", "addressBlock": "'+addressBlock+'", "addressBuildingName": "'+addressBuildingName+'", "addressCity": "'+addressCity+'", "addressCountry": "'+addressCountry+'", "addressLat": "'+addressLat+'", "addressLng": "'+addressLng+'", "addressPostCode": "'+addressPostCode+'", "addressState": "'+addressState+'", "addressStreet": "'+addressStreet+'", "addressText": "'+addressText+'" } ],\n'+
                                        ' "vendorBankDetails": { "accountName": "'+accountName+'", "accountNumber": "'+accountNumber+'", "bic": "'+bic+'", "iban": "'+iban+'", "sortCode": "'+sortCode+'", "vat": "'+vat+'" },\n'+
                                        ' "vendorBusiness": { "cod": "'+cod+'", "companyName": "'+companyName+'", "contractEnd": "'+contractEnd+'", "contractOngoing": "'+contractOngoing+'", "contractStart": "'+contractStart+'", "deliveryCharges": "'+deliveryCharges+'", "industry": "'+industry+'", "invoiceEmail": "'+invoiceEmail+'", "noOfEmp": "'+noOfEmp+'", "paymentTerminal": "'+paymentTerminal+'", "trialDays": "'+trialDays+'" },\n'+
                                        ' "vendorFares": { "baseFare": "6", "dropOff": "3", "pickUp": "3", "radius": "2", "perKMCharges":"2" },\n'+
                                        ' "vendorPersonal": { "enabled": "1", "firstName": "firstName", "language": "language", "lastName": "lastName", "middleName": "middleName", "phoneNumber": "phoneNumber", "username": "'+email+'" } }';

    // Callout

    // /*
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');

        system.debug(' POST JSON: '+ jsonPost);
        HttpResponse response = http.send(request);
        system.debug('Helper class--Lead Resposne: ' + response);

        if(response.getStatusCode() == 403){
            system.debug('403 Confirmed...');
        else if (response.getStatusCode() != 201) {
            System.debug('The status code returned was not expected: ' +
                response.getStatusCode() + ' ' + response.getStatus());
        else {
            System.debug('response.getBody() :  '+response.getBody());

    // */
    // END Eallout


  • Does your user in the SF account have the 'API Enabled' permission? I mean the one whose sessionId you use for Authorization header? matchmyemail.com/wiki/errors-and-alerts/… – Mariia Illarionova Mar 25 at 7:46
  • Yes, I did cross checking and it's enabled. I am doing this in trailhead playground org. Is that allowed in trailhead org ? – Umer Farooq Mar 25 at 8:07
  • A Trailhead Playground is actually a Developer Edition (DE) that has been customized with Trailhead-specific bells and whistles. developer.salesforce.com/forums/?id=9060G000000I1TXQA0 – Mariia Illarionova Mar 25 at 8:13
  • So, whats the issue if DE is allowing this ? – Umer Farooq Mar 25 at 8:16
  • Can you please add here th endpoint you use in POST method, so I can check it? Erase the org domain from it if you want, I just need everything that goes after .com/ – Mariia Illarionova Mar 25 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.