Blog

Introducing Provisioning API And Detailed Usage Reporting

Today we’ve introduced a brand new provisioning API that allows Enterprise customers to convinently manage API keys for their clients, apps and websites. Along with the new API additions we’re now also exposing detailed usage statistics on per API-key basis available from API endpoints and Optidash Account interface.

Usage resporting in the Optidash Account

Chances are that not all the members of your organization are technical people who can programmaticaly query our endpoints and get usage statistics per API key. For individuals usually operating in the browser we redesigned the “API Keys” view in the Optidash Account.

We now have a “Manage” menu in the API Keys list. The pretty self-explanatory “Show usage” entry is where usage statistics can be found. A pair of simple date-pickers allows for fine tuning the time range while the bottom section shows cumulative usage for the selected date range (individual requests and input volume in GBs).

Here’s a quick screencast demostrating how this brand new UI behaves works:

Provisioning API

We now have a new /1.0/keys endpoint built specifically for API Keys management. You can add, modify and get API keys and their respective usage. Important note: requests to that endpoint must be authenticated only with the master (primary API key).

POST /1.0/keys — add new API key

Expected name parameter is a unique name of the new API key, for example:

{
    "name": "my awesome key"
}

Example cURL request:

curl -X POST https://api.optidash.ai/1.0/keys -u MASTER_API_KEY: \
-H "Content-Type: application/json" \
-d '{
    "name": "my awesome key"
}'

The API will respond with 200 OK and the following data:

{
    "success": true,
    "name": "my awesome key",
    "key": "0UASk8hgjwSq1XetiVPLNyltNPvqJKAmBP8209Qn"
}

PUT /1.0/keys/:key — edit existing API key

This endpoint is used to change the name of an existing API key and expects a unique new name of the API key:

{
    "name": "better name"
}

Example cURL request:

curl -X POST https://api.optidash.ai/1.0/keys/API_KEY_TO_UPDATE -u MASTER_API_KEY: \
-H "Content-Type: application/json" \
-d '{
    "name":"better name"
}'

The API will respond with 200 OK and the following data:

{
    "success": true,
    "name": "better name",
    "key": "0UASk8hgjwSq1XetiVPLNyltNPvqJKAmBP8209Qn"
}

GET /1.0/keys/:key — get usage by API Key

This endpoint is used to query historical usage per API Key (defaults to last 90 days).

Example cURL request:

curl -X GET https://api.optidash.ai/1.0/keys/API_KEY -u MASTER_API_KEY:

The API will respond with 200 OK and the following data:

{
    "success": true,
    "results": [{
        "bucket": "2021-01-25T00:00:00.000Z",
        "volume": 0,
        "count": 0
    },
    {
        "bucket": "2021-01-26T00:00:00.000Z",
        "volume": 109500190,
        "count": 3333
    },
    {
        "bucket": "2021-01-27T00:00:00.000Z",
        "volume": 269640216,
        "count": 8994
    }
    ...
    ]
}

The GET /1.0/keys/:key endpoint also accepts three additional query parameters: from, to, and interval.

The first two control the date/time range (in ISO-8601 format) while the latter controls the granularity of the results. All requests to the /1.0/keys/:id endpoint must be authenticated with master (primary) API key.

Granularity (interval) defaults to day (if interval parameter is omitted) and accepts the following values: minute, hour, day, week, and month.

With great power comes great responsibitly and granularity should be used wisely - if one queries for a maximum time range (90 days) and sets the interval to minute, the API will respond with 131487 time buckets.

Here’s an example cURL query that responds to: “give me all usage data for the API key USER_API_KEY from 2021-01-19T00:00:00 to 2021-01-28T23:59:59 with hourly granularity”

curl -X GET https://api.optidash.ai/1.0/keys/USER_API_KEY?interval=hour&from=2021-01-19T00:00:00&to=2021-01-28T23:59:59 -u MASTER_API_KEY:

Example response:

{
    "success": true,
    "results": [
        {
            "bucket": "2021-01-19T00:00:00.000Z",
            "volume": 51253,
            "count": 1
        },
        {
            "bucket": "2021-01-19T01:00:00.000Z",
            "volume": 0,
            "count": 0
        },
        {
            "bucket": "2021-01-19T02:00:00.000Z",
            "volume": 252849,
            "count": 3
        },
        ...
    ]
}

Should you have questions about the provisioning API or requests for other features do not hesitate to contact us anytime.

Ready to try Optidash?

Start optimizing your images smarter. Integrate in minutes.

Create Free Account Get In Touch

This website uses cookiesBy using Optidash, you agree to our Cookie Policy.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.