import os import requests import json
project_id = os.getenv("PROJECT_ID") funtion_id = "" appwrite_endpoint = "https://cloud.appwrite.io/v1"
url = f"{appwrite_endpoint}/functions/{function_id}/executions"
headers = {
"X-Appwrite-Project": project_id,
"Content-Type": "application/json"
}
# Payload to send
payload = {
"key": "value"
}
# Stringify the JSON payload before sending
payload_string = json.dumps(payload)
# Make a request to trigger the function with the stringified payload
response = requests.post(url, headers=headers, data=payload_string) # Use 'data' instead of 'json'
# Check the response status and parse it
if response.status_code == 200:
print("Response JSON:", response.json())
else:
print(f"Error: {response.status_code}, Response: {response.text}")```
I think its something stupid like how im formatting the outbound payload as ive debugged everything else. Or maybe there's something appwrite specific like you need to allow it to receive values
All values and endpoints are working, function is triggering and printing and sending a generic response without issues
def main(context, res=None): try: # Directly get the raw request body text text = context.req.body_text context.log(f"Request Body: {text}")
# Log other request parameters if needed
context.log(f"Request Headers: {context.req.headers}")
context.log(f"Request Method: {context.req.method}")
except Exception as e:
context.log(f"Error 1: {str(e)}")
try:
return {"statusCode": 200, "body": "Success"}
except Exception as e:
try:
context.error(str(e)) # Log the error
return {"statusCode": 500, "body": "Internal Server Error"}
except:
return {"statusCode": 500, "body": "Unknown Error"}
Just curious is there any reason you're not using the sdk and calling the rest endpoints?
The payload for that endpoint is this object
{
"body": "<BODY>",
"async": false,
"path": "<PATH>",
"method": "GET",
"headers": {},
"scheduledAt":
}
Which could be why you're having issues.
I was having errors initially, using requests always helps me understand whats happening a bit better. I can try again but I merely have two questions.
Does data receiving have to be enabled
and how is the structure of the message supposed to look. Is a stringified
"key": "value"
}
good enough?
The executions endpoint doesn't directly call your function but put that call in a queue. You can altneratively call the function directly using it's generated URL as it's own endpoint.
well thats a good tip, probably faster that way
oh wait
I think I know the issue.
could the fact that it's a dict being stringified be the problem?
it cant be the endpoint because otherwise it wouldnt work at all
You're not passing the data it is expecting
yea I just tried to send a very basic string and it still didnt work
checking out your link now, one sec
It has the be formatted like the object I put above
Recommended threads
- Function domain not available
Hello, even tho in docs you clearly describe that every function has its domain, I can not see it anywhere in any of my projects. How do I reveal the url of th...
- Inquiry: How to Reduce Cold Start Durati...
Hey! I was using Python for the function runtime, but after reading that Go has the fastest runtime, I switched my code over to Go. However, I'm still seeing co...
- After a GET request is passed to functio...
Create execution in the console can normally retrieve the get parameters。WHy?