Skip to main content
This cookbook explains how to upload an evidence file to multiple Mangrove events using the API.

Example Scenario

You have a single evidence file (e.g., a meter reading export) that needs to be attached to multiple events in your Mangrove project. Instead of uploading manually to each event, you can automate this by iterating over your event IDs and calling the API.

Uploading Evidence with Code

1

Prerequisites

Before starting, make sure you have:
  • A Mangrove API token with Data Collection permissions (read and write access)
  • A list of event IDs you want to attach evidence to
  • Your evidence files
  • You can use a tool like Postman to make the API calls.
2

Convert Evidence File to the right format

The API accepts evidence files as base64-encoded strings.Open Terminal and run:
This converts your file into base64 and copies it to your clipboard.
3

Upload to a Single Event

Use the Create evidence on event endpoint to attach evidence to each event.Here’s an example request to upload evidence to one event:
curl
4

Upload to Multiple Events

To upload to multiple events, iterate over your list of event IDs. Here are examples in different languages:
If you’re attaching the same file to multiple events, encode it once and reuse the base64 string for each request.

Using Postman

You can also use Postman’s Collection Runner to upload evidence to multiple events without writing code.
1

Create a Collection and Request

  1. Open Postman
  2. Create a new Collection (e.g., “Mangrove Evidence Upload”)
  3. Inside the collection, click Add Request
2

Configure the Request

URL:
Authorization tab:
  • Set Type to Bearer Token
  • Paste your Mangrove API token
Headers tab:Body tab:
  • Select raw and set format to JSON
  • Paste the following:
The {{event_id}}, {{file_name}}, and {{file_base64}} variables will be populated from your CSV file.
3

Convert Evidence File to Base64

Open Terminal (macOS) and run:
This converts your file to base64 and copies it to your clipboard.
4

Prepare the Runner Data File

Create a file called events.csv with these columns:
Example
If attaching the same file to multiple events, reuse the same base64 value across rows.
5

Run the Collection

  1. In Postman, open your Collection
  2. Click Run
  3. Upload events.csv as the data file
  4. Click Run
Postman will send one request per row in your CSV file. The number of successful responses should match the number of rows.