Skip to content

Admin API

Khor Philemon edited this page Aug 31, 2020 · 1 revision

Update data (COVID-19)

As the functionality of knowyourzone.xyz relies on the availability and up-to-dateness of the underlying data, we have to ensure the robustness of the site's data updating mechanism.

This endpoint allows us to update the site's underlying data manually in the event of failed automated data update. A successful request will replace the data stored in the application's cache and a new index.html will be re-rendered with the new data. (See the application data update flow here)

PUT https://knowyourzone.xyz/api/admin/covid19

Authentication

To use this endpoint, you must pass an API key with your request. The API key is a secret key used to authenticate requests made by site administrators. Requests with an incorrect API key or without an API key will return an Unauthorized error.

Well, at this point you should probably realize that this endpoint is not for you unless you own knowyourzone.xyz's API key. However, the following documentation might be useful for you if you are redeploying this project as your own website/service. As your site's administrator, you will need to configure the API key in the .env file as mentioned in the configuration guidelines.

Rate limit

100 requests per 15-minute window.

See the rate limit documentation for details on determining your current rate limit status.

Parameters

Field Type Description
states array Required. This array must contain at least 1 state object.

A state object encapsulates the data of a state.

Field Type Description
name string Required. The name of the state or federal territory.
total integer Required. The number of total active COVID-19 cases in the corresponding state. It should be the sum of active cases in all districts, excluding import cases.
districts array Required. This array must contain at least 1 district object.

A district object encapsulates the data of a district that belongs to the parent state object.

Field Type Description
name string Required. The name of the district.
total integer Required. The number of total active COVID-19 cases in the corresponding district.

Example Request

Make sure to replace <your API key> with a valid API key.

curl -X PUT https://knowyourzone.xyz/api/admin/covid19 \
  -H 'X-API-KEY: <your API key>' \
  -H 'Content-Type: application/json' \
  -d '{"states": [{"name": "At least one state object", "total": 1, "districts": [{"name": "At least one district object", "total": 1}]}]}'

Example Response

If successful, this endpoint returns a 200 with the following response body. The states field shows the latest data while the last_updated field indicates the timestamp at which the data is updated.

{
  "states": [
    {
      "name": "At least one state object",
      "total": 1,
      "districts": [
        {
          "name": "At least one district object",
          "total": 1
        }
      ]
    }
  ],
  "last_updated": 1594785600
}

If the request is unsuccessful, an appropriate status code will be returned with the following response body that gives you a more descriptive error message:

{
  "message": "A descriptive error message"
}