• Image Management Service

ims
  1. Help Center
  2. Image Management Service
  3. API Reference
  4. APIs
  5. Image Tagging (Extension APIs)
  6. Querying Images by Tag

Querying Images by Tag

Function

This API is used to filter or count images using tags or other conditions.

Constraints

  • To be compatible with remaining tags, the system will not verify the character set of the tag keys and values in the query condition when parameters tags not_tagstags_any, and not_tags_any are used.

URI

  • URI format
    POST /v2/{project_id}/images/resource_instances/action
  • Parameter description

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

    Specifies the project ID.

Request

  • Parameter description

    Parameter

    Mandatory

    Type

    Description

    action

    Yes

    String

    Identifies the operation. This parameter is case sensitive and its value can be filter or count.

    • The value filter indicates pagination query.
    • The value count indicates that the total number of query results meeting the search criteria will be returned.

    tags

    No

    List<tag>

    Includes all specified tags. A maximum of 10 tag keys are allowed for each query operation. Each tag key can contain a maximum of 10 tag values. Both tag keys and values must be unique. The tag keys cannot be left blank.

    tags_any

    No

    List<tag>

    Includes any of specified tags. A maximum of 10 tag keys are allowed for each query operation. Each tag key can contain a maximum of 10 tag values. Both tag keys and values must be unique. The tag keys cannot be left blank and set to an empty string.

    not_tags

    No

    List<tag>

    Excludes all specified tags. A maximum of 10 tag keys are allowed for each query operation. Each tag key can contain a maximum of 10 tag values. Both tag keys and values must be unique. The tag keys cannot be left blank.

    not_tags_any

    No

    List<tag>

    Excludes any of specified tags. A maximum of 10 tag keys are allowed for each query operation. Each tag key can contain a maximum of 10 tag values. Both tag keys and values must be unique. The tag keys cannot be left blank.

    limit

    No

    String

    Specifies the maximum number of images to be queried. This parameter is available when action is set to filter, and the default value is 10 if it is not specified. The maximum value is 1000, the minimum value is 1, and the value cannot be a negative number.

    offset

    No

    String

    Specifies the index position. The query starts from the next image indexed by this parameter. This parameter is not required when data on the first page is queried, and it is unavailable when action is set to count. If action is set to filter, the default value is 0. The value cannot be a negative integer.

    matches

    No

    List<match>

    Specifies the search criteria. The tag key is the field to match, for example, resource_name or resource_idvalue indicates the matched value. Keys in this list must be unique. The parameter cannot be left blank and may not be transferred.

  • Data structure description of the tag field

    Parameter

    Mandatory

    Type

    Description

    key

    Yes

    String

    Specifies the tag key. The tag key contains a maximum of 127 Unicode characters and cannot be left blank.

    values

    Yes

    List<String>

    Lists the tag values. Each value can contain a maximum of 255 Unicode characters. If this parameter is left blank, any value is matched. When multiple values are specified and the key requirements are met, images that have any of the specified values are queried.

  • Data structure description of the matches field

    Parameter

    Mandatory

    Type

    Description

    key

    Yes

    String

    Specifies the tag key, that is to say, the field name for the query operation. Valid values include resource_name and resource_id.

    If the field name is resource_name and the value is an empty string, exact query is performed. Otherwise, fuzzy query is performed based on the image name. If the field name is resource_id, exact query is performed based on the image ID.

    value

    Yes

    String

    Specifies the tag value. It cannot be left blank. Each value can contain a maximum of 255 Unicode characters.

  • Example requests
    POST /v2/fd73a4a14a4a4dfb9771a8475e5198ea/images/resource_instances/action
    • Request body when action is set to count
      {
         "action": "count",
         "matches": [{
            "key": "resource_name",
            "value": "test100"
         }],
         "tags": [
         {
            "key": "key3",
            "values": ["valueXX"]
         }],
         "tags_any": [
         {
            "key": "key0",
            "values": ["valueXX"]
         }],
            "not_tags": [
         {
            "key": "key9",
            "values": ["value9"]
         }],
         "not_tags_any": [{
            "key": "key7",
            "values": ["value7"]
         }]
      }
    • Request body when action is set to filter
      {
         "action": "filter",
         "limit": "1",
         "offset": "0",
         "matches": [{
            "key": "resource_name",
            "value": "test100"
         }],
         "tags": [
         {
            "key": "key3",
            "values": ["valueXX"]
         }],
         "tags_any": [
         {
            "key": "key0",
            "values": ["valueXX"]
         }],
         "not_tags": [
         {
            "key": "key9",
            "values": ["value9"]
         }],
         "not_tags_any": [{
            "key": "key7",
            "values": ["value7"]
         }]
      }

Response

  • Parameter description

    Parameter

    Type

    Description

    resources

    List<resource>

    Lists the images.

    total_count

    Integer

    Specifies the total number of query records.

  • Data structure description of the resource field

    Parameter

    Type

    Description

    resource_id

    String

    Specifies the image ID.

    resouce_detail

    Dict

    Provides image details.

    tags

    List<resource_tag>

    Lists the image tags.

    resource_name

    String

    Specifies the image name.

  • Data structure description of the resource_tag field

    Parameter

    Type

    Description

    key

    String

    Specifies the key of the tag.

    value

    String

    Specifies the value of the tag.

  • Example response bodies
    • Example response when action is set to count
      STATUS CODE 200
      {
         "total_count": 36
      }
    • Example response when action is set to filter
      STATUS CODE 200
      {
         "total_count": 36,
         "resources": [{
            "resource_name": "test10002",
            "resource_detail": {"status": "active"},
            "tags": [{
               "value": "value4",
               "key": "key4"
            },
            {
               "value": "valueXX",
               "key": "key3"
            },
            {
               "value": "value2",
               "key": "key2"
            },
            {
               "value": "value5",
               "key": "key5"
            },
            {
               "value": "value8",
               "key": "key8"
            },
            {
               "value": "valueXX",
               "key": "key6"
            },
            {
               "value": "valueXX",
               "key": "key0"
            },
            {
               "value": "value1",
               "key": "key1"
            },
            {
               "value": "value7",
               "key": "key7"
            },
            {
               "value": "valueXX",
               "key": "key9"
         }],
            "resource_id": "8693187d-1590-4f9f-ae34-eb9e3037cf68"
      }]
      }

Returned Values

  • Normal

    200

  • Abnormal

    Return Value

    Description

    400 Bad Request

    Request error.

    401 Unauthorized

    Authentication failed.

    403 Forbidden

    You do not have the rights to perform the operation.

    404 Not Found

    The requested resource was not found.

    500 Internal Server Error

    Internal service error.

    503 Service Unavailable

    The service is unavailable.