Unexspected end of JSON input
Hey guys,
I recently updated from API Plugin v6.1.1 to v7.0.3 and got into trouble with the new handling of request body.
I try to extract the body of my request with
const body = await request.readBodyJson();
Once this call is executed I get the error SyntaxError: Unexpected end of JSON input
.
My JSON looks the following
I don't know how to deal with this error as I already tried everything I know to fix this. Any suggestions or ideas would be recommended π4 Replies
You have a leading comma at license_key, which is a syntax error in JSON, and youβre not closing the top brace (
{}
)Good point. I will correct this is only a Copy & Paste Error here sorry π
This was not the error, I fixed the example JSON of my post as I was using the "correct" version on Postman
Funny thing seems like
if (((await request.readBody()) as any).action !== 'app_membership.went_invalid') return response.badRequest();
works but when I want to access .data
I get an exceptionSolution
You shouldn't read the body twice π
Well that's a good point! You are absolutely right, I transformed my code (In v6 I accessed request.body and so on) and now it's working π Thx :this: