Project

General

Profile

Bug #6446

We need to either support non-json requests or show an error when a user submits other content types.

Added by David Davis over 8 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
API
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:
Red Hat JIRA:

Description

In the API doc, it says you can either use a root node or not. However, this only works with JSON. As in http://projects.theforeman.org/issues/5178, many (or maybe most) API users aren't using JSON.


Related issues

Related to Foreman - Bug #6786: Cannot create an organization.Closed2014-07-26
Related to Katello - Bug #8846: Katello API throws an incorrect error when receiving non-json requestsClosed2015-01-06

Associated revisions

Revision 50ebc024 (diff)
Added by David Davis over 8 years ago

Fixes #6446 - Forbidding non-json POST/PUT requests in v2

History

#1 Updated by Joseph Magen over 8 years ago

our API is only JSON format??

#2 Updated by David Davis over 8 years ago

Responded to your email but figured I'd post a copy here too. What do you mean by "our API is only JSON format"? Does that mean that users can't submit form data to the fortello API? Looks like you can to me:

$ curl -X POST http://localhost:3000/api/v2/organizations -d "organization[name]=Test2345" -u admin:changeme
{"ancestry":null,"apply_info_task_id":null,"created_at":"2014-07-17T12:22:48Z","default_info":{"system":[],"distributor":[]},"description":null,"id":7,"ignore_types":[],"katello_default":true,"label":"Test2345","name":"Test2345","owner_auto_attach_all_systems_task_id":null,"title":"Test2345","updated_at":"2014-07-17T12:22:55Z","service_levels":[],"service_level":null} 

#3 Updated by David Davis over 8 years ago

The problem that I've dealt with a few times over the past month with the API users is that they see that requests like this don't work:

$ curl -X POST http://localhost:3000/api/v2/organizations -d "name=Test2345" -u admin:changeme

While requests like this do:

$ curl -X POST http://localhost:3000/api/v2/organizations -d "organization[name]=Test2345" -u admin:changeme

So they get confused and then I get asked questions like "Why does the apidoc say that the params should be un-nested but then I get an error when I send nested params?" and "Why are some api endpoints nested and others aren't?" Maybe the solution is to show an error that we only accept JSON? I don't care either way but I feel like we do need to do something though because I've seen this at least 3 times already.

#4 Updated by David Davis over 8 years ago

  • Subject changed from Consider extending wrap_parameters since a lot of API users aren't using JSON to Since a lot of API users aren't using JSON to send requests, consider extending wrap_parameters or showing an error when they send other content types like application/x-www-form-urlencoded

#5 Updated by David Davis over 8 years ago

  • Subject changed from Since a lot of API users aren't using JSON to send requests, consider extending wrap_parameters or showing an error when they send other content types like application/x-www-form-urlencoded to We need to either support non-json requests or show an error when a user submits other content types.

Simplifying title.

By the way, here's another example. QA hits an user-unfriendly error when submitting non-json:

https://bugzilla.redhat.com/show_bug.cgi?id=1116043

#6 Updated by David Davis over 8 years ago

  • Related to Bug #6786: Cannot create an organization. added

#7 Updated by The Foreman Bot over 8 years ago

  • Status changed from New to Ready For Testing
  • Target version set to 1.8.0
  • Pull request https://github.com/theforeman/foreman/pull/1622 added
  • Pull request deleted ()

#8 Updated by Dominic Cleal over 8 years ago

  • Assignee set to David Davis

#9 Updated by Anonymous over 8 years ago

  • Target version changed from 1.8.0 to 1.7.5

#10 Updated by Dominic Cleal over 8 years ago

  • Legacy Backlogs Release (now unused) set to 10

#11 Updated by David Davis over 8 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#12 Updated by Bryan Kearney over 8 years ago

  • Bugzilla link set to 1129769

#13 Updated by David Davis about 8 years ago

  • Related to Bug #8846: Katello API throws an incorrect error when receiving non-json requests added

Also available in: Atom PDF