Hi all,
I am trying to create multiple elements in one of my things of my Bubble database with a single bulk create API as described in Data API - Bubble Docs. However, I’m retrieving an error in my request response when trying this.
I’m using a Python script leveraging the requests library to bulk create multiple entities based on the input of a .csv file and .png images I have on my local machine.
The POC of my script looks like the following:
import requests
import json
import base64
url = "https://aiq-app.bubbleapps.io/version-test/api/1.1/obj/clubtest/bulk"
file_names = ["../data/Clubs/Logos/Beerschot.png", "../data/Clubs/Logos/KAA Gent.png"]
club_names = ['Beerschot', 'KAA Gent']
leagues = ["Belgian Jupiler Pro League", "Belgian Jupiler Pro League"]
with open('body.txt', 'w') as body:
for file_name, club_name, league in zip(file_names, club_names, leagues):
with open(file_name, "rb") as image:
encoded_file = base64.b64encode(image.read())
body.write(json.dumps({
"League": league,
"Logo": {
"filename": file_name,
"contents": encoded_file.decode('utf-8')
},
"Name": club_name
}))
body.write('\n')
with open('body.txt', "rb") as body_file:
encoded_body = base64.b64encode(body_file.read())
headers = {
'Authorization': 'Bearer PASSWORD',
'Content-Type': 'text/plain'
}
response = requests.request("POST", url, headers=headers, data=encoded_body)
print(response.text)
Which returns
{"status":"error","message":"Could not parse as JSON: VERY LONG STRING"}
The content of the body.txt
file looks like the following
{"League": "Belgian Jupiler Pro League", "Logo": {"filename": "../data/Clubs/Logos/Beerschot.png", "contents": "VERY LONG STRING"}, "Name": "Beerschot"}
{"League": "Belgian Jupiler Pro League", "Logo": {"filename": "../data/Clubs/Logos/KAA Gent.png", "contents": "VERY LONG STRING"}, "Name": "KAA Gent"}
Does anyone have an idea why I’m getting this error?
Thanks,
Dries