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, but I am unsure how it should be constructed or if I am even looking in the right place.
@umagarimella 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:
"exportResponse": "{\"code\":\"handlebars_template_parse_error\",\"message\":\"Failed to generate soql.query from template: SELECT Id, Name from Account WHERE Id='{{data.someKey}}' LIMIT 1. Details: \\\"someKey\\\" not defined in the model. - 1:41.\"}"
As mentioned, this is regardless of whether I use {{someKey}} or {{data.someKey}} in the SOQL. How do I correctly reference the values from the "data" property in the SOQL?