Main Content

Write Image

Write channel image with HTTP POST

Request

HTTP Method

POST

URL

https://data.thingspeak.com/channels/<channel_id>/images/<filename>/<timestamp>

URL Parameters

NameDescription

<channel_id>

(Required) Channel ID for the image channel to write to.

<filename>(Optional) Name of the image file.
<timestamp>(Optional) Timestamp provided by the client.

Example:https://data.thingspeak.com/channels/123456/images/MVseg_01.jpg/2022-01-29T15:06:35.642Z

Body

The body of the POST is the image data. The means of specifying the file depends on the utility.

Headers

The following headers are required for an image POST request.

Key NameValue
Content-type

(Required) image/jpeg

thingspeak-image-channel-api-key

(Required) The API Key for this specific image channel. The Write API Key is found in the API Keys column of the image channels table.

Response

Success

HTTP Status Code

202 OK

JSON Response

The response is a JSON object of the new entry, for example:

{
    "requestID": "cmnog8kdd00224cmc4cz0dnwo",
    "code": 0,
    "status": "PENDING",
    "message": null
}

Errors

For the full list, see Error Codes.

Limitations

  • You must have a paid licence to create an image channel.

  • The only supported image format is JPEG/JPG.

  • Images are limited in size to 5 MB. Those slightly larger are automatically scaled down. Significantly larger images are rejected.

  • All timestamps must be unique within a channel. You cannot write a new image using a timestamp that matches the timestamp of an existing image in the channel.

Examples

expand all

The following code operates in a Linux® shell. Change the channel ID, API Key, and filename as appropriate.

curl --location --request POST "https://data.thingspeak.com/channels/95b0766f76/images" \
--header "Content-Type: image/jpeg" \
--header "thingspeak-image-channel-api-key: M3I17NS05QKZ6Q5D" \
--data-binary "./MyImage44.jpg"

The raw response is:

{"requestID":"cl2t7ybd40ppo07k7fo2lbi83","code":0,"status":"PENDING"}

You can use Postman to try out your HTTP requests using the RESTful API for ThingSpeak. This example shows how to write data to a channel using Postman.

  1. In Postman, select POST from the drop-down list of HTTP verbs.

  2. Enter https://data.thingspeak.com/channels/<channel_id>/images in the address field, replacing <channel_id> with the ID of the channel you are writing the image to.

  3. Under the Headers tab, enter the following parameter keys:

    • Content-type with the value image/jpeg.

    • thingspeak-image-channel-api-key with the value from your image channel API Key, which is available in the ThingSpeak™ Channels > My Image Channels listing.

    Postman image post headers

  4. Under the Body tab select binary, then click Select File to browse for the image file with the file explorer.

    Postman image post body

  5. Click Send to POST your image. The response is a JSON object with request ID, code, and status; and a 202 Accepted from the server.

    Postman image post response