revk / NOTSCO

One Touch Switching test system
Other
7 stars 1 forks source link

Json response required but not allowed #11

Closed mikecoxcowes closed 2 weeks ago

mikecoxcowes commented 2 weeks ago

I've been enjoying using the Notsco system for building our integration but I'm having an issue with getting into an endless loop which I wander if any of you have come across. I'm using Laravel with Passport to connect and that works fine. When I test by sending a Match Request from Notsco, I receive the data and try to respond with a 202 message.

If I send a JSON response with anything in it I get the error message "No JSON response is expected for a 2XX response" return Response::json(['status' => 202], 202)->send();

If I send a JSON response with nothing in it I get the error message "Response is not a JSON object" return Response::json('', 202)->send(); return Response::json([], 202)->send(); return Response::json('accepted', 202)->send(); return Response::json([''], 202)->send();

Anyone got any pointers please?

Many thanks Mike

revk commented 2 weeks ago

The 202 response should have no content at all. That is what I understand from the spec. Not JSON. Not an empty JSON object or array. No content at all. And not content type json, even.

I'll double check the logic in the morning to be sure.

revk commented 2 weeks ago

OK, the wording is

The letterbox API REST interface is synchronous, meaning that when a message is sent to the letterbox it will reply within the same communication session. That reply does not contain a JSON message on a successful post as its purpose is only to acknowledge receipt of the message being delivered to the letter box. However, on a failure, a small JSON error structure will be returned describing the nature of the error.

The key part is That reply does not contain a JSON message on a successful.

When communicating with TOTSCO, they respond with:

Content-Type: application/json
content-length: 0

Can you try some messages today, and I'll see if I can find exactly what we are seeing from you.

rmills9 commented 2 weeks ago

Hi Mike,

Just return the below message which just returns the response code 202 in laravel with no content on success message recevied 202

return response()->noContent(202);

or

return Response::make('', 202);

if you're using the response facade etc.

mikecoxcowes commented 2 weeks ago

Thanks very much. I’ll give that a run.

Mike

Mike Cox @. t.01983 770000 a.23-25 Fortis House, Cothy Way, Ryde, Isle of Wight, PO33 1QT We are rated 9.1 out of 10 Connect with us Go Internet Ltd is a company registered in England and Wales under number 07251276. Registered office: 11 Daish Way, Dodnor Industrial Estate, Newport, Isle of Wight, PO30 5XJ, United Kingdom. Go Internet Ltd accepts no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. Any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. From: rmills9 @.> Sent: Thursday, July 11, 2024 3:04 PM To: revk/NOTSCO @.> Cc: Mike Cox @.>; Author @.***> Subject: Re: [revk/NOTSCO] Json response required but not allowed (Issue #11)

Hi Mike,

Just return the below message which just returns the response code 202 in laravel with no content on success message recevied 202

return response()->noContent(202);

or

return Response::make('', 202);

if you're using the response facade etc.

— Reply to this email directly, view it on GitHubhttps://github.com/revk/NOTSCO/issues/11#issuecomment-2223026351, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BJYGZMMLXDSJZAWM427CNC3ZL2GFJAVCNFSM6AAAAABKTFCBJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRTGAZDMMZVGE. You are receiving this because you authored the thread.Message ID: @.***>

mikecoxcowes commented 1 week ago

Sorry for the delay but I'm only part time in this role.

I've tried sending the suggestions made by rmills9 (thank you) but still get an error:

return response()->noContent(202); returns API§2.1.8: Response is not a JSON object return Response::make('', 202); returns API§2.1.8: Response is not a JSON object return response('', 202); returns API§2.1.8: Response is not a JSON object

revk commented 1 week ago

I'll check the logs on notsco and see if I can tell what you are sending.

revk commented 1 week ago

OK you are sending content-length: 2 and [] as content.

TOTSCO may not care, but the spec says That reply does not contain a JSON message on a successful. Which i take to mean nothing, and not [].

Hope that helps.

mikecoxcowes commented 1 week ago

That must be something odd that Laravel is doing to my empty response! Thanks very much for your help. I really appreciate it. Mike