[Python] How do I request a CSV of email activity from SendGrid without emailing our Admin?

Discussão em 'Python' iniciado por Stack, Maio 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am using the SendGrid v3 Email Activity API to request a CSV export of email activity. When I make a POST request to https://api.sendgrid.com/v3/messages/download, I receive a response saying the CSV will be emailed to the administrator of our SendGrid account.

    import os
    from sendgrid import SendGridAPIClient

    sg = SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
    response = sg.client.messages.download.post()
    print(response.body)


    Response

    {
    "status": "pending",
    "message": "An email will be sent to name_of_admin@example.com when the CSV is ready to download."
    }


    There's no link to the CSV in the API response. The only way I can find to download it is through a link emailed to the administrator. I plan on automating this export to run on a regular basis, so I would prefer not having to ask our admin to forward the CSV every time a new one is generated. SendGrid's documentation mentions an endpoint for downloading a CSV, but it requires a download_uuid that isn't in the response from the initial request.

    Is there a way to retrieve the generated CSV of email activity through the SendGrid API that doesn't require the admin to receive and forward an email?

    Continue reading...

Compartilhe esta Página