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

Endpoint to retrieve tags under a category with descriptions #704

Open
skateman opened this issue Nov 9, 2019 · 5 comments
Open

Endpoint to retrieve tags under a category with descriptions #704

skateman opened this issue Nov 9, 2019 · 5 comments

Comments

@skateman
Copy link
Member

skateman commented Nov 9, 2019

I need a way to retrieve tags under a given category with tag descriptions (which are actually used across the UI as the title of the given tag). For now I have this request, that returns me with the tags under a category:

# curl -XGET http://admin:smartvm@localhost:3000/api/categories/1\?expand\=tags | jq
{
  "href": "http://localhost:3000/api/categories/1",
  "id": "1",
  "description": "Location",
  "icon": null,
  "read_only": false,
  "syntax": "string",
  "single_value": true,
  "example_text": "The geographic location of the resource, such as New York, Chicago, or London.",
  "tag_id": "3",
  "parent_id": null,
  "show": true,
  "default": true,
  "perf_by_tag": null,
  "name": "location",
  "tags": [
    {
      "href": "http://localhost:3000/api/categories/1/tags/4",
      "id": "4",
      "name": "/managed/location/ny"
    },
    {
      "href": "http://localhost:3000/api/categories/1/tags/5",
      "id": "5",
      "name": "/managed/location/chicago"
    },
    {
      "href": "http://localhost:3000/api/categories/1/tags/6",
      "id": "6",
      "name": "/managed/location/london"
    },
    {
      "href": "http://localhost:3000/api/categories/1/tags/7",
      "id": "7",
      "name": "/managed/location/paris"
    }
  ],
  "actions": [
    {
      "name": "edit",
      "method": "post",
      "href": "http://localhost:3000/api/categories/1"
    },
    {
      "name": "delete",
      "method": "post",
      "href": "http://localhost:3000/api/categories/1"
    },
    {
      "name": "delete",
      "method": "delete",
      "href": "http://localhost:3000/api/categories/1"
    }
  ]
}

But the description is not part of the expanded tags, however, I found a solution to fire a second request that returns me the descriptions as well:

# curl -XPOST http://admin:smartvm@localhost:3000/api/tags/\?attributes\=categorization -d '{ "action": "query", "resources": [ { "id": 4 }, { "id": 5 } ]  }'

{
  "results": [
    {
      "href": "http://localhost:3000/api/tags/4",
      "id": "4",
      "name": "/managed/location/ny",
      "categorization": {
        "name": "ny",
        "description": "New York",
        "category": {
          "name": "location",
          "description": "Location"
        },
        "display_name": "Location: New York"
      },
      "actions": [
        {
          "name": "edit",
          "method": "post",
          "href": "http://localhost:3000/api/tags/4"
        },
        {
          "name": "delete",
          "method": "post",
          "href": "http://localhost:3000/api/tags/4"
        },
        {
          "name": "delete",
          "method": "delete",
          "href": "http://localhost:3000/api/tags/4"
        }
      ]
    },
    {
      "href": "http://localhost:3000/api/tags/5",
      "id": "5",
      "name": "/managed/location/chicago",
      "categorization": {
        "name": "chicago",
        "description": "Chicago",
        "category": {
          "name": "location",
          "description": "Location"
        },
        "display_name": "Location: Chicago"
      },
      "actions": [
        {
          "name": "edit",
          "method": "post",
          "href": "http://localhost:3000/api/tags/5"
        },
        {
          "name": "delete",
          "method": "post",
          "href": "http://localhost:3000/api/tags/5"
        },
        {
          "name": "delete",
          "method": "delete",
          "href": "http://localhost:3000/api/tags/5"
        }
      ]
    }
  ]
}

However, the request building is a little messy as I have to specify all the tag IDs one by one and then merge the result. So my question: is there a way to do this in a single request, by specifying a magic attribute that adds the description field to the expanded tags?

@martinpovolny @abellotti

@martinpovolny
Copy link
Member

Seems right now you really need 2 requests.

@abellotti : can you, please, take a look if we are not wrong?

@martinpovolny
Copy link
Member

https://www.manageiq.org/docs/reference/latest/api/overview/query#expanding-collection

Virtual attributes can also be queried from one-to-one relationships via the dot notation

Here we have 1:n and after that a 1:1 so this is afaik unsupported.

@abellotti
Copy link
Member

maybe this:

api get categories/1/tags --expand=resources --attributes=categorization

@skateman
Copy link
Member Author

@abellotti yes! It works as expected. But what if I want all tags grouped by all categories, i.e. for the 2 dropdowns of the new tagging component?

@miq-bot
Copy link
Member

miq-bot commented Jun 11, 2020

This issue has been automatically marked as stale because it has not been updated for at least 3 months.

If you can still reproduce this issue on the current release or on master, please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions! More information about the ManageIQ triage process can be found in the traige process documentation.

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

No branches or pull requests

6 participants