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

0

Comments

4 comments
Date Votes
  • 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

    exports.runVirtual({
    export: {
    "_connectionId": "<your sf conn id>",
    "adaptorType": "SalesforceExport",
    "asynchronous": true,
    "name": "NS SF",
    "oneToMany": false,
    "salesforce": {
    "api": "rest",
    "distributed": {
    "referencedFields": [],
    "relatedLists": [],
    "userDefinedReferencedFields": []
    },
    "soql": {
    "query": "SELECT Id, Name from Account WHERE Id='{{someKey}}'"
    },
    "type": "soql"
    },
    "sandbox": false
    },
    data: [{"someKey":idComingFromExternalApp}]
    })

    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.

    1
  • 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:

    "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?
     
    Thanks in advance.
     
    0
  • 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 

    SELECT Id, Name from Account WHERE Id='{{data.data.0.someKey}}' LIMIT 1

    "data": [{
    "someKey": 123
    }]

    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.

    1
  • 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

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post