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
- Open Postman
- Create a new Collection (e.g., “Mangrove Evidence Upload”)
- Inside the collection, click Add Request
2
Configure the Request
URL:Authorization tab:
- Set Type to
Bearer Token - Paste your Mangrove API token
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
- In Postman, open your Collection
- Click Run
- Upload
events.csvas the data file - Click Run