Objective
We provide X-Message-ID in the response header of a Mail Send API request as opposed to complete Message ID. X-Message-ID is specific to the API request prior to messages being broken up individually in SendGrid email servers and then assigned the SendGrid Message ID. The SendGrid Message ID accounts not only for the original request but also server data and the specific identification between a unique message and recipient. If you only have the X-Message-ID from your Mail Send API response header and no access to the SendGrid console or Event Webhook, then you may wish to use the Activity Feed API to filter the results based on X-Message-ID. This document should be used along with our existing API documentation on Activity Feed API.
Product
Email Activity Feed API
User Account Permission/Role(s) Required
We recommend using an API with full access to make the Activity Feed API call. If that is not feasible, check these articles to find out what permissions are required to use this endpoint:
Types of API keys
Teammate permissions (if you are not an admin).
In order to gain access to the Email Activity Feed API, you must purchase additional email activity history. Once purchased, you must also update your existing API key(s) to have Email Activity access or create a new API key with Email Activity access.
Procedure
Encoding Query
The query to be used in the Email Activity API URL for filtering on the basis of X-Message-ID would be:
query=msg_id LIKE '<X-Message-ID>%'
For instance, the X-Message-ID is 'Ua9z9lSTSaqYBWJe_Xfc-Q', then the query would be:
query=msg_id LIKE 'Ua9z9lSTSaqYBWJe_Xfc-Q%'
Since, the query will be used in the API URL endpoint as a query parameter, it needs to be URL encoded.
Encoding the query as per below table:
space | %20 |
% | %25 |
' | %27 |
Encoded query will look like:
query=msg_id%20LIKE%20%27<X-Message-ID>%25%27
For instance, the X-Message-ID is 'Ua9z9lSTSaqYBWJe_Xfc-Q', then the query would be:
query=msg_id%20LIKE%20%27Ua9z9lSTSaqYBWJe_Xfc-Q%25%27
Once the query is encoded, you can make the Email Activity Feed API call as follows:
- Method: GET
- URL: https://api.sendgrid.com/v3/messages?query=msg_id%20LIKE%20%27<X-Message-ID>%25%27
- Headers:
- Authorization: Bearer <<your API key>>
Additional Information