function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael MMichael M 

Help with callout

Hello, I have been stuck on a callout I'm trying to make. When I did it from POSTMAN it worked successfully (i received a 200 response code), however it is not going through from Salesforce. Can anybody tell me if I'm either missing any steps or doing Named Credentials wrong? Please keep in mind that for this callout, I do not need user name or password, rather the external system vallidates the system based on certain information from the body of the callout itself.) 

Here's my code, named credentials, and static resource:

Code:

    public final Lead referral;
    public String requestLabel;
    public String result {get;set;}
    public List<Object> seekData {get;set;}
    public string reqbody;
 StaticResource r =[Select Id,Body from StaticResource where Name='Seek_Callout_Body' limit 1];
      reqBody=r.body.toString();
       HttpRequest req = new HttpRequest();
         //  req.setHeader('Content-Length','0');
                req.setHeader('Content-Type','text/xml');
                req.setMethod('POST');
                req.setBody(reqBody);
                req.setEndpoint('callout:Seek');
                req.setCompressed(true);
    system.debug('FULL REQUEST: ' + req);

         Http http = new Http();
           HttpResponse response = http.send(req);
        // Parse the JSON response
        if (response.getStatusCode() != 201) {
            System.debug('The status code returned was not expected: ' +
                response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        }
User-added image

Static resource is .txt file of this:

User-added image

 
Best Answer chosen by Michael M
David Zhu 🔥David Zhu 🔥
can you get the debug message for response.getbody() for both named crendetaila and remote site?

All Answers

David Zhu 🔥David Zhu 🔥
What is the error code you get? Is it possible to get the details of HTPP request header and body the API server receives?
Michael MMichael M
A 500 error. But it is working from Postman, which I think tells me that the problem is from SF's end. 

When I system.debug(req.getbody()) Here is what I'm seeing:

User-added image

Does it look like it's cutting off the static resource in the middle? the debug logs look like the body is stopping at "</requestcode>

Here is what the actual body is looking like (in case the screenshot in my question didn't show clearly):
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <CheckEligibility
            xmlns="http://outdash.com/EligibilityIncyranceWebService">
            <returnCode>**</returnCode>
            <returnData></returnData>
            <requestCode>EO</requestCode>
            <vendorCode>CCA</vendorCode>
            <facilityProviderNpi>1982913109</facilityProviderNpi>
            <patientFirstName>Medicare</patientFirstName>
            <patientLastName></patientLastName>
            <patientDateOfBirth></patientDateOfBirth>
            <patientSex></patientSex>
            <payerCode>00431</payerCode>
            <policyNumber></policyNumber>
            <dateOfServiceForEligibilityChecking></dateOfServiceForEligibilityChecking>
        </CheckEligibility>
    </soap:Body>
</soap:Envelope>



 
David Zhu 🔥David Zhu 🔥
Error code 500 means the request hit the server and server encounted an unexpected condition to complete the request.
Can you use remote site to send the request instead of named credential? If you still get the same result, you may have to check with API service provider.
Michael MMichael M
Ok- so now I added the link as a remote site setting, and specified the URL in my endpoint. Now I am getting a 403 error (see debugs below.) What do you think I need to fix? 

User-added image

 
David Zhu 🔥David Zhu 🔥
can you get the debug message for response.getbody() for both named crendetaila and remote site?
This was selected as the best answer
Michael MMichael M
It is now solved- though I'm not totally sure what I did differently. Thank you!!