Campaign Report API

Campaign Report API lets you download campaign reports for any specific date range. You can fetch reports for one-time and periodic campaigns.

Downloading reports via API helps you in the following ways:

  • Provides structured data that can be integrated into your system directly.
  • Automate your report generation process by scheduling reports in regular intervals.
  • Enables you to efficiently manage large volumes of data and export to other systems.

The following are the steps involved in generating the reports through API:

  1. Configure reports
  2. Generate reports through API

Configure Reports

  1. On the left navigation menu in the MoEngage dashboard, click Engage, and then click Campaigns.
  2. Click Export in the header section and select Advanced, which allows you to generate reports for specific campaigns and channels through API.

    info

    Information

    If you select Basic as the option, then the report will not be fetched through API; Instead, the reports will be sent to your email ID.

  3. On the Export campaigns- create a report page, select the campaigns to be exported, and define the format and content of your report. For more information, refer to Advanced Reports.
  4. In step 3 (Scheduling and delivery) of campaign creation, select the time interval for generating the report.
  5. You can fetch reports one time and at periodic time intervals.
    • One time: 
      • As soon as possible: This option allows you to fetch reports instantly.
      • As specific date and time: This option allows you to fetch reports for any specific date and time.
    • Periodic time intervals: this option allows you to fetch reports on a daily, weekly, and monthly basis.
  6. In the Send report to section, click Rest API to download the report using the API. Using this method, you can generate campaign reports using API instead of receiving reports by email.0e1a284-CampaignReportBuilder.png

    info

    Note

    Ensure some buffer time from the scheduled time, as the reports are generated using the API. The generated report expires within seven days.

  7.  

Generate Reports Through API

API Endpoint

Method: GET
GET https://api-0X.moengage.com/campaign_reports/rest_api/[APP ID]/[FILENAME]

The 'X' in the API Endpoint URL refers to the MoEngage Data Center (DC). MoEngage manages different data centers for different clients. You can find your DC number (value of X) and replace the value of 'X' in the URL by referring to the DC and API endpoint mapping here.

Path Parameters

Parameter Description
WORKSPACE ID (APP ID)  WORKSPACE ID can be fetched from Settings > Account > APIs.
FILENAME

The file name is a combination of the report name, report generation date, and file format. For example, Report_test_20210217.zip

  • Report name: The report name is the same as the one defined in the Campaign Report Builder, with spaces replaced by underscores. For example, if the file name on the dashboard is Report test, then the file name for the API is Report_test.
  • Report generation date: The report generation date should be in YYYYMMDD format. For example, the name 20210217 contains the report generated on 17/02/2021.
  • File format: Compression format such as .zip
 
 
 
 

Request Headers

Generate a unique signature, passed as a GET parameter, to verify the caller's authenticity and the request's validity. The signature is a combination of the WORKSPACE ID (previously APP ID), FILENAME, and SECRET-KEY.

Generate Headers

The API request will be authenticated through Basic Authentication. Basic Authentication sends a Base64-encoded string containing your username and password with every API request. It encodes a 'username: password' string in Base64 and appends the encoded string with 'Basic '. This string is included in the authorization header as shown below:

{"Authorization": "Basic Base64_ENCODED_APPKEY_APIKEY"}

You can obtain the username and password details from the MoEngage UI.

  1. Navigate to Settings -> Account -> APIs.
  2. Copy the following details:
    • Username: Under Workspace ID (earlier app id), click the copy icon to copy the username.
    • Password: In the API keys section, click the copy icon in the Campaign report/Business events/Custom templates tile to copy the API key.
  3. Use these details to authenticate the API requests.
Key Sample value Description
Signature Headers: Signature:80300f554f9dc88cdc7d64c6c06f4de580b27a2afcc396816d1ec3a8d1c09579

A signature is a combination of API_ID + FILENAME + SECRET KEY 

Signature_Key = Api_ID + "|" + FILENAME + "|" + SECRET_KEY

Sample API

https://api-0X.moengage.com/campaign_reports/rest_api/<APP ID>/Report_-_test_20210217.zip Headers: Signature: 80300f554f9dc88cdc7d64c6c06f4de580b27a2afcc396816d1ec3a8d1c09579

Sample Signature Python

Python
# SAMPLE IMPLEMENTATION IN PYTHON
from hashlib import sha256
Api_ID = "YOUR-APP-ID"
FILENAME = "Report_-_test_20210217.zip"
SECRET_KEY = "YOUR-SECRET-KEY"
Signature_Key = Api_ID + "|" + FILENAME + "|" + SECRET_KEY
# Now Signature is hexdigest of sha256 of Signature_Key
Signature = sha256(Signature_Key.encode('utf-8')).hexdigest()

Response

Successful API requests automatically download the report file.
API request failure results in JSON Response explaining the reason for failure.

Response Code Content Type Response Description
200 application/gzip   Successful API request automatically downloads the report file.
400 application/json {
"error": {
"attribute": "",
"message": "error message",
"type": "BAD REQUEST",
"request_id": ""
}
}
Any of the following reasons:
1. Invalid Report file name/ file name format
2. Requested report if older than 7 days.
3. Incorrect App Id
401 application/json empty body Invalid Signature/Signature Missing

Import APIs 

We have made it easy for you to test the APIs. Click here to view it in Postman.

FAQs

1. Why am I not receiving any response for the selected date?

 Campaigns might not be available to run on the selected date to fetch the report, which could result in an error message.

2. Can I retrieve the report file whenever needed?

The reports generated will expire in 7 days from the date of creation.

3. What is the maximum number of days I can choose to generate reports?

You can generate reports for up to 90 days.

Previous

Next

Was this article helpful?
0 out of 7 found this helpful

How can we improve this article?