Skip to content
michaelkringelhede edited this page Oct 22, 2022 · 11 revisions

The jid-server API has the following endpoints:

Location search

You can search for locations by Jid without being logged in:

GET /api/locations/:jid

Response for /api/locations/5gb75n will be similar to:

{
    "location": {
        "id": "79b42f6d-bfa2-49e9-ab07-542359864877",
        "year": 2022,
        "jid": "5gb75n",
        "country": "gb",
        "name": "Magrathea 2022",
        "owner": "bc99c4a3-c186-4104-928d-5843c16ec69b",
        "created": "2022-10-22 18:47:22"
    },
    "errorCode": null,
    "error": null
}

Fetch stats

Fetching stats from the jid-server only required the location id:

GET /api/locations/:location/stats

The response for /api/locations/79b42f6d-bfa2-49e9-ab07-542359864877/stats will be similar to:

{
    "users": [
        {
            "position": 1,
            "userid": "cf4ac6ff-c49e-4a12-84b0-0a255fde6e90",
            "name": "Anker Monrad",
            "jids": 5,
            "countries": 3,
            "latest": "2019-10-18T16:35:26+02:00",
            "change": {
                "jids": 3,
                "countries": 1,
                "position": 1
            }
        },
        {
            "position": 2,
            "userid": "50a59d04-c3ce-47ef-8246-3db11f93f05d",
            "name": "Hilmar Kampmann",
            "jids": 3,
            "countries": 2,
            "latest": "2019-10-18T16:37:20+02:00",
            "change": {
                "jids": 1,
                "countries": 1,
                "position": -1
            }
        },
        {
            "position": 3,
            "userid": "4a66ba4a-f03f-4cf9-8bff-724551139e01",
            "name": "Ove Sehested",
            "jids": 2,
            "countries": 1,
            "latest": "2019-10-18T15:15:15+02:00",
            "change": {
                "jids": 0,
                "countries": 0,
                "position": 0
            }
        }
    ],
    "countries": [
        {
            "position": 1,
            "country": "dk",
            "countryName": "Denmark",
            "jids": 4,
            "created": "2019-10-18T16:26:30+02:00",
            "change": {
                "jids": 0,
                "position": 0
            }
        },
        {
            "position": 2,
            "country": "se",
            "countryName": "Sweden",
            "jids": 3,
            "created": "2019-10-18T16:11:21+02:00",
            "change": {
                "jids": 2,
                "position": 1
            }
        },
        {
            "position": 2,
            "country": "no",
            "countryName": "Norway",
            "jids": 1,
            "created": "2019-10-18T16:26:50+02:00",
            "change": {
                "jids": 0,
                "position": -1
            }
        }
    ],
    "totals": {
        "jids": 10,
        "unique": 7,
        "countries": 3,
        "change": {
            "jids": 4,
            "unique": 1,
            "countries": 0
        }
    },
    "error": null,
    "errorCode": null
}

Admins

Create admin

Admins can be created using the API:

POST /api/admins
{
	"name": "Zaphod Beeblebrox",
	"email": "[email protected]",
	"password": "Pan-Galactic Gargle Blaster",
	"phone": "+44 1978 1980"
}

Response will be similar to:

{
    "id": "bb115c88-b404-4ebe-9297-e8fb9524285f",
    "created": true,
    "token": "eyJhbGciOiJ...ETCcfoKZ6xA4bZuw",
    "error": null,
    "errorCode": null
}

Login

Once the admin is created you can use the token returned from "Create admin" or you can fetch a new token like this:

POST /admins/login
{
	"email": "[email protected]",
	"password": "Pan-Galactic Gargle Blaster"
}

Response will be similar to:

{
    "successful": true,
    "token": "eyJhbGciOiJ...ZqS0Gj48ifOUew04",
    "errorCode": null,
    "error": null
}

Create location

Admins can create new locations using the API (needs to be logged in as Admin first):

POST /api/locations
{
	"year": 2022,
	"jid": "5gb75n",
	"name": "Magrathea 2022"
}

Response will be similar to:

{
    "id": "79b42f6d-bfa2-49e9-ab07-542359864877",
    "created": true,
    "errorCode": null,
    "error": null
}

Show locations

Admins can fetch their own locations using the API (needs to be logged in as Admin first):

GET /locations

Response will be similar to:

{
    "locations": [
        {
            "id": "79b42f6d-bfa2-49e9-ab07-542359864877",
            "year": 2022,
            "jid": "5GB13D",
            "name": "Guildford",
            "owner": "d4db6e5d-b5a3-4e8c-b1a4-8fbbadda9b0d",
            "created": "2022-01-24 15:13:04"
        },
        {
            "id": "dd938fb3-dbdc-41f0-a93a-52ce7a65cd42",
            "year": 2022,
            "jid": "5GB25E",
            "name": "London",
            "owner": "d4db6e5d-b5a3-4e8c-b1a4-8fbbadda9b0d",
            "created": "2022-01-31 16:25:35"
        }
    ],
    "errorCode": null,
    "error": null
}

Users

Users can be created using the API:

POST /createUser
{
	"name": "Arthur Dent",
	"username": "adent",
	"password": "THGTTG-42"
}

Response will be similar to:

{
    "id": "13b579ee-fcb8-409b-83f3-e1ce96935276",
    "created": true,
    "token": "eyJhbGciOiJ...zdOUex7uEFQjf-Kw",
    "error": null,
    "errorCode": null
}

Once the user is create you can use the token returned from createUser or you can fetch a new token like this:

POST /login
{
	"username": "adent",
	"password": "THGTTG-42"
}

Response will be similar to:

{
    "successful": true,
    "token": "eyJhbGciOiJ...zdOUex7uEFQjf-Kw",
    "errorCode": null,
    "error": null
}

Send JID code

Users can send JID codes to the server by using the jid endpoint. The login token should be sent as value to the authorization header.

POST /jid
Authorization: eyJhbGciOiJ...zdOUex7uEFQjf-Kw
{
    "jid": "5dk17j"
}

Response will be similar to:

{
    "saved": true,
    "code": {
        "userid": "13b579ee-fcb8-409b-83f3-e1ce96935276",
        "jid": "5dk17j",
        "country": "dk",
        "created": "2019-10-18T16:26:50+02:00"
    },
    "errorCode": null,
    "error": null
}
Clone this wiki locally