Passing data from a My API script to an export's handlebars variables?
Hi,
If I pass data into a MyAPI script through the options.body or options.queryString attributes, how do I then pass this data on to the handlebars variables in the export that the MyAPI script is triggering?
For instance, if an export (with ExportID = "618a7**************70b9b") contains this simple Salesforce SOQL query:
SELECT Id, Name from Account WHERE Id='{{someKey}}'
and my handleRequest function for the MyAPI contains these lines:
import { exports } from 'integrator-api'
// An ID sent into the MyAPI from i.e. Postman
let idComingFromExternalApp = options.body.salesforceId;
let exportResponse = exports.run({_id:'618a7**************70b9b', [{"someKey":idComingFromExternalApp}]});
Is there any way of setting "someKey" in the script, so that is becomes available as "someKey" in the export's handlebars template, as sketched out above? Basically enabling me to call a MyAPI that returns data from an integrator.io export to an external application based on search data provided by the external application.
I see a mention of a listenerData property that can be passed into the exports.run() function (https://docs.celigo.com/hc/en-us/articles/360047339711), but I am unsure how it should be constructed or if I am even looking in the right place.
Thank you.
Kind regards,
Christoffer
Comments
Hey Christoffer Sinnbeck
You will want to use a different API call for achieving this.
exports.runVirtual accepts a parameter called `data` which is what you're looking for.
https://docs.celigo.com/hc/en-us/articles/360046916092-exports-runVirtual-options-
An example for your use case would be
The export is actually just the export document. You can view it by opening integrator.io/api/exports/<your export id>
PS: The listenerData param in exports.run refers to a listener(webook) export. We'll get the documentation updated to reflect this soon.
Uma Lakshmi Kanth Garimella Thanks a lot for your quick and thorough answer. I can get the export.runVirtual call to work if I construct my SOQL like this:
"query": "SELECT Id, Name from Account WHERE Id='" + options.body.sfdc_id + "' LIMIT 1"
But if I try to use string interpolation with the handlebars template:
"query": "SELECT Id, Name from Account WHERE Id='{{data.someKey}}' LIMIT 1"
or
"query": "SELECT Id, Name from Account WHERE Id='{{someKey}}' LIMIT 1"
and I have this as the "data" property of the runVirtual call:
data: [{"someKey":options.body.sfdc_id}]
I get this error returned in Postman:
Hey Christoffer Sinnbeck I've looked into this. It looks off to me as well.
The handlebar engine using this api is expecting another `data.` appended to the original expression.
It works when we change the expression to
I would suggest you use string concatenation for now as that would be stable and should work every time.
I'll get this logged and get it addressed by the appropriate team in an upcoming release.
Uma Lakshmi Kanth Garimella Yes, that works! Thanks a lot for your expertise.
But, as you suggest, I will use string concatenation or the "backtick" notation for now as both of these seem to work inside integrator.io.
Best regards
Please sign in to leave a comment.