Badges

Badges are the core and primary entity of PromoBadger, and on this page we'll dive into how they can be queried using our API.

The Badge object

This object represents a badge that has been created within your project. It contains all of a badges data such as it's ID, type, and any configured custom fields.

Attributes

  • Name
    id
    Type
    String
    Description

    Unique identifier for the badge.

  • Name
    typeId
    Type
    String
    Description

    The user defined identifier for the badges 'type'.

  • Name
    content
    Type
    Object
    Description

    An object containing the values of the custom fields defined against the badges type schema.

The Badge Object

{
  "id": "4d28ffee-29a3-435a-8013-3e5e303e419b",
  "typeId": "productCardBadge",
  "content": {
    "backgroundColour": "#22c55e",
    "textColour": "#ffffff",
    "text": "2 for $50"
  }
}

POST/badges/query/byProductId

List all badges by product ID

Returns a list of badges for up to 100 products. For each product, badges are sorted based on the order defined in your control panel.

Attributes

  • Name
    context
    Type
    Object
    Required
    required
    Description

    The context for the request. ContextObject

  • Name
    query.products
    Type
    Array<ProductQuery>
    Required
    required
    Description

    Array of queries for badges. Limited to a maximum of 100 queries. ProductQuery

ProductQuery Attributes

  • Name
    id
    Type
    Integer
    Required
    required
    Description

    The product ID to retrieve badges for.

  • Name
    variantIds
    Type
    Array<Integer>
    Optional
    optional
    Description

    An optional array of product variant IDs to retrieve badges for.

POST
/v1/{PROJECT_ID}/badges/query/byProductId
curl --request POST \
  --url https://api.promobadger.dev/v1/{PROJECT_ID}/badges/query/byProductId \
  --data '{
  "context": {},
  "query": {
    "products": [{ "id": 1234 }]
  }
}'

Response

{
  "products": [
    {
      "query": { "id": 1234 },
      "badges": [
        {
          "id": "4d28ffee-29a3-435a-8013-3e5e303e419b"
        }
      ]
    }
  ],
  "badges": [
    {
      "id": "4d28ffee-29a3-435a-8013-3e5e303e419b",
      "typeId": "productCardBadge",
      "content": {
        "backgroundColour": "#22c55e",
        "textColour": "#ffffff",
        "text": "2 for $50"
      }
    }
  ]
}