import os
import requests
response = requests.get(
"https://api.sendgrid.com/v3/suppression/bounces",
headers={
"Authorization": f"Bearer {os.environ['SENDGRID_API_KEY']}",
"Content-Type": "application/json"
}
)
response.raise_for_status()
print(response.json())
import os
import httpx
with httpx.Client() as client:
response = client.get(
"https://api.sendgrid.com/v3/suppression/bounces",
headers={
"Authorization": f"Bearer {os.environ['SENDGRID_API_KEY']}",
"Content-Type": "application/json"
}
)
response.raise_for_status()
print(response.json())
import fetch from 'node-fetch';
const response = await fetch('https://api.sendgrid.com/v3/suppression/bounces', {
method: 'GET',
headers: {
'Authorization': `Bearer ${process.env.SENDGRID_API_KEY}`,
'Content-Type': 'application/json'
}
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
console.log(data);
import axios from 'axios';
const response = await axios.get('https://api.sendgrid.com/v3/suppression/bounces', {
headers: {
'Authorization': `Bearer ${process.env.SENDGRID_API_KEY}`,
'Content-Type': 'application/json'
}
});
console.log(response.data);
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://api.sendgrid.com/v3/suppression/bounces", nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("SENDGRID_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
panic(fmt.Sprintf("HTTP error! status: %s, body: %s", resp.Status, body))
}
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.sendgrid.com/v3/suppression/bounces');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . getenv('SENDGRID_API_KEY'),
'Content-Type: application/json'
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception('Curl error: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
throw new Exception("HTTP error! status: $httpCode, body: $response");
}
$decoded = json_decode($response, true);
print_r($decoded);
curl_close($ch);
require 'net/http'
require 'json'
uri = URI('https://api.sendgrid.com/v3/suppression/bounces')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Authorization'] = "Bearer #{ENV['SENDGRID_API_KEY']}"
request['Content-Type'] = 'application/json'
response = http.request(request)
unless response.is_a?(Net::HTTPSuccess)
raise "HTTP error! status: #{response.code}, body: #{response.body}"
end
puts JSON.parse(response.body)
import Foundation
let url = URL(string: "https://api.sendgrid.com/v3/suppression/bounces")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Bearer \(ProcessInfo.processInfo.environment["SENDGRID_API_KEY"] ?? "")", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
fatalError("Error: \(error)")
}
guard let httpResponse = response as? HTTPURLResponse else {
fatalError("Invalid response")
}
guard (200...299).contains(httpResponse.statusCode) else {
fatalError("HTTP error! status: \(httpResponse.statusCode)")
}
if let data = data, let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
print(json)
}
}
task.resume()
RunLoop.main.run()
use reqwest;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = reqwest::Client::new();
let response = client
.get("https://api.sendgrid.com/v3/suppression/bounces")
.header("Authorization", format!("Bearer {}", std::env::var("SENDGRID_API_KEY")?))
.header("Content-Type", "application/json")
.send()
.await?;
if !response.status().is_success() {
return Err(format!("HTTP error! status: {}", response.status()).into());
}
let body = response.json::<serde_json::Value>().await?;
println!("{:?}", body);
Ok(())
}
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var client = new HttpClient();
client.BaseAddress = new Uri("https://api.sendgrid.com");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Bearer", Environment.GetEnvironmentVariable("SENDGRID_API_KEY")
);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.GetAsync("/v3/suppression/bounces");
if (!response.IsSuccessStatusCode)
{
throw new Exception($"HTTP error! status: {response.StatusCode}");
}
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}