Hi everyone,
I’m trying to build a Python script to send a POST request to a function post_myFunction inside my backend file http-functions.js
The request is successful, however it always returns an empty body. My python script is:
import requests
import json
url = “https://www.mitrip.live/_functions-dev/myFunction”
headers = {
“Content-Type”: “application/json”,
}
data = {
“tripId”: “123456”,
“destination”: “Paris”,
“startDate”: “2023-10-01”,
“endDate”: “2023-10-10”,
“duration”: 9,
“nbTravellers”: 2,
“vibe”: “Chill”,
“pace”: “Medium”,
“activities”:
}
payload = json.dumps(data)
response = requests.post(url, data=payload, headers=headers)
if response.status_code == 200:
print(response.json())
else:
print(“Error:”, response.status_code, response.text)
My function myFunction is defined as follows:
export async function post_myFunction(request) {
const record = request.body;
// Log the received data for debugging
console.log(“Received data:”, JSON.stringify(record));
// rest of my code
On my logs, I always get [“Received data:”,“{}”]
I’ve tried different variations to send the payload object (ex: removing json.dumps, replacing data=payload with json=payload) but I always get the same result. I have also tried to send this POST request using Postman, but I get the same issue.
If that can help, I have successfully managed to send a GET request with a Python script. The issue really seems to be with the POST.
Would you have any idea on how to correctly send my JSON object to Wix?
Many thanks in advance!
Amine