You need to sign in to do that
Don't have an account?
Joseph Miramon 1
How to call an REST API via a button?
Hi guys, I need your help. I am not a developer and I don't know to edit the codes below. I placed these codes on a Detail Page Button with Content Source as OnClick Javascript. These codes were only handed to me, with the purpose of calling an external web API.
-------------------------
HttpRequest req = new HttpRequest();
Http http = new Http();
// set the request method
req.setMethod(‘POST');
String url = 'http://api.xxx.com/quickbooks/createinvoice’ + '?invoiceRefNumber=' + EncodingUtil.urlEncode([TheInvoiceReferenceNumber],'UTF-8’) + '&price=' + EncodingUtil.urlEncode([TheInvoicePrice],'UTF-8’) + '&date=' + EncodingUtil.urlEncode([TheInvoiceDate],'UTF-8');
// add the endpoint to the request
req.setEndpoint(url);
// create the response object
HTTPResponse resp = http.send(req);
----------------------
When the button is clicked, I get an error: Unexpected identifier 'req'
What should I do? Thanks guys.
-------------------------
HttpRequest req = new HttpRequest();
Http http = new Http();
// set the request method
req.setMethod(‘POST');
String url = 'http://api.xxx.com/quickbooks/createinvoice’ + '?invoiceRefNumber=' + EncodingUtil.urlEncode([TheInvoiceReferenceNumber],'UTF-8’) + '&price=' + EncodingUtil.urlEncode([TheInvoicePrice],'UTF-8’) + '&date=' + EncodingUtil.urlEncode([TheInvoiceDate],'UTF-8');
// add the endpoint to the request
req.setEndpoint(url);
// create the response object
HTTPResponse resp = http.send(req);
----------------------
When the button is clicked, I get an error: Unexpected identifier 'req'
What should I do? Thanks guys.
Controller:
Page:
NOTE: Copy & paste and review the parameters that you concatenate in the variable "String url" because I had to change these values
I hope I've helped, regards from Mexico :D