Last updated: 2024-07-31

internal documents

Applies from: Opter 2023.12.203

Retrieve statistical data via API

You can create statistical reports in the following different ways:

The statistics API works like this

Step 1: Planera

The steps below provide instructions on how to use the statistics API, but we recommend that you do the following first:

  1. Decide what you want to achieve, i.e. what do you want to get out and why.

  2. Decide how often the statistical data will be retrieved from Opter.

    For example, if you want to present the statistics on a dashboard, you may want to retrieve the statistics data once every hour. If you want to use the statistics for follow-up at the end of each day, you can download the statistical data at the end of each day.

  3. Decide who will have access to the statistics API. Anyone who accesses the statistics API will have access to all data, including information on customers, prices, invoices, etc.

Tip

Step 2: Create an API key

Note:

Anyone who accesses the statistics API will have access to all data, including information on customers, prices, invoices, etc. There is no way to restrict access (for example, to exclude information on prices).

The user of the statistics API needs an API key. Proceed as follows:

  1. Click on Settings > API access (and the tab General).

  2. To create a new user, click on and enter Name.

    The API key field displays the API key that has been created.

  3. In the Description field, you can describe what the user will have access to.

  4. Click on the Access tab.

  5. Double-click on Statistics in the Excluded list and Statistics will be moved to the Included list.

    This means that the user can access all statistical data in Opter via the statistics API, using the API key.

  6. Click on to save all changes.

Step 3: Go to the swagger documentation

  1. The Swagger documentation for the statistics API can be found at the same URL as the customer web, but with "/api" at the end:

    • If you are running Opter Cloud:

      https://<ert företagsnamn>.opter.cloud/api/index.html

      Example: If your company name in Opter is "budfirman" and the country is Sweden, use https://budfirmanse.opter.cloud/api/index.html

    • If you have your own server:

      https://<your company name or IP address>.<country>/api/index.html

      Example: If your company name in Opter is "budfirman" and the country is Sweden, you use

      https://budfirman.se/api/index.html eller 123.45.678.901/api/index.html

    If you cannot find the swagger documentation for the statistics API, please contact the EDI team at .

  2. In the top right-hand corner of the website, there is a drop-down menu Select a definition. Select "Opter API v1".

Using the data model (optional)

If you want to import the API into a tool such as Postman, you can find the data model for the API at the top of the swagger webpage.

Try using the API (optional)

If you want to test using the API, you can do so on the swagger website or use a test programme such as Postman.

If you want to try calling the statistics API on the swagger website and see the results, do this:

  1. In the top right-hand corner of the website, there is a drop-down menu Select a definition. Select "Opter API v1" from the drop-down menu.

  2. Click on Authorize. Copy the API key from the API access window in Opter, paste it into the Value field and click Authorize. Now it says Authorized in the window. Click on Close.

    (You created the API key in Step 2: Create an API key above.)

  3. Scroll down to Statistics and click on GET.

    All parameters ("queries") are displayed.

  4. Click on the Try it out button.

  5. Select dateType (mandatory) from the drop-down menu. The meaning of the different choices is shown in the table Selecting the type of date on which to base the statistical data below.

  6. Select the period for which you want the statistical data by choosing dateFrom (mandatory) and dateTo (mandatory).

    Dates are written in the format "yyyy-mm-dd", for example "2024-08-19". If you want to enter both the date and the time, type a space between the date and the time, for example "2024-08-19 13:30".

    If you only enter the date, the default time is 00:00.

  7. Choose which statistical data you want by selecting "true" in the drop-down list for those parameters. For example, includeDeliveries and includeScans.

    (The default setting is "false", which means you only need to select "true" for the parameters you want to include in the statistics data.)

    Tip

    Details on what data is retrieved if you select "true" for, for example, includeDeliveries and includeScans are shown further down the swagger documentation under Schemas. Click on Statistics.Delivery and Statistics.Scan. Click on "[...]" to see more details.

  8. In the api-version field, you can choose to enter a specific version or leave the field blank if you want the latest version of the API to be used. For example, if you want to use a specific version, type "1.0" in the field.

  9. Click on the Execute button to send the API call. The results are available at Responses.

    Under Server response the result/response is displayed in JSON format. Click on the button Download to download the JSON file.

    Tip

    If you want to test the same API call in, for example, the Postman tool, you can copy the API call shown in the code window Curl.

  10. If you want to test again (for example with other parameters), click on Clear next to Execute to clear under Responses. You can then call the API again by clicking on Execute and view the results.

Select the type of date on which the statistical data will be based

When calling the Statistics API, use the parameters dateFrom (from date and time) and dateTo (to date and time) to select the period for which the statistical data should be retrieved.

You use the parameter dateType to select the type of date on which the statistical data will be based as shown in the table below.

dateType Description
TransportDate

Based on orders where Order date matches the date range. All information about those orders can be included, including invoices, scans, etc. outside the date period.

ScanDate

Based on scan lines (parcel scans or consignment note scans). All information on the orders that have scans in the selected period can be included, regardless of the order date of the orders, the invoice date of the invoices, etc.

Invoices and settlements will not necessarily be complete, only those orders that have scans in the period will be included.

Tip

In the parameters dateFrom and dateTo it may be relevant to specify both date and time. See example below.

InvoiceDate

Based on invoices where the invoice date matches the date period. All information about orders included on the invoices can be included. This applies even if it is just an additional invoice on the order (a new item or a credit note, for example).

Orders that are not on an invoice that matches the period will not be included, regardless of the order date, scan date, etc.

BillDate

Based on settlements where the settlement date matches the date period in the same way as above.

ChangeDate

Retrieves data on which orders have changed during the period.

This does not only apply to changes made by opening the order, making changes and then saving it. This also applies to changes made to traffic management and apps, for example:

  • If a driver changes the status from Picked up to Delivered in the Opter Driver app, the statistics will show that the order has changed.

  • If you change the status in the traffic management or connect to co-loading, the statistics will show that the order has changed.

Tip

In the parameters dateFrom and dateTo it may be relevant to specify both date and time. See example below.

For an order that has been modified during the period, the date and time when the order was last modified (during the period) is displayed.

Tip

You can see some more information about changes to the orders by looking at the logs in the Order log box in the order reception in Opter.

Restrictions

Example

Statistics on which orders have been changed

If you want to retrieve data on the following:

Select "ChangeDate" from the drop-down menu dateType. (For more information, see the table above, see ChangeDate.)

Select "true" from the drop-down menu includeDeliveries.

Tip

Details on what data is retrieved if you select "true" for includeDeliveries are shown further down the swagger documentation under Schemas. Click on Statistics.Delivery and then on "[...]" to see more details. For orders that have changed during the period:

Troubleshooting


See also

Statistical reports

Climate impact of CO2 emissions in grams, pricing weight