0

As a marketer, I'm going through the EmailOctopus (email service provider) API docs (https://emailoctopus.com/api-documentation) and have trouble combining multiple requests in one.

Goal: Get all campaign reports for all campaigns exported to a CSV.

Step 1: Get all campaign IDs. This works. curl GET https://emailoctopus.com/api/1.5/campaigns?api_key={APIKEY}

Step 2: Get the report for a single campaign. This works too. curl GET https://emailoctopus.com/api/1.5/campaigns/{CAMPAIGNID}/reports/summary?api_key={APIKEY}

Step 3: Combine step 1 and 2 and export to a CSV. No idea how to proceed here.

Output step 1:

{
    "data": [
        {
            "id": "00000000-0000-0000-0000-000000000000",
            "status": "SENT",
            "name": "Foo",
            "subject": "Bar",
            "to": [
                "00000000-0000-0000-0000-000000000001",
                "00000000-0000-0000-0000-000000000002"
            ],
            "from": {
                "name": "John Doe",
                "email_address": "john.doe@gmail.com"
            },
            "content": {
                "html": "<html>Foo Bar<html>",
                "plain_text": "Foo Bar"
            },
            "created_at": "2019-10-30T13:46:46+00:00",
            "sent_at": "2019-10-31T13:46:46+00:00"
        },
        {
            "id": "00000000-0000-0000-0000-000000000003",
            "status": "SENT",
            "name": "Bar",
            "subject": "Foo",
            "to": [
                "00000000-0000-0000-0000-000000000004",
                "00000000-0000-0000-0000-000000000005"
            ],
            "from": {
                "name": "Jane Doe",
                "email_address": "jane.doe@gmail.com"
            },
            "content": {
                "html": "<html>Bar Foo<html>",
                "plain_text": "Bar Foo"
            },
            "created_at": "2019-11-01T13:46:46+00:00",
            "sent_at": "2019-11-02T13:46:46+00:00"
        }
    ],
    "paging": {
        "next": null,
        "previous": null
    }
}

Output step 2:

{
    "id": "00000000-0000-0000-0000-000000000000",
    "sent": 200,
    "bounced": {
        "soft": 10,
        "hard": 5
    },
    "opened": {
        "total": 110,
        "unique": 85
    },
    "clicked": {
        "total": 70,
        "unique": 65
    },
    "complained": 50,
    "unsubscribed": 25
}

How can I get all campaign reports in one go and exported to a CSV?

Ruben Portz
  • 174
  • 1
  • 10
  • What language or tool you are using? please provide more explanation. What is your expected CSV output? Your JSON data seems to be objects with different schema (output 1 vs output 2) and you should provide also the columns of your CSV file – Ali Khalili Nov 04 '19 at 08:33

1 Answers1

1

May be this URLs be helpful Merging two json in PHP How to export to csv file a PHP Array with a button? https://www.kodingmadesimple.com/2016/12/convert-json-to-csv-php.html

  • Thanks Arash, I might need to make my question clearer. It's not just two outputs that need to get merged. The IDs I get from the first output, need to be used to run the API POST Request to obtain the second output. Do you have any directions on that? – Ruben Portz Nov 03 '19 at 14:18