Bag is live โ€” accept USDC & card payments globally. Get started โ†’
BagBag Docs
SDKs

Other Languages

Use the Bag REST API from any language with cURL and HTTP examples.

Other Languages

Bag's API is a standard REST API with JSON request/response bodies and Bearer token authentication. You can call it from any language that can make HTTP requests.


Authentication

Every request requires an Authorization header:

Authorization: Bearer bag_live_sk_your_api_key

cURL Examples

curl -X POST https://getbags.app/api/payment-links \
  -H "Authorization: Bearer $BAG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Pro Plan",
    "amount": 29.99,
    "network": "base",
    "description": "Monthly Pro subscription"
  }'
curl https://getbags.app/api/payment-links?limit=25 \
  -H "Authorization: Bearer $BAG_API_KEY"

Get a tax quote

curl -X POST https://getbags.app/api/tax/quote \
  -H "Authorization: Bearer $BAG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "paymentLinkId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "customerAddress": {
      "address_line_1": "100 Main St",
      "address_city": "San Francisco",
      "address_province": "CA",
      "address_postal_code": "94105",
      "address_country": "US",
      "address_type": "billing"
    }
  }'

Create a checkout session

curl -X POST https://getbags.app/api/checkout/session \
  -H "Authorization: Bearer $BAG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "linkId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "quoteToken": "eyJhbGciOiJIUzI1NiIs...",
    "walletAddress": "0xCustomerWallet",
    "walletType": "evm",
    "network": "base",
    "customer": {
      "name": "Jane Doe",
      "email": "jane@example.com",
      "country": "US"
    },
    "totalsSnapshot": {
      "subtotalCents": 2999,
      "taxCents": 262,
      "totalCents": 3261,
      "calculationId": "calc_abc123"
    }
  }'

List transactions

curl https://getbags.app/api/transactions?limit=50 \
  -H "Authorization: Bearer $BAG_API_KEY"

Create a refund

curl -X POST https://getbags.app/api/refunds \
  -H "Authorization: Bearer $BAG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "transaction_id": "txn_123abc",
    "amount": 29.99,
    "reason": "customer_request"
  }'

Create a webhook endpoint

curl -X POST https://getbags.app/api/webhooks \
  -H "Authorization: Bearer $BAG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://yourapp.com/webhooks/bag",
    "events": ["payment.completed", "payment.failed", "subscription.created"]
  }'

Go

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
)

func main() {
	apiKey := os.Getenv("BAG_API_KEY")

	body, _ := json.Marshal(map[string]interface{}{
		"name":    "Pro Plan",
		"amount":  29.99,
		"network": "base",
	})

	req, _ := http.NewRequest("POST", "https://getbags.app/api/payment-links", bytes.NewBuffer(body))
	req.Header.Set("Authorization", "Bearer "+apiKey)
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	var result map[string]interface{}
	json.NewDecoder(resp.Body).Decode(&result)
	fmt.Println(result)
}

Ruby

require "net/http"
require "json"
require "uri"

api_key = ENV["BAG_API_KEY"]
uri = URI("https://getbags.app/api/payment-links")

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{api_key}"
request["Content-Type"] = "application/json"
request.body = { name: "Pro Plan", amount: 29.99, network: "base" }.to_json

response = http.request(request)
data = JSON.parse(response.body)
puts data

PHP

<?php
$apiKey = getenv('BAG_API_KEY');

$ch = curl_init('https://getbags.app/api/payment-links');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer {$apiKey}",
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'name' => 'Pro Plan',
        'amount' => 29.99,
        'network' => 'base',
    ]),
]);

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);
print_r($data);

Building a client library

If you're building a typed client, use the OpenAPI spec:

  • Spec URL: https://docs.getbags.app/openapi.yaml
  • Base URL: https://getbags.app
  • Auth: Authorization: Bearer {apiKey} on every request
  • Content type: application/json for all requests and responses
  • Response envelope: { "status": "success", "data": { ... } } or { "status": "error", "message": "...", "code": "..." }

Popular OpenAPI code generators:


What's next

On this page