API Keys | SendGrid Docs (2024)

(warning)

Warning

Twilio SendGrid API keys are 69 characters long. We are unable to make exceptions for third-party infrastructure that is unable to support a key of 69 characters.

Your application, mail client, or website can all use API (Application Programming Interface) keys to authenticate access to SendGrid services. They are the preferred alternative to using a username and password because you can revoke an API key at any time without having to change your username and password. We suggest that you use API keys for connecting to all of SendGrid's services.

Types of API keys

types-of-api-keys page anchor

There are 3 different types of API keys:

  1. Full Access allows the API key to access GET, PATCH, PUT, DELETE and POST endpoints for all parts of your account, excluding billing and Email Address Validation.
  2. Restricted Access customizes levels of access for all parts of your account, excluding billing and Email Address Validation.
  3. Billing Access allows the API key to access billing endpoints for the account.

API key permissions

api-key-permissions page anchor

During the API key creation process, you will be given the option of selecting scopes, or specific permissions, that you would like to assign to your new API key. These permissions restrict which areas of your account your API key will be able to access.When assigning permissions to your API key, you will be given the option to select one of the following levels of access:

  • No Access prevents the API key from accessing any endpoint within the selected permission.
  • Read Access allows the API key to access GET endpoints within the selected permission.
  • Full Access allows the API key to access GET, PATCH, PUT, DELETE, and POST endpoints within the selected permission.

We require that you create a separate API key for making billing-related API calls. This segmentation adds an extra level of security by giving you more control over who has access to the various areas of your account.

Managing API keys

managing-api-keys page anchor

When viewing the API keys page, you will see a list of your current API keys along with the following information:

Name - The name you defined for your API key.

API Key ID - The way you would reference your API key for management through the API (e.g. editing or deleting a key).

Action - Actions you can perform on your API keys, such as editing or deleting the key.

Creating an API key

creating-an-api-key page anchor

  1. Navigate to Settings on the left navigation bar, and then select API Keys.
  2. Click Create API Key.
  3. Give your API key a name.
  4. Select Full Access, Restricted Access, or Billing Access.
  5. If you're selecting Restricted Access, or Billing Access, select the specific permissions to give each category. For more information, see API key permissions.
  6. Click Create & View.
  7. Copy your API key somewhere safe. For security reasons, do not put it directly in your code, or commit it somewhere public like GitHub.

(warning)

Warning

You will only be shown your API key one time. Please store it somewhere safe as we will not be able to retrieve or restore it.

There is a limit of 100 API Keys per account.

Storing an API key in an environment variable

storing-an-api-key-in-an-environment-variable page anchor

Twilio SendGrid recommends storing your API key in an environment variable or a config file that is not stored in version control.

When setting a variable in your program, that variable is readable by any person or system that can access the text file where it's set. However, a variable that's confined to the environment where the code is executed, stored outside the program itself, is called an environment variable. Only people and programs with access to the environment can read the value assigned to an environment variable. This makes environment variables a more secure choice for storing credentials such as API keys.

Once you assign your API key to an environment variable, you can then tell your program to look for and use that variable. Another benefit of this approach is the ability to set API keys with different permissions in different environments such as development, staging, and production without changing the code you deploy to those environments.

The examples below show how to store your key in a variable named SENDGRID_API_KEY. You can find additional examples in the Twilio Documentation.

To store your SendGrid API key, open your terminal or command prompt and add the following:

export SENDGRID_API_KEY=the_key_you_copied_from_SendGrid

setx SENDGRID_API_KEY the_key_you_copied_from_SendGrid

To then access the variable, you can use the convention provided by your coding language.

var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");

apiKey := os.Getenv("SENDGRID_API_KEY")

apiKey = System.getenv("SENDGRID_API_KEY");

const apiKey = process.env.SENDGRID_API_KEY;

$apiKey = getenv('SENDGRID_API_KEY');

api_key = os.environ.get('SENDGRID_API_KEY')

api_key = ENV['SENDGRID_API_KEY']

Editing an API key

editing-an-api-key page anchor

Click the action menu in the same row as the key you would like to edit. From here you can delete a key, making it completely inactive, or you can edit your key's name and permissions.

