Hi everyone,
I’m currently integrating OpenAI’s GPT-4o API into my Bubble app but I’m running into an issue with the JSON formatting when making API requests. I keep getting a HTTP 400 error saying:
“We could not parse the JSON body of your request. The OpenAI API expects a JSON payload, but what was sent was not valid JSON.”
**Current Setup in Bubble:
[
{
“role”: “system”,
“content”: “You are an AI assistant.”
},
{
“role”: “user”,
“content”: Reflexion_Input’s value
}
]
**
- I’m using the ChatGPT - Chat Completion plugin.
- The body message field currently looks like this:
json
KopierenBearbeiten
[
{
"role": "system",
"content": "You are an AI assistant."
},
{
"role": "user",
"content": Reflexion_Input's value
}
]
- Issue: The Reflexion_Input’s value is coming from a Bubble input field, but it seems that it is not properly formatted as JSON. I tried using
:formatted as JSON-safe
, but I can’t find this option in Bubble.
Questions:
- How do I correctly format the input field value as valid JSON?
- Is there a manual way to write the request body as a JSON string while inserting the input field dynamically?
- What’s the best practice in Bubble to ensure OpenAI receives a valid JSON request?
Would appreciate any help or guidance!