MyAPI imports

Comments

6 comments

  • Bhavik Shah Senior Product Manager
    Answer Pro
    Great Answer

    Chris Coppenbarger Thanks for posting to the community. It looks like invoking imports through MyAPIs should work as you explained. However it would be great to connect and go through the use case before providing any recommendations.  

    Meanwhile here's a help article which you could refer : https://docs.celigo.com/hc/en-us/articles/360047142012-Example-3-Configure-My-API-to-run-an-import-with-supplied-mapped-fields

    0
  • Chris Coppenbarger
    Engaged
    Celigo University Level 1: Skilled

    Bhavik Shah

    I did successfully get one import to run correctly. I'm not sure if I have the way of running the second import correctly, or not. I'm posting a screenshot of my integration, and sample code from my script. I need the customer id returned from the first import to run the second import.

    import { request, exports, imports, flows } from 'integrator-api'
    function handleRequest (options) {
      let method = options.method;
      let body = options.body;
      let queryString = options.queryString;
      // Get the input data that are passed in the records attribute in the request 
      let recordsToBeImported = body.records;
      
      let contactResponse;
      let regResponse;
      try {
      contactResponse = imports.run({ _id:'******', data:body });
      }catch(e) {
        contactResponse = JSON.stringify(e)
      }
      if(contactResponse.length > 0){
        try {
        regResponse = imports.run({ _id: '******', data:contactResponse })
        }
        catch(e) {
          regResponse = JSON.stringify(e)
        }
      }
      // Build response information
      let response = {};
      // Set the response status code
      response.statusCode = 200;
      response.body = {
        method: method,
        body: body,
        queryString: queryString,
        finalResponse: contactResponse
      }
      return response;
    }
    0
  • Scott Henderson CTO
    Celigo University Level 1: Skilled
    Answer Pro
    Top Contributor

    I recommend using 'console.log()' in your JavaScript code to inspect all the different objects, and then it should be easy to piece it all together. To view the logs, see pic below for context.

    At a very high level, if you need to mash up a bunch of different imports (i.e. API calls to different apps), and also get the results of all the API calls in the original HTTP request + response, then MyAPI is the way to go.  If you do not need the results of all the different imports in the original HTTP request + response, then I would recommend sending your API requests to a "Listener" bubble in a normal flow that can do all the work behind the scenes.

    Regarding your code, here is some high level guidance that might help too.

    1. contactResponse._json is a generic container variable that we use to return back all the information from the external API. This is where you should find the NetSuite id.
    2. For your second import, you can create the perfect 'data' payload that matches the import2+mappings.  i.e. you can take fields from 'body' and '_json' and then submit a brand new object.

    0
  • Chris Coppenbarger
    Engaged
    Celigo University Level 1: Skilled

    Hey Scott Henderson,

    Thanks for the reply. If figured how to "listen" to my AWS Lambda as a webhook. My current issue is getting the HMAC authentication working. I got it working in Postman using one example from one of the posts here, but having an issue in my Node.js code. It's not a Celigo issue, in this case, obviously, but any ideas?

    let hmac = crypto.createHmac("sha256", HMAC_SECRET).update(JSON.stringify(postData)).digest("base64");
    where postData is:
    {

      "records": [

        {

          "first_name": "Demo",

          "last_name": "MyAPI",

          "email": "tes1234@nospan.com",

          "street_address":"123 first street",

          "city": "columbus",

          "state_or_province": "ga",

          "zip_code": "31804",

          "country": "usa",

          "phone":"123-456-7890"

         }

      ]

    }

    I keep getting 401 unauthorized. Secret is same as I put in my Listener on Celigo.

    0
  • Chris Coppenbarger
    Engaged
    Celigo University Level 1: Skilled

    Well, nevermind. The test from the API Gateway was sending empty data, but from PostMan, it worked fine. Moving forward with the listeners and import.

    0
  • Bhavik Shah Senior Product Manager
    Answer Pro
    Great Answer

    Chris Coppenbarger - Thanks for providing the feedback. 

    We have published a new article on invoking multiple imports. 

    https://docs.celigo.com/hc/en-us/articles/9228081153435

    0

Please sign in to leave a comment.