Python Forum
Using Python variable with SurveyMonkey API
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Python variable with SurveyMonkey API
#1
I am pulling down Survey Monkey Data via Python and inserting it into a SQL Server database via an SSIS task and am running into problems with pagination. I am new to both Python and the Survey Monkey Api but have got this working for 1 page. Where I am getting stuck is dealing with multiple pages. In short, I want to create a python variable with the maximum number of pages and use this in a loop to bring down all of the pages. Let me give you an example

When I query the data I have pulled into SQL with openjson, I get the following indicating there are 9 pages in this Survey

Key Value
data json string
per_page 50
page 1
total 406
links separate link for each page
I need to create a variable, likely math.ceil to round up total/50 (In this case, 406/50) to get the maximum number of pages (9). I then need to use this variable in my script below

SURVEY_LIST_ENDPOINT = "/v3/surveys?page=2"
cursor = conn.cursor()
cursor.execute("Insert Into JsonImport (json) values (?)", (json.dumps(response_json),))
conn.commit()
Format Json and insert into new SQL Table
Truncate JsonImport Table
This works when I hard code the number 2 for the page but I don't seem to be able to use a variable. Also, I am not sure how I would put this into a While loop (While page (variable <= totalpages) loop ). Any direction would be appreciated. I just want to get all of the pages from this Survey into the database without having to manually run this for each page in the Survey
Reply


Messages In This Thread
Using Python variable with SurveyMonkey API - by Djin - May-21-2020, 05:01 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020