Bulk create new things via API not working

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

Hi @driesdeprest1,

I had the same issue too. I found a dirty way to insert with the bulk method some data from a pandas DataFrame.

It’s a dirty way because, I am manually fit with text/plain expectations of the API by removing the brackets from a json + adding the “\n” manually.

Is not for me a long term solution, but hope that this can help you.

BTW, I am also creating an open source package to interact with Bubble API using python. If you are interested in, don’t hesitate to contact me.

Kind regards,
Justin

Hi @driesdeprest1 have you tried to use something like https://webhook.site/ to see exactly what you’re sending? That has been helpful for me when it comes to diagnosing issues with this endpoint. I’d love to take a look at the raw data if you still need help here.

Conseguiram resolver o problema?

já fez isso amigo?