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
sami amisami ami 

Making HTTPS POST from salesforce and GET.

Hi...

 

I am having an REST URI of my client and i need to make some call outs to that from salesforce and POST some data...How can i do that?Its an integration between two orgs(salesforce and another third party tool)

 

Thanks,

Ramesh

Pat PattersonPat Patterson

Calling out from Salesforce to a third party RESTful web service is pretty straightforward - this article covers most of the basics: Apex Web Services and Callouts

 

You'll need to configure a Remote Site, then look at the HTTP Code Sample - that shows how to do a PUT against Amazon S3, but you can easily adapt it to a POST against another service.

 

Cheers,


Pat

sami amisami ami
Thank you sir.
But i heard we can do HTTP requests in two ways.
1.Using header(as said in your example of PUT)
2.Using API token/rest URI
I am trying to make POSTs using Token.
So my URI is http://my.target?key=7456423der3445445345543553552egsg3.
Also i have my logic/condition when the POST should happen and what fields should be posted to target and all...where should i include all that ??in the same HTTP class??
Pat PattersonPat Patterson

You can set up a form post like this - parameters are usually URL encoded in the body of the post:

 

HttpRequest req = new HttpRequest();
req.setEndpoint('https://someserver.com/somepath');
req.setMethod('POST');
req.setHeader('Some-HTTP-Header', 'some-value'); req.setBody('param1='+EncodingUtil.urlEncode(value1, 'UTF-8')+ '&param2='+EncodingUtil.urlEncode(value2, 'UTF-8')); Http http = new Http(); HttpResponse res; try { res = http.send(req); } catch(System.CalloutException e) { System.debug('Callout error: '+ e); System.debug(res.toString()); } System.debug('Response body: ' + res.getBody());

 

sami amisami ami
Thanks sir...
Yes i have done something like this.I hardcoded xml format as body .

Snippet is like following,

HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();

string test = ' <some xml format data>';
req.setEndpoint('http://www.my-end-point.');
req.setMethod('POST');
req.setBody(test;)
try {
res = http.send(req);
} catch(System.CalloutException e) {
System.debug('Callout error: '+ e);
System.debug(res.getBody());
}

How can i get it dynamically????my xml data from salesforce.Thanks for your help sir.