Skip to content

Storing Data on the UP CARE Platform via REST API

This guide explains how to upload data to the UP CARE platform in two formats: wide format (for grouped data) and long/tall format (for time-series data). Follow the instructions below to use the API endpoints for uploading data.


1. Uploading Data to the Wide Format Database

In this format, multiple data points (such as measurements) are uploaded together for a specific source and time.

API Endpoint:
POST https://sync.upcare.ph/api/data/<database name>?organization=<your organization id>
Sample Request in Python:
import requests

# API URL with placeholders for your database and organization ID
url = "https://sync.upcare.ph/api/data/<database name>?organization=<your organization id>"

# Data payload in wide format
payload = {
    "topic": "<any topic, preferably topics assigned to your group>",
    "data": [
        {
            "source": "<source of data, i.e., device id>",
            "local_time": "2024-10-09 05:00:01",
            # Example data - you can add multiple key-value pairs as required
            # "PM2.5": "20.1",
        }
    ]
}

# Headers including authorization token
headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "authorization": "Basic <Basic auth token based on your credentials>"
}

# Sending the POST request
response = requests.post(url, json=payload, headers=headers)

# Response from the API
print(response.text)
Explanation of Fields:
  • url: Replace <database name> with the actual name of your database and <your organization id> with your organization's ID.
  • payload:
  • topic: A string representing the topic of the data (preferably a topic assigned to your group).
  • data: An array containing the data, where each entry includes:
    • source: The origin of the data (e.g., device ID).
    • local_time: The timestamp in YYYY-MM-DD HH:MM:SS format.
    • Any other key-value pairs representing the measurements.
  • headers: Include the authorization key with your Basic Auth token for API access.

2. Uploading Data to the Long/Tall Format Database

In this format, each measurement is uploaded individually, typically used for time-series data.

API Endpoint:
POST https://sync.upcare.ph/api/measurement/<database name>?organization=<your organization id>
Sample Request Body:
{
  "topic": "UPCARE/TEST",
  "data": [
    {
      "source": "00001b39",
      "local_time": "2024-08-10 08:00:00",
      "type": "SEN55_MassPM10",
      "value": 25.5
    }
  ]
}
Explanation of Fields:
  • url: Replace <database name> with the actual database name and <your organization id> with your organization's ID.
  • payload:
  • topic: Topic of the data (use a relevant topic).
  • data: An array containing each measurement:
    • source: The origin of the data (e.g., device ID).
    • local_time: Timestamp in YYYY-MM-DD HH:MM:SS format.
    • type: Type of the measurement (e.g., sensor type).
    • value: The value of the measurement.

3. Authentication and Headers

  • For both formats, include Basic Authentication in the request headers using your credentials.
  • Ensure the content-type is set to application/json and the accept header is set to application/json.

4. Handling API Responses

The response from the API will return a status code and message. For successful uploads, you will typically receive a 200 OK response.

Example:

{
  "message": "Data successfully uploaded."
}

In case of errors, ensure to check the response for any error messages to correct the request.


5. Additional Information

For more details on the API endpoints and their functionality, check out:

POST /data/{db}
POST /measurement/{db}

Refer to these endpoints in the documentation of the CARE REST API for comprehensive information on parameters, error handling, and other options.