Start a conversation

Using a badge set and a badge

Added in 24.2.

Learn about how to use a badge set and a badge.

In this guide, you will learn:

  • Create a badge set
  • Update a badge set
  • Delete a badge set
  • Create a badge
  • Update a badge
  • Delete a badge

Create a badge set

Before creating a badge set, ensure that the badge feature is turned on.

Note: You can create up to five badge sets in a single request.

To create a badge set, use the following mutation:

mutation createBadgeSet($createInput: CreateBadgeSetInput!) {
    createBadgeSet(createInput: $createInput) {
        result {
            id
            name
            featured
            position
        }
        errors {
            ... on Error {
                message
                fields
            }
        }
    }
}

Use the following createInput variable for the mutation:

{
    "createInput": {
        "name": "this is a new badge set"
    }
}

Example response:

{
    "data": {
        "createBadgeSet": {
            "result": {
                "id": "badge_set: 4",
                "name": "this is a new badge set",
                "featured": false,
                "position": 3
            },
            "errors": null
        }
    }
}

Update a badge set

In this section, we are going to update the name, position, and featured variables of the badge set (ID: 3).

mutation updateBadgeSet($id: ID!, $updateInput: UpdateBadgeSetInput!) {
    updateBadgeSet(id: $id, updateInput: $updateInput) {
        result {
            id
            name
            featured
            position
        }
        errors {
            ... on Error {
                message
                fields
            }
        }
    }
}

Variables:

{
    "id": "badge_set:4",
    "updateInput": {
        "name": "This is an badge set related to activity of the user.",
        "position": 0,
        "featured": true
    }
}

Note:

  • The name field must be less than 80 characters.
  • The position field must be greater than zero.

Example response:

{
    "data": {
        "updateBadgeSet": {
            "result": {
                "id": "badge_set: 4",
                "name": "This is an badge set related to activity of the user.",
                "featured": true,
                "position": 0
            },
            "errors": null
        }
    }
}

Delete a badge set

You can delete a badge set by using the deleteBadgeSet mutation.

Mutation:

mutation deleteBadgeSet($id: ID!) {
    deleteBadgeSet(id: $id) {
        result
        errors {
            ... on Error {
                message
                fields
            }
        }
    }
}

Variables:

{
    "id": "badge_set:4"
}

Example response:

{
    "data": {
        "deleteBadgeSet": {
            "result": true,
            "errors": null
        }
    }
}

Create a badge

In this section, we will create a badge in the badge set.

The required fields to create a badge in the badge set are:

  • icon
  • formula
  • badge set
  • hidden

We are going to create a Badge 1 badge in the badge set: 1 with a title Badge 1, hidden as false, map the local image file to the badge, and a formula.

Mutation:

mutation($file: Upload!) {
    createBadge(createInput: {
        icon: {file: $file}
        badgeSet: "badge_set:1"
        title: "Badge 1"
        hidden: false
        formula: "metric.tagging_tag_count >= 1"
    }) {
        result {
            title
        }
        errors {
            ...on Error {
                message
                fields
            }
        }
    }
}

Map the variables.file to a variable 0:

{"0":["variables.file"]}

Assign the variable 0 with an image file.

attach an image file

Example response:

{
    "data": {
        "createBadge": {
            "result": {
                "title": "Badge 1"
            },
            "errors": null
        }
    }
}

Update a badge

In this section, we are going to update the title of badge 1 to Most Liked. The ID of badge 1 is 21.

Mutation:

mutation updateBadge($id: ID!, $updateInput: UpdateBadgeInput!) {
    updateBadge(id: $id, updateInput: $updateInput) {
        result {
            id
            title
            description
            position
        }
        errors {
            ... on Error {
                message
                fields
            }
        }
    }
}

Variables:

{
    "id": "badge:21",
    "updateInput": {
        "description": "This badge is given to user who idea are most liked.",
        "position": 10,
        "title": "Most Liked"
    }
}

Example response:

{
    "data": {
        "updateBadge": {
            "result": null
        }
    }
}

Delete Badge

In this section, we will delete the badge 21.

Mutation:

mutation deleteBadge($id: ID!) {
    deleteBadge(id: $id) {
        result {
            id
            title
            description
            icon {
                url
            }
        }
        errors {
            ... on Error {
                message
                fields
            }
        }
    }
}

Variables:

{
    "id": "badge:21"
}

Example response:

{
    "data": {
        "deleteBadge": {
            "result": [],
            "errors": null
        }
    }
}
Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. ATLAS

  2. Posted
  3. Updated

Comments