Retrieving product labels
  • 19 Nov 2020
  • 3 Minutes To Read
  • Print
  • Share
  • Dark
    Light

Retrieving product labels

  • Print
  • Share
  • Dark
    Light

Product labels are used to draw your customers' attention to some specific products. Each of them has a name, a priority, and a validity period. The Product Labels API provides endpoints for getting labels via the REST HTTP requests.

Installation

For detailed information on the modules that provide the API functionality and related installation instructions, see Glue API: Product Labels Feature Integration.

Retrieve a product label

To retrieve a product label, send the request:


GET /product-labels/{{product_label_id}}


Path parameter Description
{{product_label_id}} ID of a product label to retrieve. You can check it in the Back Office > Products > Product Labels

Request

Request sample: GET http://glue.mysprykershop.com/product-labels/3

Response

Response sample
{
    "data": {
        "type": "product-labels",
        "id": "3",
        "attributes": {
            "name": "Standard Label",
            "isExclusive": false,
            "position": 3,
            "frontEndReference": ""
        },
        "links": {
            "self": "http://glue.mysprykershop.com/product-labels/3"
        }
    }
}

Attribute Type Description
name String Specifies the label name.
isExclusive Boolean Indicates whether the label is exclusive.
If the attribute is set to true, the current label takes precedence over other labels the product might have. This means that only the current label should be displayed for the product, and all other possible labels should be hidden.
position Integer Indicates the label priority.
Labels should be indicated on the frontend according to their priority, from the highest (1) to the lowest, unless a product has a label with the isExclusive attribute set.
frontEndReference String Specifies the label custom label type (CSS class).
If the attribute is an empty string, the label should be displayed using the default CSS style.

Get Product Labels for Cart Items

To retrieve labels for all products in a cart, send a GET request to the following endpoints and include product-labels as a relationship:

Cart Type Endpoints* Sample Request Description Notes
Registered Customer Cart /carts/?include=items,concrete-products,product-labels GET /carts?include=items,concrete-products,product-labels Gets labels for all products in all carts of a customer. To fetch carts of registered customers, you need to authenticate the customers and pass the authentication token as part of your request. For details, see Managing Carts of Registered Users.
Registered Customer Cart /carts/{{cart_ID}}?include=items,concrete-products,product-labels GET /carts/369541fa2e-02c2-5d47-b397-8ac1f5c58ff9?include=items,concrete-products,product-labels Gets labels for all products in a specific cart. To fetch carts of registered customers, you need to authenticate the customers and pass the authentication token as part of your request. For details, see Managing Carts of Registered Users.
Registered Customer Cart /carts/{{cart_ID}}/up-selling-products?include=items,concrete-products,product-labels GET /carts/369541fa2e-02c2-5d47-b397-8ac1f5c58ff9/up-selling-products?include=items,concrete-products,product-labels Gets product labels for all up-selling products of a specific cart. To fetch carts of registered customers, you need to authenticate the customers and pass the authentication token as part of your request. For details, see Managing Carts of Registered Users.
Performance
The above requests fetch not only label information, but also information on the products in the cart. That can adversely affect the overall performance. Use them with caution and apply caching, where possible.

Get Product Labels for Wishlist Items

To retrieve labels for all products in a wishlist, send a GET request to the following endpoints and include product-labels as a relationship:

  • /wishlists?include=wishlist-items,concrete-products,product-labels - all wishlists of a customer;
  • /wishlists/{{wishlist_ID}}?include=wishlist-items,concrete-products,product-labels - specific wishlist.

Sample request: GET http://glue.mysprykershop.com/wishlists/19154981-f490-56b5-9537-359703a2ed08?include=wishlist-items,concrete-products,product-labels

where 19154981-f490-56b5-9537-359703a2ed08 is the ID of the wishlist you need labels for.

Performance
The above requests fetch not only label information, but also information on the products in the wishlist. That can adversely affect the overall performance. Use them with caution and apply caching, where possible.

Response

The endpoint responds with information on the requested wishlist, including the products in it and the labels assigned to them. For each assigned label, the attributes are the same as when requesting that specific label.

Sample:

{
    "data": {
        "type": "wishlists",
        "id": "19154981-f490-56b5-9537-359703a2ed08",
        "attributes": {...},
        "links": {...},
        "relationships": {
            "wishlist-items": {
                "data": [
                    {
                        "type": "wishlist-items",
                        "id": "020_21081478"
                    }
                ]
            }
        }
    },
    "included": [
        {
            "type": "product-labels",
            "id": "3",
            "attributes": {
                "name": "Standard Label",
                "isExclusive": false,
                "position": 3,
                "frontEndReference": ""
            },
            "links": {
                "self": "http://glue.mysprykershop.com/product-labels/3"
            }
        },
        {
            "type": "product-labels",
            "id": "5",
            "attributes": {
                "name": "SALE %",
                "isExclusive": false,
                "position": 5,
                "frontEndReference": "highlight"
            },
            "links": {
                "self": "http://glue.mysprykershop.com/product-labels/5"
            }
        },
        {
            "type": "concrete-products",
            "id": "020_21081478",
            "attributes": {...},
            "links": {...},
            "relationships": {
                "product-labels": {
                    "data": [
                        {
                            "type": "product-labels",
                            "id": "3"
                        },
                        {
                            "type": "product-labels",
                            "id": "5"
                        }
                    ]
                }
            }
        },
        {
            "type": "wishlist-items",
            "id": "020_21081478",
            "attributes": {...},
            "links": {...},
            "relationships": {
                "concrete-products": {
                    "data": [
                        {
                            "type": "concrete-products",
                            "id": "020_21081478"
                        }
                    ]
                }
            }
        }
    ]
}

Possible errors

Code Reason
400 Product label ID is not specified.
404 A label with the specified ID does not exist.

For information on the possible error responses, see Managing Wishlists.

Was This Article Helpful?