Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json response required but not allowed #11

Closed
mikecoxcowes opened this issue Jul 9, 2024 · 8 comments
Closed

Json response required but not allowed #11

mikecoxcowes opened this issue Jul 9, 2024 · 8 comments

Comments

@mikecoxcowes
Copy link

mikecoxcowes commented Jul 9, 2024

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
Copy link
Owner

revk commented Jul 9, 2024

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
Copy link
Owner

revk commented Jul 10, 2024

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
Copy link

rmills9 commented Jul 11, 2024

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
Copy link
Author

mikecoxcowes commented Jul 11, 2024 via email

@revk revk closed this as completed Jul 13, 2024
@mikecoxcowes
Copy link
Author

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
Copy link
Owner

revk commented Jul 15, 2024

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

@revk
Copy link
Owner

revk commented Jul 15, 2024

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

  • Where content-type: application/json we are expecting a JSON object, or nothing.
  • For a 202, as per TOTSCO spec, we are expecting nothing.

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants