Skip to content
Back

I can't see the values I'm sending to my function

  • 0
  • Functions
ks
4 Mar, 2025, 20:45

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"

TypeScript
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}")

TypeScript
    # 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"}
TypeScript
TL;DR
Developers are having trouble seeing the values they're sending to their function via Appwrite. The issue likely lies in the formatting of the outbound payload or enabling data receiving. The solution involves using the SDK to call the REST endpoints directly with correct payload formatting.
Kenny
4 Mar, 2025, 20:46

Just curious is there any reason you're not using the sdk and calling the rest endpoints?

Kenny
4 Mar, 2025, 20:47

The payload for that endpoint is this object

TypeScript
{
  "body": "<BODY>",
  "async": false,
  "path": "<PATH>",
  "method": "GET",
  "headers": {},
  "scheduledAt": 
}

Which could be why you're having issues.

ks
4 Mar, 2025, 20:47

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

TypeScript
    "key": "value"
}

good enough?

Kenny
4 Mar, 2025, 20:48

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.

ks
4 Mar, 2025, 20:49

well thats a good tip, probably faster that way

ks
4 Mar, 2025, 20:49

oh wait

ks
4 Mar, 2025, 20:49

I think I know the issue.

ks
4 Mar, 2025, 20:50

could the fact that it's a dict being stringified be the problem?

ks
4 Mar, 2025, 20:50

it cant be the endpoint because otherwise it wouldnt work at all

Kenny
4 Mar, 2025, 20:53

You're not passing the data it is expecting

ks
4 Mar, 2025, 20:53

yea I just tried to send a very basic string and it still didnt work

ks
4 Mar, 2025, 20:53

checking out your link now, one sec

Kenny
4 Mar, 2025, 20:54

It has the be formatted like the object I put above

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more