import os
import requests
response = requests.get(
"https://api.sendgrid.com/v3/scopes",
headers={
"Authorization": f"Bearer {os.environ['SENDGRID_API_KEY']}",
"Content-Type": "application/json"
}
)
response.raise_for_status()
import os
import httpx
response = httpx.get(
"https://api.sendgrid.com/v3/scopes",
headers={
"Authorization": f"Bearer {os.environ['SENDGRID_API_KEY']}",
"Content-Type": "application/json"
}
)
response.raise_for_status()
import fetch from 'node-fetch';
const response = await fetch('https://api.sendgrid.com/v3/scopes', {
headers: {
'Authorization': `Bearer ${process.env.SENDGRID_API_KEY}`,
'Content-Type': 'application/json'
}
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
import axios from 'axios';
const response = await axios.get('https://api.sendgrid.com/v3/scopes', {
headers: {
'Authorization': `Bearer ${process.env.SENDGRID_API_KEY}`,
'Content-Type': 'application/json'
}
});
package main
import (
"net/http"
"os"
)
func main() {
req, err := http.NewRequest("GET", "https://api.sendgrid.com/v3/scopes", nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("SENDGRID_API_KEY"))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
panic("Request failed")
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.sendgrid.com/v3/scopes');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . getenv('SENDGRID_API_KEY'),
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
throw new Exception('Request failed');
}
curl_close($ch);
?>
require 'net/http'
require 'json'
uri = URI('https://api.sendgrid.com/v3/scopes')
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{ENV['SENDGRID_API_KEY']}"
req['Content-Type'] = 'application/json'
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(req)
end
raise "Request failed" unless res.is_a?(Net::HTTPSuccess)
import Foundation
let url = URL(string: "https://api.sendgrid.com/v3/scopes")!
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
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
fatalError("Request failed")
}
// Process data here
}
task.resume()
use reqwest;
use std::env;
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let client = reqwest::Client::new();
let response = client
.get("https://api.sendgrid.com/v3/scopes")
.header("Authorization", format!("Bearer {}", env::var("SENDGRID_API_KEY").unwrap()))
.header("Content-Type", "application/json")
.send()
.await?;
assert!(response.status().is_success());
Ok(())
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {Environment.GetEnvironmentVariable("SENDGRID_API_KEY")}");
client.DefaultRequestHeaders.Add("Content-Type", "application/json");
var response = await client.GetAsync("https://api.sendgrid.com/v3/scopes");
response.EnsureSuccessStatusCode();
}
}