Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Make all back-end APIs accept JSON payload rather than formData #2023

Closed
maxpatiiuk opened this issue Aug 23, 2022 · 0 comments
Closed

Make all back-end APIs accept JSON payload rather than formData #2023

maxpatiiuk opened this issue Aug 23, 2022 · 0 comments
Assignees
Labels
1 - Request A request made by a member of the community 2 - API Issues that are related to the APIs good first issue

Comments

@maxpatiiuk
Copy link
Member

From a user support email:

I believe the 500 error he gets is because he is sending the requests body as JSON rather than form data.
I get confused by that all the time too.
Can we either give a proper error message for cases like this, or make [all] APIs accept JSON payload (like all modern APIs)?
I believe you mentioned earlier that it is harder to get JSON payload that form data payload, but can you just write a utility function for that and use it in API request handlers?

Currently, some endpoins accept JSON, and some form data


User email:

Now I’m getting a 500 server error that I will attempt to troubleshoot.

From the logs I can gather that the POST request may be malformed as it doesn’t appear to pick up on the target id:

  [Thu Aug 18 07:15:38.085715 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)] Traceback (most recent call last):

  [Thu Aug 18 07:15:38.085717 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]   File "/home/specify/currentversion/specify7/ve/lib64/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

  [Thu Aug 18 07:15:38.085719 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]     response = get_response(request)

  [Thu Aug 18 07:15:38.085721 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]   File "/home/specify/currentversion/specify7/ve/lib64/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response

 [Thu Aug 18 07:15:38.085723 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]     response = self.process_exception_by_middleware(e, request)

 [Thu Aug 18 07:15:38.085726 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]   File "/home/specify/currentversion/specify7/ve/lib64/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response

 [Thu Aug 18 07:15:38.085728 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]     response = wrapped_callback(request, *callback_args, **callback_kwargs)

 [Thu Aug 18 07:15:38.085730 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]   File "/home/specify/currentversion/specify7/specifyweb/specify/views.py", line 20, in wrapped

 [Thu Aug 18 07:15:38.085732 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]     return view(request, *args, **kwargs)

 [Thu Aug 18 07:15:38.085735 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]   File "/home/specify/currentversion/specify7/ve/lib64/python3.6/site-packages/django/views/decorators/http.py", line 40, in inner

 [Thu Aug 18 07:15:38.085737 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]     return func(request, *args, **kwargs)

 [Thu Aug 18 07:15:38.085739 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]   File "/home/specify/currentversion/specify7/specifyweb/specify/views.py", line 32, in wrapped

 [Thu Aug 18 07:15:38.085755 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]     return view(request, *args, **kwargs)

 [Thu Aug 18 07:15:38.085758 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]   File "/usr/lib64/python3.6/contextlib.py", line 52, in inner

 [Thu Aug 18 07:15:38.085760 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]     return func(*args, **kwds)

 [Thu Aug 18 07:15:38.085762 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]   File "/home/specify/currentversion/specify7/specifyweb/specify/tree_views.py", line 30, in wrapper

 [Thu Aug 18 07:15:38.085764 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]     mutation(*args, **kwargs)

 [Thu Aug 18 07:15:38.085766 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]   File "/home/specify/currentversion/specify7/specifyweb/specify/tree_views.py", line 253, in merge

 [Thu Aug 18 07:15:38.085768 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]     target = get_object_or_404(tree, id=request.POST['target'])

 [Thu Aug 18 07:15:38.085770 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]   File "/home/specify/currentversion/specify7/ve/lib64/python3.6/site-packages/django/utils/datastructures.py", line 80, in __getitem__

 [Thu Aug 18 07:15:38.085772 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)]     raise MultiValueDictKeyError(key)

 [Thu Aug 18 07:15:38.085776 2022] [wsgi:error] [pid 7547] [remote [10.175.116.29:64655](http://10.175.116.29:64655/)] django.utils.datastructures.MultiValueDictKeyError: 'target'

@maxpatiiuk maxpatiiuk added 1 - Request A request made by a member of the community back-end labels Aug 23, 2022
@grantfitzsimmons grantfitzsimmons moved this to 📋 Backlog in Back-End Backlog Mar 9, 2023
@grantfitzsimmons grantfitzsimmons added the 2 - API Issues that are related to the APIs label Aug 5, 2023
@specify specify locked and limited conversation to collaborators Dec 20, 2024
@grantfitzsimmons grantfitzsimmons converted this issue into discussion #5619 Dec 20, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Back-End Backlog Dec 20, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
1 - Request A request made by a member of the community 2 - API Issues that are related to the APIs good first issue
Projects
Status: Done
Development

No branches or pull requests

3 participants