+ Start a Discussion

How to call REST method from within Custom Button using onClick JavaScript

I am a newbie to SalesForce and trying to call a REST service in a custom button's onclick JavaScript.

I get error, Error 400 Endpoint protocol(http/https) mismatch: 

My endpoint is http://blah.blah.. and I can hit it separately in browser, so the RESt service getPrimaryQuoteDetails is working fine.

My onclick JavaScript code is as below. Can anybody throw light onto why this is not working? The site is listed as 'Remote Site' and I can also make a call to this service from a VF page. But the problem is the requirement is not to use VF page. This button is part of a custom object which is added to a standard opportunity layout.

Any answers or suggestions from gurus?





url : 'http://c-----.com/----------/getPrimaryQuoteDetails.htm?quoteId=364926',
async : true,
cache : false,
method: "GET",
onSuccess : function(response) { alert('OK: '+response); },
onFailure : function(response) { alert('ERROR: '+response); }






I'd like to do the exact same thing . Any directions on how to do this will be appretiated.

Wan Kit FongWan Kit Fong
Hi Mk2013,

I've tried your code, and it is working. From your error code, you can try to change your URL from http to https