Uploaded image for project: 'Satellite'
  1. Satellite
  2. SAT-18468

Inconsistent API responses for Katello endpoints (integer/string)

XMLWordPrintable

    • Moderate

      Description of problem:

      When querying Katello endpoints that return a collections of objects, e.g. /katello/api/host_collections, the data types of the `page` and `per_page` fields in the response depend on whether they were specified in the query:

      ```
      $ curl -u $SAT_USER:$SAT_PASS 'https://lmchim1250.bisinfo.org/katello/api/host_collections'
      {
      "total": 59,
      "subtotal": 59,
      "selectable": 59,
      "page": 1,
      "per_page": 300,
      "error": null,
      ...
      ```
      In the above query, both `page` and `per_page` in the response are numbers.

      ```
      $ curl -u $SAT_USER:$SAT_PASS -H content-type:application/json 'https://lmchim1250.bisinfo.org/katello/api/host_collections?page=2'
      {
      "total": 59,
      "subtotal": 59,
      "selectable": 59,
      "page": "2",
      "per_page": 300,
      ...
      ```
      In the above query instead, supplying the `page` parameter, the `page` field in the response is now a string!

      The same happens with `per_page`.

      This makes it rather awkward to use in certain languages, when parsing API responses, especially if you need to know the type at compile time.

      We guess it should have stayed an integer instead.

      Steps to Reproduce and Actual results:

      1. curl -u admin:redhat 'https://bvassova-satellite611.gsslab.brq.redhat.com/katello/api/host_collections'
        Unknown macro: {"total"}
      1. curl -u admin:redhat -H content-type:application/json 'https://bvassova-satellite611.gsslab.brq.redhat.com/katello/api/host_collections?page=2'
        Unknown macro: {"total"}

      Expected results:

      1. curl -u admin:redhat 'https://bvassova-satellite611.gsslab.brq.redhat.com/katello/api/host_collections'
        Unknown macro: {"total"}
      1. curl -u admin:redhat -H content-type:application/json 'https://bvassova-satellite611.gsslab.brq.redhat.com/katello/api/host_collections?page=2'
        Unknown macro: {"total"}

      FIXING FORMATTING:

      1. # curl -u admin:redhat 'https://bvassova-satellite611.gsslab.brq.redhat.com/katello/api/host_collections' 
        {{ {"total":0,"subtotal":0,"selectable":0,"page":1,"per_page":20,"error":null,"search":null,"sort":\{"by":"name","order":"asc"}

        ,"results":[]}}}

      2. # curl -u admin:redhat -H content-type:application/json 'https://bvassova-satellite611.gsslab.brq.redhat.com/katello/api/host_collections?page=2'
        {{ {"total":0,"subtotal":0,"selectable":0,"page":"2","per_page":20,"error":null,"search":null,"sort":\{"by":"name","order":"asc"}

        ,"results":[]}}}

       

      Additional info:

      This is intended as a product improvement either for API or Katello component.

            jira-bugzilla-migration RH Bugzilla Integration
            fperalta@redhat.com Francisco Peralta
            RH Bugzilla Integration RH Bugzilla Integration
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: