Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
Adrien Pétremann edited this page Jun 28, 2016 · 4 revisions

Authentication

As an authenticated user, visible badges are limited to the tags you belong to.
You can't update, delete nor give a badge unless you are authenticated as an admin.

Create a badge

You need to be an administrator to do this.

POST /badges

Parameters

Name Type Description
title string Required. Title of the badge.
description string Required. A description of the badge, on how to obtain it.
tags array of strings Array of tag codes the badge will belong to. Every users that belong to at least one of this tags will be able to see this badge.

Example

{
  "title": "Say 'What' Again",
  "description": "To unlock this badge, say 'what' again, I dare you.",
  "tags": [
    "community",
    "movie"
  ]
}

Response

Headers
Status: 201 Created
Location: https://api.badger.local/badges/1265f62f-f4ff-11e5-832b-b86b23bc0685
Body
{
  "id": "1265f62f-f4ff-11e5-832b-b86b23bc0685",
  "url": "https://api.badger.local/badges/1265f62f-f4ff-11e5-832b-b86b23bc0685",
  "image_url": "https://api.badger.local/uploads/badges/1265f62f-f4ff-11e5-832b-b86b23bc0685.png",
  "title": "Say What Again",
  "description": "To unlock this badge, say what again, I dare you.",
  "tags": [
    {
      "url": "https://api.badger.local/tags/community",
      "name": "Community",
      "code": "community",
      "created_at": "2011-04-10T20:09:31Z",
      "is_default": true
    },
    {
      "url": "https://api.badger.local/tags/movie",
      "name": "Movie",
      "code": "movie",
      "created_at": "2012-07-11T20:00:34Z",
      "is_default": false
    }
  ],
  "possessors": []
}

List all badges

Note that administrators can see all badges, regardless of tags they belong to.

GET /badges

Parameters

Name Type Description
filter string Indicates which sorts of badges to return. Can be one of:
* unlocked: Badges you unlocked
* claimed: Badges claimed by you
* all: All badges the authenticated user can see, regardless of claim or unlock
Default: all
tags string A list of comma separated tag codes. Example: community,movie,game
sort string What to sort results by. Can be either name, description. Default: name
direction string The direction of the sort. Can be either asc or desc. Default: desc

Response

Headers
Status: 200 OK
Link: <https://api.badger.local/badges?page=2>; rel="next",
      <https://api.badger.local/badges?page=5>; rel="last"
Body
[
  {
    "id": "f5e3fb6f-f52d-11e5-832b-b86b23bc0685",
    "url": "https://api.badger.local/badges/f5e3fb6f-f52d-11e5-832b-b86b23bc0685",
    "image_url": "https://api.badger.local/uploads/badges/f5e3fb6f-f52d-11e5-832b-b86b23bc0685.png",
    "title": "Master of Potatoes",
    "description": "You built a machine with at least 250 potatoes.",
    "tags": [
      {
        "url": "https://api.badger.local/tags/game",
        "name": "Game",
        "code": "game",
        "created_at": "2011-04-10T20:09:31Z",
        "is_default": false
      }
    ],
    "possessors_url": "https://api.badger.local/badges/f5e3fb6f-f52d-11e5-832b-b86b23bc0685/possessors"
  }
]

Get a single badge

GET /badges/123

Response

Headers

Status: 200 OK
Body
{
  "id": "f5e3fb6f-f52d-11e5-832b-b86b23bc0685",
  "url": "https://api.badger.local/badges/f5e3fb6f-f52d-11e5-832b-b86b23bc0685",
  "image_url": "https://api.badger.local/uploads/badges/f5e3fb6f-f52d-11e5-832b-b86b23bc0685.png",
  "title": "Master of Potatoes",
  "description": "You built a machine with at least 250 potatoes.",
  "tags": [
    {
      "url": "https://api.badger.local/tags/game",
      "name": "Game",
      "code": "game",
      "created_at": "2011-04-10T20:09:31Z",
      "is_default": false
    }
  ],
  "possessors": [
    {
      "username": "bender",
      "id": "a42ba74c-f205-11e5-a7ca-b86b23bc0685",
      "url": "https://api.badger.local/users/a42ba74c-f205-11e5-a7ca-b86b23bc0685",
      "avatar_url": "https://avatars0.githubusercontent.com/u/301169?v=3&s=460",
      "badges_url": "https://api.badger.local/users/a42ba74c-f205-11e5-a7ca-b86b23bc0685/badges",
      "quests_url": "https://api.badger.local/users/a42ba74c-f205-11e5-a7ca-b86b23bc0685/quests",
      "adventures_url": "https://api.badger.local/users/a42ba74c-f205-11e5-a7ca-b86b23bc0685/adventures",
      "nuts": 225
    }
  ]
}

Edit a badge

Only administrators can edit a badge.

PATCH /badges/123

Parameters

Name Type Description
title string Required. Title of the badge.
description string Required. A description of the badge, on how to obtain it.
tags array of strings Array of tag codes the badge will belong to. Every users that belong to at least one of this tags will be able to see this badge.

Example

{
  "title": "Say 'What' Again",
  "description": "To unlock this badge, say 'what' again, I dare you.",
  "tags": [
    "community",
    "movie",
    "legendary"
  ]
}

Response

Headers
Status: 200 OK
Body
{
  "id": "1265f62f-f4ff-11e5-832b-b86b23bc0685",
  "url": "https://api.badger.local/badges/1265f62f-f4ff-11e5-832b-b86b23bc0685",
  "image_url": "https://api.badger.local/uploads/badges/1265f62f-f4ff-11e5-832b-b86b23bc0685.png",
  "title": "Say What Again",
  "description": "To unlock this badge, say what again, I dare you.",
  "tags": [
    {
      "url": "https://api.badger.local/tags/community",
      "name": "Community",
      "code": "community",
      "created_at": "2011-04-10T20:09:31Z",
      "is_default": true
    },
    {
      "url": "https://api.badger.local/tags/movie",
      "name": "Movie",
      "code": "movie",
      "created_at": "2012-07-11T20:00:34Z",
      "is_default": false
    },
    {
      "url": "https://api.badger.local/tags/legendary",
      "name": "Legendary",
      "code": "legendary",
      "created_at": "2012-07-11T20:00:34Z",
      "is_default": false
    }
  ],
  "possessors": [
      {
      "username": "bender",
      "id": "a42ba74c-f205-11e5-a7ca-b86b23bc0685",
      "url": "https://api.badger.local/users/a42ba74c-f205-11e5-a7ca-b86b23bc0685",
      "avatar_url": "https://avatars0.githubusercontent.com/u/301169?v=3&s=460",
      "badges_url": "https://api.badger.local/users/a42ba74c-f205-11e5-a7ca-b86b23bc0685/badges",
      "quests_url": "https://api.badger.local/users/a42ba74c-f205-11e5-a7ca-b86b23bc0685/quests",
      "adventures_url": "https://api.badger.local/users/a42ba74c-f205-11e5-a7ca-b86b23bc0685/adventures",
      "nuts": 225
    }
  ]
}