#Error setting postman body
48 messages · Page 1 of 1 (latest)
Are you using the domain generated for the function, and are you making a post/patch/put request?
No, I'm using this domain in this postman:
https://fra.cloud.appwrite.io/v1/functions/function-id/executions
and it is a post request
what I noticed is that if parse the body in the console, I get the appropriate response, but if its postman I'll get invalid req.body: attached are the screenshots of the postman and the appwrite console
@lyric fjord
Here from console ss you can see the body is string type. So stringifying the object should work.then parse it in the function
I did just that, can I share you my code ?
Yes
Here or private ?
Here is ok. You can hide the ids and stuf if you want
the function side is good
have you tried sending the data as a string or still not working?
you mean i shouldnt send it as json on postman ?
You mean I shouldn't send it as JSON on POSTMAN? , when I execute the function on Appwrite console, I get the appropriate response, the issue is using POSTMAN with it, that is when I get req.body is empty error.
just try stringifying it i guess
tbh I havent tried postman so its a lot confusing for me too
@wicked sierra i need help on this
Thanks, I really appreciate your time.
I can take a look at this in about an hour
Instead of req.body you should be using req.bodyJson
req.body is a string, req.bodyJson is a parsed version of the body
Here is the call I setup in postman that works just fine for a small function I created to test
curl --location 'https://fra.cloud.appwrite.io/v1/functions/6852bbbb002f2f4e2224/executions' \
--header 'X-Appwrite-Project: 6841f3c90005c8feef8f' \
--header 'Content-Type: application/json' \
--data '{
"body": "{\n\"test\": \"test\"\n}",
"async": false,
"path": "/",
"method": "POST",
"headers": {
"null": ""
}
}'
@cobalt agate do you mean it should be JSON.parse(req.bodyJson) in the function?
You shouldn't have to json parse anything, req.bodyJson is already parsed
Okay... Let me try that and see
Can you show in postman how you are making the appwrite call
Okay let me share the screenshot
@cobalt agate These scrennshots include the postman(api call, body and response)
That is not how the body for that request is created, have you looked at the documentation?
@cobalt agate even after reading the docs, and setting the req.body to req.bodyJson or req.bodyText, I still have the same issue, but the error says:
{"success":false,"message":"Unexpected end of JSON input"}"
Which means that the body is still empty
Show your postman request.
@cobalt agate
That is not right
have you looked at the documentation
Your body must look like this
{
"body": "<BODY>",
"async": false,
"path": "<PATH>",
"method": "GET",
"headers": {},
"scheduledAt":
}
You could also have looked in the network tab from the console how the call was being made
You mean my body should be this
instead of {"providerName":"jane"}?
Yes...
The call you're making with execute does not directly call the function but puts your call in a queue that is fulfilled by a worker. So you provide all the information needed for that worker to make the call
I'll check that out, sorry where can I get this information from the docs, cause I've checked through ?
Let me check that out, I'll keep you posted if I'm able to solve it...thanks for your time
lmk, I can send a postman collection if you need.