Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

makapaka's avatar

what am I missing regarding API POST body

i'm finding the docs a tad lacking or maybe i'm just missing something - but i'm trying to write a simple unit test in my lumen API to validate an API endpoint.

I'm just using the ->call('POST') , however I can't figure out how to pass the params for the body - the endpoint takes a json string in the body and I cannot seem to find any examples on how to do this.

I'm trying

$response = $this->call('POST', '/api-check', [ 'body' => $snapshot ]);

where $snapshot is a json string.

but the endpoint is coming up empty on the first line that retrieves the body content:

$responseArray = json_decode($request->getContent(), true);

Please any pointers, i'm not sure why i can't find anything on this Thanks

EDIT: i've just checked the $request itself and it seems the body is actually there - but for some reason $request->getContent() is empty - i've always used this method and testing the API using Postman works this way - so is there something else im doing wrong ?

0 likes
0 replies

Please or to participate in this conversation.