Passing data from a My API script to an export's handlebars variables?

Comments

4 comments

  • Uma Lakshmi Kanth Garimella Lead Engineer
    Celigo University Level 2: Seasoned

    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
  • Christoffer Sinnbeck
    Engaged

    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
  • Uma Lakshmi Kanth Garimella Lead Engineer
    Celigo University Level 2: Seasoned

    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
  • Christoffer Sinnbeck
    Engaged

    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.