...
The callout API is available for making HTTP(S) requests from the Pulsar platform and returning results to the HTML and javascript. Since custom HTML/javascript code is hosted as a local file within Pulsar, there can be issues using the normal XMLHttpRequest (XHR) or fetch methods to issue Cross-Origin requests to external services. This Pulsar API helps sidestep those problems.
Code Block |
---|
var request = {
type: 'callout',
object: '',
data: {
resource: 'https://my.org.instance.salesforce.com/api/resources',
options: {
method: 'POST', // or GET, PUT, DELETE, etc...
headers: { // header name-value pairs, as shown below
Authorization: 'Bearer AABBEEAARREERRTTOOKKEENN....',
Content-Type: 'application/json',
},
body: 'my post content body!',
}
}
};
pulsarBridge.sendRequest(request, function (result) {
if (result.type === 'calloutResponse') {
var response = result.data;
console.log('Response Status Code: '+response.status); // string
console.log('Response Data:'+response.body); // string
}
else {
console.log('failed: '+ result.data)
}
}); |