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 almost 4 years ago. Updated over 3 years ago.

Status:Closed
Priority:Normal
Assigned To:David Davis
Category:API
Target version:Sprint 27
Difficulty: Bugzilla link:1129769
Found in release: Pull request:https://github.com/theforeman/foreman/pull/1622
Story points-
Velocity based estimate-
Release1.6.0Release relationshipAuto

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. Closed 07/26/2014
Related to Katello - Bug #8846: Katello API throws an incorrect error when receiving non-... Closed 01/06/2015

Associated revisions

Revision 50ebc024
Added by David Davis over 3 years ago

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

History

#1 Updated by Joseph Magen almost 4 years ago

our API is only JSON format??

#2 Updated by David Davis almost 4 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 almost 4 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 almost 4 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 3 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 3 years ago

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

#7 Updated by The Foreman Bot over 3 years ago

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

#8 Updated by Dominic Cleal over 3 years ago

  • Assigned To set to David Davis

#9 Updated by Dmitri Dolguikh over 3 years ago

  • Target version changed from Sprint 26 to Sprint 27

#10 Updated by Dominic Cleal over 3 years ago

  • Release set to 1.6.0

#11 Updated by David Davis over 3 years ago

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

#12 Updated by Bryan Kearney over 3 years ago

  • Bugzilla link set to 1129769

#13 Updated by David Davis over 3 years ago

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

Also available in: Atom PDF