The lazy dev’s guide to API automation: Airtable to SurveyMonkey uploader

The first Postman conference is coming up soon, and there’s so much to do! We’re hosting a pre-conference workshop where Postman users can level up ? their Postman game and take a quiz to get certified as a Postman expert. 

The Postman team came up with quiz questions on a shared spreadsheet, and we whittled and wordsmithed our way to a final list of questions. We planned to use SurveyMonkey to administer the quiz, so I created a survey, entered the first question, entered all the answers, configured the display options, and then selected the right answers. 

It’s widely known that developers are a lazy group. I did not want to spend more time painstakingly entering in each question by hand. There had to be an easier way to do this!

Pulling records with the Airtable API

I’d worked with the spreadsheet app Airtable before, and knew it had an easy API to access my data. I copied and pasted the quiz data into an Airtable base and added some formulas to format the data the way I wanted.

I can’t give away the answers to the Postman quiz! So here’s another example base:

For the authorization, add your Airtable API key as an environment variable called airtable_api_key under the environment editor. To generate or manage your API key, visit your Airtable account page.

The first request in my Postman collection is to GET all airtable records from this base. Make sure to update your airtable_base in the environment editor the way you did with your API key. Let’s store this information by parsing the response and setting an environment variable called airtable_records under the Tests tab.

Uploading questions with the SurveyMonkey API

I turned to the SurveyMonkey API documentation, and was pleased to see the familiar Run in Postman button. I imported the collection of all of their endpoints into the Postman app, and could immediately see how their endpoints were organized and how every request would work. So easy!

The second request in my Postman Collection would be to POST every question to my existing survey. For the authorization, create a new SurveyMonkey app. Under their Settings tab, select the scopes and permissions that your app will have.

On this same page, copy the access token and add this information as an environment variable called surveymonkey_token under the environments editor. In this same manner, you will also need to update the SURVEY_ID and PAGE_ID environment variables, which you can now GET using the other SurveyMonkey API endpoints.

Under the Pre-request Script tab, let’s access the airtable records and format the question data in the way that the SurveyMonkey API requires, to be sent in the request body.

Scripting in Postman

A lot of people know Postman Collections as a way to document and share their APIs, like how SurveyMonkey shared their collection with me using the Run in Postman button, so that I could get started faster.

The collection I was building in the Postman app was a different kind of collection. This operational collection works like a script or utility, and will continue to iterate over every airtable record and create a new question until there are no more questions left.

  • Controlling your workflow: we can use `postman.setNextRequest()` to continue sending the same request until no more questions remain.
  • Saving state: we can use an environment variable like `airtable_records` to save the current state of the array containing all the questions that remain to be uploaded.

Try it yourself

Click the orange Run in Postman button to check out the Airtable to SurveyMonkey Uploader collection.

Need help getting started? Check out the Airtable to SurveyMonkey uploader collection documentation for step-by-step instructions and helpful screenshots.

Tags:

What do you think about this topic? Tell us in a comment below.

Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.