import os
import requests
url = "https://api.stripe.com/v1/invoices/in_1234567890abcdef"
headers = {
"Authorization": f"Bearer {os.environ.get('STRIPE_SECRET_KEY')}"
}
response = requests.get(url, headers=headers)
response.raise_for_status()
print(response.json())
import os
import httpx
url = "https://api.stripe.com/v1/invoices/in_1234567890abcdef"
headers = {
"Authorization": f"Bearer {os.environ.get('STRIPE_SECRET_KEY')}"
}
with httpx.Client() as client:
response = client.get(url, headers=headers)
response.raise_for_status()
print(response.json())
const fetch = require('node-fetch');
const url = 'https://api.stripe.com/v1/invoices/in_1234567890abcdef';
const headers = {
'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`
};
fetch(url, { headers })
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
const axios = require('axios');
const url = 'https://api.stripe.com/v1/invoices/in_1234567890abcdef';
const headers = {
'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`
};
axios.get(url, { headers })
.then(response => {
console.log(response.data);
})
.catch(error => {
if (error.response) {
console.error('Error:', error.response.status, error.response.data);
} else {
console.error('Error:', error.message);
}
});
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)
func main() {
url := "https://api.stripe.com/v1/invoices/in_1234567890abcdef"
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("STRIPE_SECRET_KEY"))
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
log.Fatalf("HTTP error! status: %s, body: %s", resp.Status, body)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
<?php
$url = 'https://api.stripe.com/v1/invoices/in_1234567890abcdef';
$headers = [
'Authorization: Bearer ' . getenv('STRIPE_SECRET_KEY')
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
die('Error:' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
die("HTTP error! status: $httpCode, body: $response");
}
$json = json_decode($response, true);
print_r($json);
curl_close($ch);
?>
require 'net/http'
require 'json'
url = URI.parse('https://api.stripe.com/v1/invoices/in_1234567890abcdef')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request['Authorization'] = "Bearer #{ENV['STRIPE_SECRET_KEY']}"
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.stripe.com/v1/invoices/in_1234567890abcdef")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Bearer \(ProcessInfo.processInfo.environment["STRIPE_SECRET_KEY"] ?? "")", forHTTPHeaderField: "Authorization")
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Error: \(error)")
return
}
guard let httpResponse = response as? HTTPURLResponse else {
print("Invalid response")
return
}
guard (200...299).contains(httpResponse.statusCode) else {
print("HTTP error! status: \(httpResponse.statusCode)")
if let data = data, let body = String(data: data, encoding: .utf8) {
print("Body: \(body)")
}
return
}
if let data = data, let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
print(json)
}
}
task.resume()
RunLoop.main.run()
use std::env;
use reqwest;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = "https://api.stripe.com/v1/invoices/in_1234567890abcdef";
let client = reqwest::Client::new();
let response = client
.get(url)
.header("Authorization", format!("Bearer {}", env::var("STRIPE_SECRET_KEY")?))
.send()
.await?;
if !response.status().is_success() {
let status = response.status();
let body = response.text().await?;
eprintln!("HTTP error! status: {}, body: {}", status, body);
std::process::exit(1);
}
let json: serde_json::Value = response.json().await?;
println!("{}", json);
Ok(())
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var url = "https://api.stripe.com/v1/invoices/in_1234567890abcdef";
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue(
"Bearer",
Environment.GetEnvironmentVariable("STRIPE_SECRET_KEY")
);
var response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine($"HTTP error! status: {response.StatusCode}, body: {content}");
return;
}
var json = await response.Content.ReadAsStringAsync();
Console.WriteLine(json);
}
}