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
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.
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.
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
Using Postman
You can also use Postman’s Collection Runner to upload evidence to multiple events without writing code.Create a Collection and Request
- Open Postman
- Create a new Collection (e.g., “Mangrove Evidence Upload”)
- Inside the collection, click Add Request
Configure the Request
URL:Authorization tab:
Body tab:
- Set Type to
Bearer Token - Paste your Mangrove API token
| Key | Value |
|---|---|
| Content-Type | application/json |
- 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.Convert Evidence File to Base64
Open Terminal (macOS) and run:This converts your file to base64 and copies it to your clipboard.
Prepare the Runner Data File
Create a file called
events.csv with these columns:| Column | Description |
|---|---|
| event_id | The event ID to attach evidence to |
| file_name | File name displayed in Mangrove |
| file_base64 | Base64 string of your evidence file |
Example
If attaching the same file to multiple events, reuse the same base64 value across rows.