API snippets
Reference API examples and schemas from any page.
Request snippet
POST/payments
curl -X POST https://api.acme.dev/v1/payments \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"amount": 2500,
"currency": "usd",
"customer": "cus_8f3k2",
"description": "Pro plan — June"
}'import requests
url = "https://api.acme.dev/v1/payments"
payload = {
"amount": 2500,
"currency": "usd",
"customer": "cus_8f3k2",
"description": "Pro plan — June"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())const response = await fetch("https://api.acme.dev/v1/payments", {
method: "POST",
headers: {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
},
body: JSON.stringify({
"amount": 2500,
"currency": "usd",
"customer": "cus_8f3k2",
"description": "Pro plan — June"
})
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
url := "https://api.acme.dev/v1/payments"
payload := strings.NewReader(`{
"amount": 2500,
"currency": "usd",
"customer": "cus_8f3k2",
"description": "Pro plan — June"
}`)
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require "uri"
require "net/http"
require "json"
url = URI("https://api.acme.dev/v1/payments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = {
"amount": 2500,
"currency": "usd",
"customer": "cus_8f3k2",
"description": "Pro plan — June"
}.to_json
response = http.request(request)
puts response.read_bodyHttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.acme.dev/v1/payments"))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\"amount\":2500,\"currency\":\"usd\",\"customer\":\"cus_8f3k2\",\"description\":\"Pro plan — June\"}"))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.acme.dev/v1/payments', [
'body' => '{"amount":2500,"currency":"usd","customer":"cus_8f3k2","description":"Pro plan — June"}',
'headers' => [
'Authorization' => 'Bearer <token>',
'Content-Type' => 'application/json',
],
]);
echo $response->getBody();using var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.acme.dev/v1/payments");
request.Headers.Add("Authorization", "Bearer <token>");
request.Content = new StringContent("{\"amount\":2500,\"currency\":\"usd\",\"customer\":\"cus_8f3k2\",\"description\":\"Pro plan — June\"}", Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());import Foundation
var request = URLRequest(url: URL(string: "https://api.acme.dev/v1/payments")!)
request.httpMethod = "POST"
request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = """
{
"amount": 2500,
"currency": "usd",
"customer": "cus_8f3k2",
"description": "Pro plan — June"
}
""".data(using: .utf8)
let (data, _) = try await URLSession.shared.data(for: request)
print(String(decoding: data, as: UTF8.self))POST/refunds
curl -X POST https://api.acme.dev/v1/refunds \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"payment": "string"
}'import requests
url = "https://api.acme.dev/v1/refunds"
payload = {
"payment": "string"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json()){
"payment": "string"
}Response snippet
{
"id": "pay_3Jk2Lm",
"object": "payment",
"amount": 2500,
"currency": "usd",
"status": "requires_payment_method",
"customer": {
"id": "cus_8f3k2",
"email": "user@example.com",
"name": "Ada Lovelace",
"address": {
"line1": "string",
"city": "string",
"country": "US"
}
},
"created_at": "2024-01-15T09:30:00Z",
"refunds": [
{
"id": "string",
"amount": 1
}
]
}{
"error": {
"code": "card_declined",
"message": "Your card was declined."
}
}{
"error": {
"code": "card_declined",
"message": "Your card was declined."
}
}Endpoint schema
Request
This endpoint expects an object.
Webhook payload
HOOKpaymentSucceeded
{
"id": "evt_1",
"type": "payment.succeeded",
"data": {
"id": "pay_3Jk2Lm",
"object": "payment",
"amount": 2500,
"currency": "usd",
"status": "requires_payment_method",
"customer": {
"id": "cus_8f3k2",
"email": "user@example.com",
"name": "Ada Lovelace",
"address": {
"line1": "string",
"city": "string",
"country": "US"
}
},
"created_at": "2024-01-15T09:30:00Z",
"refunds": [
{
"id": "string",
"amount": 1
}
]
}
}Types
{
"id": "cus_8f3k2",
"email": "user@example.com",
"name": "Ada Lovelace",
"address": {
"line1": "string",
"city": "string",
"country": "US"
}
}Runnable endpoint
GEThttps://api.acme.dev/v1/payments/:payment_id
POSThttps://api.acme.dev/v1/refunds