0

I am making a callout and getting the error

"System.CalloutException: The callout couldn't access the endpoint. You might not have the required permissions, or the named credential "XXX" might not exist."

When I inspect the log, it appears that the Named callout has all values as null. I don't understand why since we already set up the named credential in Salesforce.

I am attaching both the named credential and the error log.

  HttpRequest reqData = new HttpRequest();
    Http http = new Http();
    
    String subscriptionApi = 'callout:xxx/https://xxx.com/api/v2/customers/' + custId + '/subscription_for_items' + params;
    System.debug('Complete request ' + subscriptionApi);
    String method = 'POST';
    reqData.setHeader('Authorization', 'Username xxxxx');
    reqData.setHeader('Content-Type', 'application/x-www-form-urlencoded');
    reqData.setHeader('Connection','keep-alive');
    reqData.setTimeout(25000);
    reqData.setEndpoint(subscriptionApi);        
    reqData.setMethod(method);

    
    HTTPResponse response = http.send(reqData);
    System.debug('response ' + response);
    return response;

Any ideas? Thanks

EDIT: After incorporating Keith's suggestion the values are now not null. I am now getting this enter image description here

6
  • 1
    One thing is that your callout:xxx/ should replace the https://xxx.com/ as the named credential identifies the endpoint server. May not be the only problem though...
    – Keith C
    Commented Apr 27, 2023 at 8:24
  • Thanks Keith. That worked since the values are not null anymore. I am now getting bad request error Status 400. Thoughts?
    – Pauline
    Commented Apr 27, 2023 at 9:12
  • PS You don't need to set the 'Authorization' header when using Named Credentials.
    – Keith C
    Commented Apr 27, 2023 at 10:21
  • An the 400 error, make sure to output all info in the response including the body e.g. JSON.serializePretty(response). And if you have any access to the service you are calling, look for errors at that side too.
    – Keith C
    Commented Apr 27, 2023 at 10:23
  • 1
    Thanks Keith. I removed the basic but the error didnt go away. But it turns out that one of the parameters which was using epoch date needed to be divided by 1000. It has finally worked!
    – Pauline
    Commented Apr 27, 2023 at 11:00

0

You must log in to answer this question.