+ Start a Discussion
John AthitakisJohn Athitakis 

Simple REST Post Failing?

My first time using APEX for Rest (Or rest in general) and did a bit of reading and not sure what might be wrong. Error I'm getting from my logs is:

16:31:55.231 (231776791)|CALLOUT_RESPONSE|[17]|System.HttpResponse[Status=Not Found, StatusCode=404]
 

(nothing else of note)

Here is the @future class being involved by a simple trigger. We are using a bearer token for 'License-Client-Key', a test value in it currently that is setup to be accepted by the real endpoint (thus the 'boom'). Not sure if this is the issue? Thoughts or suggestions would be appreciated.
 

public class WebServiceCallout {

    @future (callout=true)
    public static void sendNotification(String name, Date expiration, string product, Decimal quantity, String type) {

        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        req.setEndpoint('https://endpointurl.com/destination);
        req.setMethod('POST');
        
        req.setHeader('License-Client-Key', 'boom');     
        req.setBody('Name='+EncodingUtil.urlEncode(name, 'UTF-8')+'&Expiration='+ expiration +'&Product='+EncodingUtil.urlEncode(product, 'UTF-8')+'&Quantity='+ quantity+'&Type='+EncodingUtil.urlEncode(type, 'UTF-8'));
       // req.setCompressed(true); // otherwise we hit a limit of 32000

        try {
            res = http.send(req);
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        }

    }

   //  run WebServiceCallout.testMe(); from Execute Anonymous to test
    public static void testMe() {
      WebServiceCallout.sendNotification('My Test Customer',date.newInstance(2015, 7, 15),'01tG0000003Hvt2',1,'Subscription');
    }

}
pconpcon
I plugged this exact same code into my devorg but pointed it at http://headers.jsontest.com/ and it works without issue.  This sounds to me like you have the wrong URL, or it is a resource that is not available from Salesforce (such as a host behind a firewall/VPN)