1 Reply Latest reply on Sep 11, 2018 5:41 PM by Sanford Whiteman

    Chai? Conditionally Updating Forms w/ REST API Calls

    Sierra Warren

      Background: Due to our complicated business model and expansiveness of our instance, we need to update 100+ Marketo forms approximately every quarter. Previously this was done manually, but we are looking to automate the process with REST API calls. The updates consist of (1) updating picklist values for a particular field and (2) approving the form.

       

      I have developed and tested several API calls to meet these needs in Postman and we are ready to run the bulk update. I was able to update several forms in bulk and "link" the calls by uploading an Excel file with form IDs to Postman's Runner, however, there are too many forms in our instance to gather all of the IDs and assemble them into a file. The matter is further complicated by having forms in multiple languages and because not all forms contain the field that needs updating.

       

      To update the forms that need to be updated based on this criteria (steps 1 and 2 above), I have come up with this conceptual framework:

      1. If language is English AND form contains "Start Date" field... GET form IDs. 

      {{URL}}/rest/asset/v1/forms.json?access_token={{access_token}}

      2. POST update picklist values.

      {{URL}}/rest/asset/v1/form/{{formid}}/field/startDate.json?values=[ {"label":"Select Start Date","value":"","isDefault":true,"selected":true}, {"label":"2019 Spring","value":"2019 Spring"}, {"label":"2019 Summer","value":"2019 Summer"}, {"label":"2019 Fall","value":"2019 Fall"}, {"label":"2020 Spring","value":"2020 Spring"}, {"label":"2020 Summer","value":"2020 Summer"}, {"label":"2020 Fall","value":"2020 Fall"} ]&access_token={{access_token}}

           If success is true...

      3. POST approve the form.

      {{URL}}/rest/asset/v1/form/{{formid}}/approveDraft.json?access_token={{access_token}}

       

      The conditions are essential to ensure we don’t accidentally translate forms in other languages or add fields that shouldn’t be there. To call only the form IDs that meet the language and field criteria, my understanding is that we can use Chai scripting in the pre-request script. Does anyone have experience with Chai for this application? Or is there another solution we should be considering that has proven successful for others?

       

      Thank you,

      Sierra Warren

       

        • Re: Chai? Conditionally Updating Forms w/ REST API Calls
          Sanford Whiteman

          Does anyone have experience with Chai for this application? Or is there another solution we should be considering that has proven successful for others?

          Chai is a testing framework for Postman (and for NodeJS). It's hardly the best/correct tool for automating a set of arbitrary HTTP calls.

           

          Or is there another solution we should be considering that has proven successful for others?

          Yes, actually write code and run it under NodeJS.

           

          Or heck, a series of cURL (command-line exe) calls interspersed with calls to jq, managed w/a shell/batch file, is more suited IMO.