Deleting an API key

deleting-an-api-key page anchor

(warning)

Warning

Once you delete a key, it can no longer be used to access SendGrid's services.

Click the action menu in the same row as the key you want to delete. Select Delete. This will delete the key permanently, making it inactive. SendGrid will reject any subsequent API calls using this deleted API key.

Replacing an old API key with a new one

replacing-an-old-api-key-with-a-new-one page anchor

  1. Locate the API key you would like to replace in your list of keys and select the action menu drop down at the right on the same row, then select Delete API key.
  2. Next, create an API key.
  3. Replace the old API key with the new one in your code.

You may not give an API key greater permissions than you currently have.

Testing an API key

testing-an-api-key page anchor

You can test your newly created API key using cURL:

1

curl -i --request POST \

2

--url https://api.sendgrid.com/v3/mail/send \

3

--header 'Authorization: Bearer YOUR_API_KEY_HERE' \

4

--header 'Content-Type: application/json' \

5

--data '{"personalizations": [{"to": [{"email": "[email protected]"}]}],"from": {"email": "[email protected]"},"subject": "Hello, World!","content": [{"type": "text/plain", "value": "Howdy!"}]}'

Look for a 202 Accepted in the HTTP response headers.

Do you want expert help to get your email program started on the right foot?

Save time and feel confident you are set up for long-term success with Email Implementation. Our experts will work as an extension of your team to ensure your email program is correctly set up and delivering value for your business.

API Keys | SendGrid Docs (2024)
Top Articles
What is a Keystore/JSON file? Can I Change my Password?
Warehouse Considerations — Snowflake Documentation
Srtc Tifton Ga
Umbc Baseball Camp
Best Pizza Novato
Tesla Supercharger La Crosse Photos
Wisconsin Women's Volleyball Team Leaked Pictures
Koordinaten w43/b14 mit Umrechner in alle Koordinatensysteme
Southeast Iowa Buy Sell Trade
When is streaming illegal? What you need to know about pirated content
Arrests reported by Yuba County Sheriff
Craigslist In Fredericksburg
2021 Tesla Model 3 Standard Range Pl electric for sale - Portland, OR - craigslist
Caresha Please Discount Code
6th gen chevy camaro forumCamaro ZL1 Z28 SS LT Camaro forums, news, blog, reviews, wallpapers, pricing – Camaro5.com
Best Fare Finder Avanti
How Much Is Tj Maxx Starting Pay
Sony E 18-200mm F3.5-6.3 OSS LE Review
Mary Kay Lipstick Conversion Chart PDF Form - FormsPal
Morgan And Nay Funeral Home Obituaries
Violent Night Showtimes Near Amc Fashion Valley 18
Nick Pulos Height, Age, Net Worth, Girlfriend, Stunt Actor
Village
Low Tide In Twilight Ch 52
Accuradio Unblocked
Dr Seuss Star Bellied Sneetches Pdf
Free T33N Leaks
A Man Called Otto Showtimes Near Carolina Mall Cinema
Why comparing against exchange rates from Google is wrong
FREE Houses! All You Have to Do Is Move Them. - CIRCA Old Houses
J&R Cycle Villa Park
Rogold Extension
Wisconsin Volleyball Team Leaked Uncovered
Boondock Eddie's Menu
Helloid Worthington Login
How To Paint Dinos In Ark
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
303-615-0055
Energy Management and Control System Expert (f/m/d) for Battery Storage Systems | StudySmarter - Talents
Courses In Touch
Guided Practice Activities 5B-1 Answers
Rs3 Nature Spirit Quick Guide
Garland County Mugshots Today
Gary Vandenheuvel Net Worth
Europa Universalis 4: Army Composition Guide
552 Bus Schedule To Atlantic City
What Is The Gcf Of 44J5K4 And 121J2K6
The Significance Of The Haitian Revolution Was That It Weegy
Cool Math Games Bucketball
Loss Payee And Lienholder Addresses And Contact Information Updated Daily Free List Bank Of America
Elizabethtown Mesothelioma Legal Question
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated:

Views: 5779

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.