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:
base64 -i path/to/your/file.csv | pbcopy
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
curl -X POST "https://app.gomangrove.com/api/v1/events/evt_abc123/evidence" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "evidences": [
      {
        "type": "file",
        "data": {
          "file": {
            "name": "meter_readings.csv",
            "type": "text/csv",
            "base64": "YOUR_BASE64_STRING"
          }
        }
      }
    ]
  }'
4

Upload to Multiple Events

To upload to multiple events, iterate over your list of event IDs. Here are examples in different languages:
#!/bin/bash
API_TOKEN="YOUR_API_TOKEN"
FILE_BASE64=$(base64 -i evidence.csv)
EVENT_IDS=("evt_001" "evt_002" "evt_003")

for EVENT_ID in "${EVENT_IDS[@]}"; do
  curl -X POST "https://app.gomangrove.com/api/v1/events/${EVENT_ID}/evidence" \
    -H "Authorization: Bearer $API_TOKEN" \
    -H "Content-Type: application/json" \
    -d "{
      \"evidences\": [{
        \"type\": \"file\",
        \"data\": {
          \"file\": {
            \"name\": \"evidence.csv\",
            \"type\": \"text/csv\",
            \"base64\": \"$FILE_BASE64\"
          }
        }
      }]
    }"
  echo "Uploaded to $EVENT_ID"
done
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:
POST https://app.gomangrove.com/api/v1/events/{{event_id}}/evidence
Authorization tab:
  • Set Type to Bearer Token
  • Paste your Mangrove API token
Headers tab:
KeyValue
Content-Typeapplication/json
Body tab:
  • Select raw and set format to JSON
  • Paste the following:
{
  "evidences": [
    {
      "type": "file",
      "data": {
        "file": {
          "name": "{{file_name}}",
          "type": "text/csv",
          "base64": "{{file_base64}}"
        }
      }
    }
  ]
}
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:
base64 -i path/to/your/file.csv | pbcopy
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:
ColumnDescription
event_idThe event ID to attach evidence to
file_nameFile name displayed in Mangrove
file_base64Base64 string of your evidence file
Example
event_id,file_name,file_base64
evt_001,evidence.csv,AAAABBBB...
evt_002,evidence.csv,AAAABBBB...
evt_003,evidence.csv,AAAABBBB...
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.