How To View Api Key Sendgrid

SendGrid provides a robust email service on the cloud to fulfill your business’s email sending requirements. It’s essential to know the proper way to safeguard your API keys, as they are the means to authenticate with the SendGrid API.

In this tutorial, we will go over how to view your SendGrid API Key. However, keep in mind that for security reasons, SendGrid does not provide the ability to view an existing API Key. Instead, you will learn how to create and view a new API Key.

Prerequisites

The first thing you need is a SendGrid account. If you don’t have one, you can sign up for a free account here.

Viewing SendGrid API Key

Let’s dive into the steps:

Step 1: Navigate to the SendGrid dashboard

Sign in to your SendGrid account and navigate to the dashboard. From the left-hand side navigation, click on “Settings,” then select “API Keys.”

Step 2: Create a new API Key

Click on the button that says “Create API Key.” You will be prompted to give your new API key a name. Choose a name that is relevant and descriptive, like “Test API key.” Then, select the level of access for this key. For testing purposes, we recommend choosing “Full Access”.

Step 3: View the API Key

Once you have created your new API key, it will be displayed on the screen. Be sure to copy and save your key in a secure location because SendGrid will not display the key again for security reasons. If you lose access to your key, you will need to create a new one.

Example Code

Once you have your API key, you can use it to make calls to the SendGrid API. Below is an example code snippet in Python using the SendGrid library:

    import sendgrid
    from sendgrid.helpers.mail import Mail

    sg = sendgrid.SendGridAPIClient(api_key='YOUR_API_KEY')
    message = Mail(
        from_email='from_email@example.com',
        to_emails='to@example.com',
        subject='Sending with SendGrid is Fun',
        plain_text_content='and easy to do anywhere, even with Python')
    response = sg.send(message)
    print(response.status_code)
    print(response.body)
    print(response.headers)
    

Replace the string ‘YOUR_API_KEY’ with your newly created API Key.

Conclusion

And that’s it! You now understand how to view your SendGrid API key by creating a new one. Remember to keep your API keys secure and never share them publicly. Happy emailing!