#Error setting postman body

48 messages · Page 1 of 1 (latest)

tiny sierra
#

Good evening, anyone has an idea on how to pass body to appwrite function using postman? this is how I've passed it :
{
"providerName": "adamu"
}
and I keep getting this error:
"Request body is empty or not a string/object.",
but when I execute using the appwrite console I get the appropriate response.
Thanks in advance

cobalt agate
#

Are you using the domain generated for the function, and are you making a post/patch/put request?

tiny sierra
tiny sierra
#

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

tiny sierra
#

@lyric fjord

lyric fjord
tiny sierra
#

I did just that, can I share you my code ?

lyric fjord
#

Yes

tiny sierra
#

Here or private ?

lyric fjord
#

Here is ok. You can hide the ids and stuf if you want

tiny sierra
#

@lyric fjord I'll do that now

#

@lyric fjord here is it

lyric fjord
tiny sierra
#

you mean i shouldnt send it as json on postman ?

tiny sierra
lyric fjord
tiny sierra
#

@wicked sierra i need help on this

tiny sierra
cobalt agate
#

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": ""
    }
}'
tiny sierra
#

@cobalt agate do you mean it should be JSON.parse(req.bodyJson) in the function?

cobalt agate
#

You shouldn't have to json parse anything, req.bodyJson is already parsed

tiny sierra
#

Okay... Let me try that and see

cobalt agate
#

Can you show in postman how you are making the appwrite call

tiny sierra
#

Okay let me share the screenshot

#

@cobalt agate These scrennshots include the postman(api call, body and response)

cobalt agate
#

That is not how the body for that request is created, have you looked at the documentation?

tiny sierra
#

@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"}"

tiny sierra
cobalt agate
#

Show your postman request.

tiny sierra
tiny sierra
cobalt agate
#

That is not right

tiny sierra
cobalt agate
#

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

tiny sierra
cobalt agate
#

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

tiny sierra
cobalt agate
tiny sierra
# cobalt agate

Let me check that out, I'll keep you posted if I'm able to solve it...thanks for your time

cobalt agate
#

lmk, I can send a postman collection if you need.