### List IPs for a customer account (JavaScript and Python) Source: https://www.twilio.com/docs/sendgrid/api-reference/account-ip-provisioning-api-ip-operations/list-ips Lists all IPs for a customer account using the SendGrid v3 API. The JavaScript example uses the @sendgrid/client package with a GET request to `/v3/partners/accounts/${accountID}/ips` and a query parameter `limit: 10`. The Python example uses the sendgrid package with `sg.client.partners.accounts._(accountID).ips.get(query_params=params)` and prints the status code, body, and headers. ```javascript const client = require("@sendgrid/client"); client.setApiKey(process.env.SENDGRID_API_KEY); const accountID = "accountID"; const queryParams = { limit: 10 }; const request = { url: `/v3/partners/accounts/${accountID}/ips`, method: "GET", qs: queryParams, }; client .request(request) .then(([response, body]) => { console.log(response.statusCode); console.log(response.body); }) .catch((error) => { console.error(error); }); ``` ```python import os from sendgrid import SendGridAPIClient sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY")) accountID = "accountID" params = {"limit": 10} response = sg.client.partners.accounts._(accountID).ips.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) ``` -------------------------------- ### Example Parse Setting Response Source: https://www.twilio.com/docs/sendgrid/api-reference/settings-inbound-parse/retrieve-a-specific-parse-setting.md The response body for a successful GET request to `/v3/user/webhooks/parse/settings/{hostname}`. The example shows a parse setting with `url`, `hostname`, `spam_check`, and `send_raw` fields. ```json ```json { "example": { "url": "http://mydomain.com/parse", "hostname": "mail.mydomain.com", "spam_check": true, "send_raw": true } } ``` ``` -------------------------------- ### Response Example for Update API Key Source: https://www.twilio.com/docs/sendgrid/api-reference/api-keys/update-api-key-name-and-scopes Example response body showing the updated API key with its ID, name, and scopes. ```JSON { "api_key_id": "qfTQ6KG0QBiwWdJ0-pCLCA", "name": "Profiles Key", "scopes": [ "user.profile.read", "user.profile.update" ] } ``` -------------------------------- ### Node.js example for retrieving a bounce Source: https://www.twilio.com/docs/sendgrid/api-reference/bounces-api/retrieve-a-bounce Uses the @sendgrid/client package to send a GET request to /v3/suppression/bounces/{email}. Requires the SENDGRID_API_KEY environment variable to be set. ```javascript const client = require("@sendgrid/client"); client.setApiKey(process.env.SENDGRID_API_KEY); const email = "brian12@example.net"; const request = { url: `/v3/suppression/bounces/${email}`, method: "GET", }; client .request(request) .then(([response, body]) => { console.log(response.statusCode); console.log(response.body); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Sample response for GET /v3/suppression/bounces/{email} Source: https://www.twilio.com/docs/sendgrid/api-reference/bounces-api/retrieve-a-bounce Example JSON response returned by the endpoint when a bounce is found. Contains the created timestamp, email address, reason, and status fields. ```json [ { "created": 1443651125, "email": "bounce1@test.com", "reason": "550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/answer/6596 o186si2389584ioe.63 - gsmtp ", "status": "5.1.1" } ] ``` -------------------------------- ### View a Sender Identity Node.js Example Source: https://www.twilio.com/docs/sendgrid/api-reference/sender-identities-api/view-a-sender-identity.md Demonstrates how to use the SendGrid Node.js client to perform a GET request for a specific sender identity. ```js const client = require("@sendgrid/client"); client.setApiKey(process.env.SENDGRID_API_KEY); const sender_id = 42; const request = { url: `/v3/senders/${sender_id}`, method: "GET", }; client .request(request) .then(([response, body]) => { console.log(response.statusCode); console.log(response.body); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Get a specific parse setting (Python, C#, Java, Go, PHP, Ruby, cURL) Source: https://www.twilio.com/docs/sendgrid/api-reference/settings-inbound-parse/retrieve-a-specific-parse-setting.md All code examples retrieve a specific parse setting for the hostname lt-38.hamilton-robinson.org using the SendGrid API. Each example uses the SENDGRID_API_KEY environment variable for authentication and prints the HTTP status code, body, and headers. In Python, the method uses sg.client.user.webhooks.parse.settings._(hostname).get(). The Go example defines a request with the host "https://api.sendgrid.com" and endpoint "/v3/user/webhooks/parse/settings/lt-38.hamilton-robinson.org". The PHP and Ruby examples follow the same pattern with their respective client libraries. The cURL command sends a GET request to the same endpoint with a Bearer token. ```python import os from sendgrid import SendGridAPIClient sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY")) hostname = "lt-38.hamilton-robinson.org" response = sg.client.user.webhooks.parse.settings._(hostname).get() print(response.status_code) print(response.body) print(response.headers) ``` ```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using SendGrid; public class Program { public static async Task Main() { string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var hostname = "lt-38.hamilton-robinson.org"; var response = await client.RequestAsync( method: SendGridClient.Method.GET, urlPath: $"user/webhooks/parse/settings/{hostname}"); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); } } ``` ```java import com.sendgrid.*; import java.io.IOException; public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("/user/webhooks/parse/settings/lt-38.hamilton-robinson.org"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ``` ```go package main import ( "fmt" "github.com/sendgrid/sendgrid-go" "os" ) func main() { apiKey := os.Getenv("SENDGRID_API_KEY") host := "https://api.sendgrid.com" request := sendgrid.GetRequest(apiKey, "/v3/user/webhooks/parse/settings/lt-38.hamilton-robinson.org", host) request.Method = "GET" response, err := sendgrid.API(request) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { fmt.Println(response.StatusCode) fmt.Println(response.Body) fmt.Println(response.Headers) } } ``` ```php /sendgrid-php.php'; $apiKey = $_ENV["SENDGRID_API_KEY"]; $sg = new \SendGrid($apiKey); $hostname = "lt-38.hamilton-robinson.org"; try { $response = $sg->client ->user() ->webhooks() ->parse() ->settings() ->_($hostname) ->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $ex) { echo "Caught exception: " . $ex->getMessage(); } ``` ```ruby require 'sendgrid-ruby' include SendGrid sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) hostname = "lt-38.hamilton-robinson.org" response = sg.client.user.webhooks.parse.settings._(hostname).get() puts response.status_code puts response.headers puts response.body ``` ```bash curl -X GET "https://api.sendgrid.com/v3/user/webhooks/parse/settings/lt-38.hamilton-robinson.org" \ --header "Authorization: Bearer $SENDGRID_API_KEY" ``` -------------------------------- ### Campaign Creation Error Response Example Source: https://www.twilio.com/docs/sendgrid/api-reference/campaigns-api/create-a-campaign A JSON example showing the structure of error messages returned when a campaign creation request fails validation. ```json { "errors": [ { "field": "title", "message": "title can't be blank" }, { "field": "title", "message": "title is too long (maximum is 100 characters)" }, { "field": "categories", "message": "categories exceeds 10 category limit" }, { "field": "html_content", "message": "html_content exceeds the 1MB limit" }, { "field": "plain_content", "message": "plain_content exceeds the 1MB limit" }, { "field": "sender_id", "message": "sender_id does not exist" }, { "field": "sender_id", "message": "sender_id is not a verified sender identity" }, { "field": "list_ids", "message": "list_ids do not all exist" }, { "field": "segment_ids", "message": "segment_ids do not all exist" }, { "field": "ip_pool", "message": "The ip pool you provided is invalid" }, { "field": "suppression_group_id", "message": "suppression_group_id does not exist" }, { "field": "unsubscribes", "message": "Either suppression_group_id or custom_unsubscribe_url may be set/used, but not both. Please remove one before setting the other." }, { "field": null, "message": "The JSON you have submitted cannot be parsed." }, { "field": null, "message": "You've reached your limit of 250 campaigns. Please delete one or more and try again." } ] } ``` -------------------------------- ### Get all offerings available to the reseller account Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-offering-operations/list-offerings Retrieve all offerings available to the reseller account using the SendGrid v3 API. Each example uses the SENDGRID_API_KEY environment variable for authentication and prints the HTTP status code, body, and headers. The cURL command uses a Bearer token. ```javascript const client = require("@sendgrid/client"); client.setApiKey(process.env.SENDGRID_API_KEY); const request = { url: `/v3/partners/offerings`, method: "GET", }; client .request(request) .then(([response, body]) => { console.log(response.statusCode); console.log(response.body); }) .catch((error) => { console.error(error); }); ``` ```python import os from sendgrid import SendGridAPIClient sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY")) response = sg.client.partners.offerings.get() print(response.status_code) print(response.body) print(response.headers) ``` ```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using SendGrid; public class Program { public static async Task Main() { string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var response = await client.RequestAsync( method: SendGridClient.Method.GET, urlPath: "partners/offerings"); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); } } ``` ```java import com.sendgrid.*; import java.io.IOException; public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("/partners/offerings"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ``` ```go package main import ( "fmt" "github.com/sendgrid/sendgrid-go" "os" ) func main() { apiKey := os.Getenv("SENDGRID_API_KEY") host := "https://api.sendgrid.com" request := sendgrid.GetRequest(apiKey, "/v3/partners/offerings", host) request.Method = "GET" response, err := sendgrid.API(request) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { fmt.Println(response.StatusCode) fmt.Println(response.Body) fmt.Println(response.Headers) } } ``` ```php /sendgrid-php.php'; $apiKey = $_ENV["SENDGRID_API_KEY"]; $sg = new \SendGrid($apiKey); try { $response = $sg->client->partners()->offerings()->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $ex) { echo "Caught exception: " . $ex->getMessage(); } ``` ```ruby require 'sendgrid-ruby' include SendGrid sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) response = sg.client.partners.offerings.get() puts response.status_code puts response.headers puts response.body ``` ```bash curl -X GET "https://api.sendgrid.com/v3/partners/offerings" \ --header "Authorization: Bearer $SENDGRID_API_KEY" ``` -------------------------------- ### Get offerings for a specific customer account (cURL) Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-offering-operations/get-account-offerings Uses cURL to send a GET request to the offerings endpoint for a given account ID. Requires the SENDGRID_API_KEY environment variable. The response is printed to stdout. ```bash curl -X GET "https://api.sendgrid.com/v3/partners/accounts/accountID/offerings" \ --header "Authorization: Bearer $SENDGRID_API_KEY" ``` -------------------------------- ### GET /v3/verified_senders/steps_completed Source: https://www.twilio.com/docs/sendgrid/api-reference/sender-verification/completed-steps.md This snippet documents the GET endpoint for retrieving the steps completed in the sender verification process. It includes the endpoint path, required authorization header, and a curl request example. ```APIDOC ## [GET] /v3/verified_senders/steps_completed ### Description Retrieves the steps completed for the sender verification process. ### Method GET ### Endpoint /v3/verified_senders/steps_completed ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token with your SendGrid API key. ### Request Example ``` curl -X GET "https://api.sendgrid.com/v3/verified_senders/steps_completed" \ --header "Authorization: Bearer $SENDGRID_API_KEY" ``` ### Response #### Success Response (200) - **statusCode** (integer) - HTTP status code of the response. - **body** (string) - Response body containing the steps completed information. - **headers** (object) - Response headers. #### Response Example ``` { "statusCode": 200, "body": "...", "headers": {} } ``` ``` -------------------------------- ### Create Account with C# Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/create-account Uses the SendGridClient to send a POST request to the partners/accounts endpoint with a test account header. ```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using SendGrid; public class Program { public static async Task Main() { string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var headers = new Dictionary { { "T-Test-Account", "true" } }; var client = new SendGridClient(apiKey: apiKey, requestHeaders: headers); var data = @"{ ""profile"": { ""first_name"": ""Sender"", ""last_name"": ""Wiz"", ""company_name"": ""Twilio SendGrid"", ""company_website"": ""https://sendgrid.com"", ""email"": ""test@test.com"", ""timezone"": ""Asia/Tokyo"" }, ""offerings"": [ { ""name"": ""org.ei.free.v1"", ""type"": ""package"", ""quantity"": 1 } ] }"; var response = await client.RequestAsync( method: SendGridClient.Method.POST, urlPath: "partners/accounts", requestBody: data); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); } } ``` -------------------------------- ### Create a customer account in Python Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/create-account Uses the sendgrid library to post account data to the partners/accounts endpoint. ```python import os from sendgrid import SendGridAPIClient sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY")) data = { "profile": { "first_name": "Sender", "last_name": "Wiz", "company_name": "Twilio SendGrid", "company_website": "https://sendgrid.com", "email": "test@test.com", "timezone": "Asia/Tokyo", }, "offerings": [{"name": "org.ei.free.v1", "type": "package", "quantity": 1}], } response = sg.client.partners.accounts.post(request_body=data) print(response.status_code) print(response.body) print(response.headers) ``` -------------------------------- ### GET /v3/partners/accounts/{accountID}/offerings Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-offering-operations/get-account-offerings This snippet documents the GET endpoint to retrieve offerings for a specific customer account. It includes the endpoint path, required path parameter, and example responses. ```APIDOC ## GET /v3/partners/accounts/{accountID}/offerings ### Description Get offerings for a specific customer account. ### Method GET ### Endpoint `/v3/partners/accounts/{accountID}/offerings` ### Parameters #### Path Parameters - **accountID** (string) - Required - The unique identifier of the customer account. ### Request Example ``` GET /v3/partners/accounts/accountID/offerings ``` ### Response #### Success Response (200) - **statusCode** (integer) - HTTP status code of the response. - **body** (object) - Response body containing the offerings data. - **headers** (object) - Response headers. #### Response Example ``` { "statusCode": 200, "body": {}, "headers": {} } ``` ``` -------------------------------- ### 200 Response Example for GET /v3/suppression/blocks/{email} Source: https://www.twilio.com/docs/sendgrid/api-reference/blocks-api/retrieve-a-specific-block Example response body for a successful 200 response when retrieving a specific block. Contains an array with one object showing the created timestamp, email address, reason, and status of the block. ```json [ { "created": 1443651154, "email": "example@example.com", "reason": "error dialing remote address: dial tcp 10.57.152.165:25: no route to host", "status": "4.0.0" } ] ``` -------------------------------- ### Create a customer account in Java Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/create-account Uses the SendGrid library and org.json to construct the request body and execute a POST request. ```java import com.sendgrid.*; import java.io.IOException; import org.json.JSONObject; import java.util.HashMap; import java.util.Arrays; public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("/partners/accounts"); request.setBody(new JSONObject(new HashMap() { { put("profile", new HashMap() { { put("first_name", "Sender"); put("last_name", "Wiz"); put("company_name", "Twilio SendGrid"); put("company_website", "https://sendgrid.com"); put("email", "test@test.com"); put("timezone", "Asia/Tokyo"); } }); put("offerings", Arrays.asList(new HashMap() { { put("name", "org.ei.free.v1"); put("type", "package"); put("quantity", 1); } })); } }).toString()); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ``` -------------------------------- ### Create Account with Go Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/create-account Uses the sendgrid-go library to send a POST request to the /v3/partners/accounts endpoint. ```go package main import ( "fmt" "github.com/sendgrid/sendgrid-go" "os" ) func main() { apiKey := os.Getenv("SENDGRID_API_KEY") host := "https://api.sendgrid.com" request := sendgrid.GetRequest(apiKey, "/v3/partners/accounts", host) request.Method = "POST" request.Headers["T-Test-Account"] = "true" request.Body = []byte(`{ "profile": { "first_name": "Sender", "last_name": "Wiz", "company_name": "Twilio SendGrid", "company_website": "https://sendgrid.com", "email": "test@test.com", "timezone": "Asia/Tokyo" }, "offerings": [ { "name": "org.ei.free.v1", "type": "package", "quantity": 1 } ] }`) response, err := sendgrid.API(request) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { fmt.Println(response.StatusCode) fmt.Println(response.Body) fmt.Println(response.Headers) } } ``` -------------------------------- ### Create Account in Go Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/create-account Uses the sendgrid-go library to send a POST request to the /v3/partners/accounts endpoint. ```go package main import ( "fmt" "github.com/sendgrid/sendgrid-go" "os" ) func main() { apiKey := os.Getenv("SENDGRID_API_KEY") host := "https://api.sendgrid.com" request := sendgrid.GetRequest(apiKey, "/v3/partners/accounts", host) request.Method = "POST" request.Body = []byte(`{ "profile": { "first_name": "Sender", "last_name": "Wiz", "company_name": "Twilio SendGrid", "company_website": "https://sendgrid.com", "email": "test@test.com", "timezone": "Asia/Tokyo" }, "offerings": [ { "name": "org.ei.free.v1", "type": "package", "quantity": 1 } ] }`) response, err := sendgrid.API(request) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { fmt.Println(response.StatusCode) fmt.Println(response.Body) fmt.Println(response.Headers) } } ``` -------------------------------- ### Create Account with Java Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/create-account Uses the SendGrid library to perform a POST request to the /partners/accounts endpoint. ```java import com.sendgrid.*; import java.io.IOException; import org.json.JSONObject; import java.util.HashMap; import java.util.Arrays; public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); sg.addRequestHeader("T-Test-Account", "true"); Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("/partners/accounts"); request.setBody(new JSONObject(new HashMap() { { put("profile", new HashMap() { { put("first_name", "Sender"); put("last_name", "Wiz"); put("company_name", "Twilio SendGrid"); put("company_website", "https://sendgrid.com"); put("email", "test@test.com"); put("timezone", "Asia/Tokyo"); } }); put("offerings", Arrays.asList(new HashMap() { { put("name", "org.ei.free.v1"); put("type", "package"); put("quantity", 1); } })); } }).toString()); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ``` -------------------------------- ### Create SSO for Partner Account (PHP, Ruby, cURL) Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/single-sign-on Create a single sign-on configuration for a partner account using the SendGrid v3 API. The PHP and Ruby examples use the SendGrid client libraries and require the SENDGRID_API_KEY environment variable. The curl command sends a POST request to the /partners/accounts/{accountID}/sso endpoint with the API key in the Authorization header. ```php /sendgrid-php.php'; $apiKey = $_ENV["SENDGRID_API_KEY"]; $sg = new \SendGrid($apiKey); $accountID = "accountID"; try { $response = $sg->client ->partners() ->accounts() ->_($accountID) ->sso() ->post(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $ex) { echo "Caught exception: " . $ex->getMessage(); } ``` ```ruby require 'sendgrid-ruby' include SendGrid sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) accountID = "accountID" response = sg.client.partners.accounts._(accountID).sso.post() puts response.status_code puts response.headers puts response.body ``` ```bash curl -X POST "https://api.sendgrid.com/v3/partners/accounts/accountID/sso" \ --header "Authorization: Bearer $SENDGRID_API_KEY" ``` -------------------------------- ### Create a customer account in C# Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/create-account Uses the SendGridClient to perform an asynchronous POST request with a JSON-formatted string body. ```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using SendGrid; public class Program { public static async Task Main() { string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var data = @"{ ""profile"": { ""first_name"": ""Sender"", ""last_name"": ""Wiz"", ""company_name"": ""Twilio SendGrid"", ""company_website"": ""https://sendgrid.com"", ""email"": ""test@test.com"", ""timezone"": ""Asia/Tokyo"" }, ""offerings"": [ { ""name"": ""org.ei.free.v1"", ""type"": ""package"", ""quantity"": 1 } ] }"; var response = await client.RequestAsync( method: SendGridClient.Method.POST, urlPath: "partners/accounts", requestBody: data); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); } } ``` -------------------------------- ### GET /v3/suppression/bounces Source: https://www.twilio.com/docs/sendgrid/api-reference/bounces-api/retrieve-all-bounces Retrieves a paginated list of all bounces. Use the limit query parameter to set the page size and the offset query parameter to control the position in the list from which to start retrieving additional items. ```APIDOC ## GET /v3/suppression/bounces ### Description This endpoint allows you to retrieve a paginated list of all your bounces. ### Method GET ### Endpoint /v3/suppression/bounces ### Base URL - https://api.sendgrid.com (for global users and subusers) - https://api.eu.sendgrid.com (for EU regional subusers) ### Parameters #### Query Parameters - **limit** (integer) - Optional - Sets the page size. Use to control how many bounces are returned per request. - **offset** (integer) - Optional - Controls the position in the list from which to start retrieving additional items. ### Response #### Success Response (200) A paginated list of bounces. The response structure is not specified in the source. #### Response Example (Not provided in the source.) ``` -------------------------------- ### Get Domain Warn List with SendGrid Client: JavaScript, Python, and C# Source: https://www.twilio.com/docs/sendgrid/api-reference/sender-verification/domain-warn-list.md Shows how to call the Domain Warn List endpoint on the verified senders domain API with the official SendGrid client. All examples are equivalent and require a SENDGRID_API_KEY environment variable set to a valid API key. They send a GET request to /v3/verified_senders/domains and print the status code and body. ```js const client = require("@sendgrid/client"); client.setApiKey(process.env.SENDGRID_API_KEY); const request = { url: `/v3/verified_senders/domains`, method: "GET", }; client .request(request) .then(([response, body]) => { console.log(response.statusCode); console.log(response.body); }) .catch((error) => { console.error(error); }); ``` ```python import os from sendgrid import SendGridAPIClient sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY")) response = sg.client.verified_senders.domains.get() print(response.status_code) print(response.body) print(response.headers) ``` ```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using SendGrid; public class Program { public static async Task Main() { string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var response = await client.RequestAsync( method: SendGridClient.Method.GET, urlPath: "verified_senders/domains"); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); } } ``` -------------------------------- ### Create Test Customer Account in Python Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/create-account Uses the sendgrid library to create a test account, including the T-Test-Account header. ```python import os from sendgrid import SendGridAPIClient sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY")) headers = {"T-Test-Account": "true"} data = { "profile": { "first_name": "Sender", "last_name": "Wiz", "company_name": "Twilio SendGrid", "company_website": "https://sendgrid.com", "email": "test@test.com", "timezone": "Asia/Tokyo", }, "offerings": [{"name": "org.ei.free.v1", "type": "package", "quantity": 1}], } response = sg.client.partners.accounts.post( request_headers=headers, request_body=data ) print(response.status_code) print(response.body) print(response.headers) ``` -------------------------------- ### Retrieve a specific block with Node.js Source: https://www.twilio.com/docs/sendgrid/api-reference/blocks-api/retrieve-a-specific-block Node.js example using the @sendgrid/client library to retrieve a specific block by email address. Sets the API key from the SENDGRID_API_KEY environment variable and makes a GET request to /v3/suppression/blocks/{email}. ```javascript const client = require("@sendgrid/client"); client.setApiKey(process.env.SENDGRID_API_KEY); const email = "brian12@example.net"; const request = { url: `/v3/suppression/blocks/${email}`, method: "GET", }; client .request(request) .then(([response, body]) => { console.log(response.statusCode); console.log(response.body); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Delete blocks with Node.js using @sendgrid/client Source: https://www.twilio.com/docs/sendgrid/api-reference/blocks-api/delete-blocks Node.js client example using @sendgrid/client to delete blocks. Sets the API key from environment variable, sends a DELETE request to /v3/suppression/blocks with the request body, and logs the response status and body. Requires installation of @sendgrid/client. ```javascript const client = require("@sendgrid/client"); client.setApiKey(process.env.SENDGRID_API_KEY); const data = { delete_all: false, emails: ["example1@example.com", "example2@example.com"], }; const request = { url: `/v3/suppression/blocks`, method: "DELETE", body: data, }; client .request(request) .then(([response, body]) => { console.log(response.statusCode); console.log(response.body); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Create Account with PHP Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/create-account Uses the SendGrid PHP library to send a POST request to the accounts endpoint. ```php /sendgrid-php.php'; $apiKey = $_ENV["SENDGRID_API_KEY"]; $sg = new \SendGrid($apiKey); $request_body = json_decode('{ "profile": { "first_name": "Sender", "last_name": "Wiz", "company_name": "Twilio SendGrid", "company_website": "https://sendgrid.com", "email": "test@test.com", "timezone": "Asia/Tokyo" }, "offerings": [ { "name": "org.ei.free.v1", "type": "package", "quantity": 1 } ] }'); $request_headers = ["T-Test-Account: true"]; try { $response = $sg->client ->partners() ->accounts() ->post($request_body, null, $request_headers); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $ex) { echo "Caught exception: " . $ex->getMessage(); } ``` -------------------------------- ### Create Account in PHP Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-operations/create-account Uses the sendgrid-php library to post account data to the partners accounts endpoint. ```php /sendgrid-php.php'; $apiKey = $_ENV["SENDGRID_API_KEY"]; $sg = new \SendGrid($apiKey); $request_body = json_decode('{ "profile": { "first_name": "Sender", "last_name": "Wiz", "company_name": "Twilio SendGrid", "company_website": "https://sendgrid.com", "email": "test@test.com", "timezone": "Asia/Tokyo" }, "offerings": [ { "name": "org.ei.free.v1", "type": "package", "quantity": 1 } ] }'); try { $response = $sg->client->partners()->accounts()->post($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $ex) { echo "Caught exception: " . $ex->getMessage(); } ``` -------------------------------- ### Get Engagement Quality Scores with SendGrid API Source: https://www.twilio.com/docs/sendgrid/api-reference/sendgrid-engagement-quality-api/get-engagement-quality-scores.md Retrieve engagement quality scores for a date range using the SendGrid API. Each example uses the SENDGRID_API_KEY environment variable and passes 'from' and 'to' query parameters set to '2006-01-02'. The response status code, body, and headers are printed. ```python import os from sendgrid import SendGridAPIClient sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY")) params = {"from": "2006-01-02", "to": "2006-01-02"} response = sg.client.engagementquality.scores.get(query_params=params) print(response.status_code) print(response.body) print(response.headers) ``` ```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using SendGrid; public class Program { public static async Task Main() { string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var queryParams = @"{'from': '2006-01-02', 'to': '2006-01-02'}"; var response = await client.RequestAsync( method: SendGridClient.Method.GET, urlPath: "engagementquality/scores", queryParams: queryParams); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); } } ``` ```java import com.sendgrid.*; import java.io.IOException; public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("/engagementquality/scores"); request.addQueryParam("from", "2006-01-02"); request.addQueryParam("to", "2006-01-02"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ``` ```go package main import ( "fmt" "github.com/sendgrid/sendgrid-go" "os" ) func main() { apiKey := os.Getenv("SENDGRID_API_KEY") host := "https://api.sendgrid.com" request := sendgrid.GetRequest(apiKey, "/v3/engagementquality/scores", host) request.Method = "GET" queryParams := make(map[string]string) queryParams["from"] = "2006-01-02" queryParams["to"] = "2006-01-02" request.QueryParams = queryParams response, err := sendgrid.API(request) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { fmt.Println(response.StatusCode) fmt.Println(response.Body) fmt.Println(response.Headers) } } ``` ```php /sendgrid-php.php'; $apiKey = $_ENV["SENDGRID_API_KEY"]; $sg = new \SendGrid($apiKey); $query_params = json_decode('{ "from": "2006-01-02", "to": "2006-01-02" }'); try { $response = $sg->client ->engagementquality() ->scores() ->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $ex) { echo "Caught exception: " . $ex->getMessage(); } ``` ```ruby require 'sendgrid-ruby' include SendGrid sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) params = JSON.parse('{ "from": "2006-01-02", "to": "2006-01-02" }') response = sg.client.engagementquality.scores.get(query_params: params) puts response.status_code puts response.headers puts response.body ``` ```bash curl -G -X GET "https://api.sendgrid.com/v3/engagementquality/scores?from=2006-01-02&to=2006-01-02" \ --header "Authorization: Bearer $SENDGRID_API_KEY" ``` -------------------------------- ### Retrieve a parse security policy with SendGrid Go Source: https://www.twilio.com/docs/sendgrid/api-reference/settings-inbound-parse/retrieve-a-specific-parse-security-policy.md Go example using the SendGrid Go library to retrieve a specific parse security policy. Requires the SENDGRID_API_KEY environment variable and the sendgrid-go package. ```go package main import ( "fmt" "github.com/sendgrid/sendgrid-go" "os" ) func main() { apiKey := os.Getenv("SENDGRID_API_KEY") host := "https://api.sendgrid.com" request := sendgrid.GetRequest(apiKey, "/v3/user/webhooks/security/policies/id", host) request.Method = "GET" response, err := sendgrid.API(request) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { fmt.Println(response.StatusCode) fmt.Println(response.Body) fmt.Println(response.Headers) } } ``` -------------------------------- ### Get Account State with SendGrid API in C#, Java, Go, PHP, Ruby, and cURL Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api-account-state-operations/get-account-state These examples retrieve the account state for a partner account using the SendGrid API. Each language version uses the SENDGRID_API_KEY environment variable and the accountID placeholder. The response includes status code, body, and headers. ```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using SendGrid; public class Program { public static async Task Main() { string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var accountID = "accountID"; var response = await client.RequestAsync( method: SendGridClient.Method.GET, urlPath: $"partners/accounts/{accountID}/state"); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); } } ``` ```java import com.sendgrid.*; import java.io.IOException; public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("/partners/accounts/accountID/state"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ``` ```go package main import ( "fmt" "github.com/sendgrid/sendgrid-go" "os" ) func main() { apiKey := os.Getenv("SENDGRID_API_KEY") host := "https://api.sendgrid.com" request := sendgrid.GetRequest(apiKey, "/v3/partners/accounts/accountID/state", host) request.Method = "GET" response, err := sendgrid.API(request) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { fmt.Println(response.StatusCode) fmt.Println(response.Body) fmt.Println(response.Headers) } } ``` ```php /sendgrid-php.php'; $apiKey = $_ENV["SENDGRID_API_KEY"]; $sg = new \SendGrid($apiKey); $accountID = "accountID"; try { $response = $sg->client ->partners() ->accounts() ->_($accountID) ->state() ->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $ex) { echo "Caught exception: " . $ex->getMessage(); } ``` ```ruby require 'sendgrid-ruby' include SendGrid sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) accountID = "accountID" response = sg.client.partners.accounts._(accountID).state.get() puts response.status_code puts response.headers puts response.body ``` ```bash curl -X GET "https://api.sendgrid.com/v3/partners/accounts/accountID/state" \ --header "Authorization: Bearer $SENDGRID_API_KEY" ``` -------------------------------- ### Set offerings payload example Source: https://www.twilio.com/docs/sendgrid/api-reference/account-provisioning-api Example payload for the Update Account Offerings operation to remove features such as Subusers by moving the account to a package that doesn't allow those features. This example shows a free offerings payload. ```json { "offerings": [ { "name": "milne.ei.free-100.v1", "type": "package", "quantity": 1 } ] } ```