Recently I created a SurveyMonkey API program that lets me create and upload surveys much faster for my purposes than using the website. My problem is that I switched up my program to make it more versatile and have run into a problem.
The part I am stuck on is when I use the program to insert image URLs into the JSON formatted upload payload.
I first create the payload, called page, and iterate through the image URLs list to upload, adding the URL to the specific section in the page along the way.
The problem that I am having is when I set a field within an entry of the page list, it changes that field for all of the page list entries.
For Example
page = final payload to upload to surveymonkey
page_template = list of JSON format questions for one page
num_pics = len(img_url_list)
for i in range(num_pics):
# Try except for if page does not have questions
try:
for question_index in range(len(page_template)):
if "presentation" in page_template[question_index]["family"]:
page_template[question_index]["headings"][0]
["image"]["url"] = img_url_list[i]
except:
print("Problem when inserting images...")
page[i] = {
"title": " ",
"description": " ",
"questions": page_template
for one_page in page[:i+1]:
for one_question in one_page["questions"]:
if "presentation" in one_question["family"]:
print(one_question["headings"][0]["image"]["url"])
This outputs something like...
img1url.jpg
img2url.jpg
img2url.jpg
img3url.jpg
img3url.jpg
img3url.jpg
I simplified the code or else it would take forever to explain this program to a further extent.
I cannot for the life of me figure out why the fields within the list entries are being changed for all entries instead of only the one I indexed to. I have tried changing around my code to use temporary variables and/or outside functions but nothing has worked.
Any thoughts?
EDIT
I am looking to have the output look like...
image1url.jpg
image1url.jpg
image2url.jpg
image1url.jpg
image2url.jpg
image3url.jpg
This would show that the same image URL is not being copied to all of the body page templates.