Hi All,
I have created Hosted Target, as my requirement is to send parallel call-out from APIGEE to multiple objects (Accounts, Contacts etc.,) in Salesforce. I am trying to do this using nodejs.
- I installed nodejs locally and imported request module as zip. Please refer the attached screenshotcapture.png (I have added this as I am getting error as "ReferenceError: Request is not defined" error).
- Also is the above approach using Hosted Target best way for the parallel call-out?
Any help here would be helpful as I am new to APIGEE. Looping @ylesyuk @Dino-at-Google
Solved! Go to Solution.
my requirement is to send parallel call-out from APIGEE to multiple objects (Accounts, Contacts etc.,) in Salesforce. I am trying to do this using nodejs.
You can send multiple parallel requests out using a JS callout.
You can also use a Hosted Target, using nodejs. Either will work.
For sending requests with a JS Callout, use the callback mechanism.
function onComplete(response, error) { if (response) { context.setVariable('example.status', response.status); } else { context.setVariable('example.error', 'Whoops: ' + error); } } var req1 = new Request(); //req1.body = ''; req1.url = 'https://sf.com/something/oneid/' + id ; req1.method = 'GET'; //req1.headers = { 'ID-Index' : ix }; httpClient.send(req1, onComplete); var req2 = new Request(); //req2.body = ''; req2.url = 'https://sf.com/something/oneid/' + id ; req2.method = 'GET'; //req2.headers = { 'ID-Index' : ix }; httpClient.send(req2, onComplete);
For a Hosted Target, your nodejs code is wrong. You seem to be mixing code that would work in the Javascript callout, with code that would work with the nodejs request module. That's not going to work. The Request object available in the JS callout is not the same as the request module available in nodejs. You cannot mix and match code.
You need to start from the beginning with a nodejs sample, outside of any Apigee context. Get that working first. Follow a tutorial.
Also, as regards the request module, please consider this. The request module is now in maintenance mode. If you want to write modern Javascript, using promises and async/await, you should consider alternatives to the request module.