APIDeveloperSustainabilityE-Commerce

Charity Donations API for E-Commerce Developers

GoodAPI Team ·

Consumers increasingly choose brands that give back. A 2024 Edelman survey found that 64% of shoppers will buy from or boycott a brand based on its social and environmental values. For developers building e-commerce apps, that’s a clear signal: impact features aren’t a nice-to-have anymore. They ship to production.

The problem is that most developers reach for the most obvious tool first: a payment processor’s donation add-on, a standalone fundraising widget, or a hand-rolled redirect to a charity’s own donation page. These options work but they create friction, introduce a third-party domain into the checkout flow, and don’t give you a clean transaction record tied to your order data.

There’s a better approach. GoodAPI’s charity donations API lets you programmatically search vetted nonprofits, record a donation at the moment of a transaction, and pull a full giving history for your organization. It runs alongside GoodAPI’s tree planting and ocean plastic removal APIs under the same API key and the same monthly invoice. One integration, multiple impact types.

This guide walks through the API in detail, with real code and patterns you can drop into your app today.

Why a Dedicated Charity API Beats Widget Approaches

Donation widgets from platforms like JustGiving or FrontStream work well for nonprofits collecting money directly. They’re the wrong fit for e-commerce backends.

Here’s the difference. When a merchant wants to donate $1 to a food bank for every order placed, they don’t need a donor checkout experience. They need a server-side call after the order webhook fires. No payment form, no redirect, no UX break. Just a POST request that records the giving and ties it to the order ID.

GoodAPI’s charity API is built for exactly this workflow. You pass an order ID in the metadata field, an EIN (Employer Identification Number) to identify the charity, and an amount in cents. The donation is recorded, attribution is tracked, and the result is returned in the response. It’s the same pattern you’d use to plant a tree per order, and you can do both in the same webhook handler.

The Three Endpoints You Need

The charity donations API is in early access (email saif@thegoodapi.com to get enabled). Once enabled, it lives at https://app.thegoodapi.com and uses the same Authorization header as the rest of GoodAPI’s APIs.

Search Charities

GET /charities/search

Use this to look up charities by name or EIN before donating. Results include the charity’s nonprofit_id, description, and website.

Terminal window
curl -H "Authorization: your-api-key" \
"https://app.thegoodapi.com/charities/search?name=american+red+cross"

Response:

{
"total_items": 1,
"total_pages": 1,
"charities": [
{
"nonprofit_id": "n_abc123",
"name": "American Red Cross",
"ein": "53-0196605",
"description": "Prevents and alleviates human suffering",
"website": "https://www.redcross.org",
"icon_url": "https://example.com/redcross-icon.png"
}
]
}

You’d typically call this endpoint once when setting up your integration, save the nonprofit_id and EIN for the charities you want to support, and hardcode those values in your donation logic.

Create a Donation

POST /charities/donate

This is the core endpoint. Call it whenever you want to record a charitable giving event.

Terminal window
curl -X POST -H "Authorization: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"amount_cents": 100,
"ein": "53-0196605",
"idempotency_key": "order-98765-donate",
"attribution": "checkout",
"metadata": {
"order_id": "98765",
"customer_email": "shopper@example.com"
}
}' \
"https://app.thegoodapi.com/charities/donate"

The required fields are amount_cents and either ein or nonprofit_id. Everything else is optional but highly recommended for production.

List Donations

GET /charities/donations

Retrieve paginated donation history with optional filters for date range, attribution tag, or metadata values. Useful for impact dashboards or monthly reports.

Terminal window
curl -H "Authorization: your-api-key" \
"https://app.thegoodapi.com/charities/donations?attribution=checkout&start_date=2026-05-01&end_date=2026-05-31"

Idempotency: Don’t Double-Donate

E-commerce webhooks can fire more than once. Payment processors retry on failure. Order management systems sometimes call the same event twice. Without idempotency, you risk recording the same donation multiple times for a single order.

The idempotency_key field handles this. Pass a unique string per order-donation pair (e.g. order-{id}-donate). If GoodAPI receives a request with an existing idempotency key, it returns the original donation record and adds the header Idempotent-Replayed: true to the response instead of creating a new entry.

Attribution Tags: Track Where Impact Comes From

The attribution field is a free-text string you set per donation. Use it to understand which flows in your app are driving giving.

Some practical examples:

Later you can filter your donations list by attribution to build campaign-level reports without needing to build your own ledger.

Combining Charity Donations With Tree Planting

This is where GoodAPI’s multi-product design pays off. If you already use GoodAPI for tree planting, you can drop a charity donation call right next to your existing tree planting call in the same webhook handler. Same API key, same billing relationship.

// Shopify order webhook handler
app.post('/webhooks/orders/create', async (req, res) => {
const order = req.body;
const orderId = order.id.toString();
await Promise.all([
// Plant a tree with Veritree via GoodAPI
fetch('https://app.thegoodapi.com/plant-trees', {
method: 'POST',
headers: { 'Authorization': process.env.GOODAPI_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
count: 1,
idempotency_key: `${orderId}-tree`,
metadata: { order_id: orderId }
})
}),
// Donate $1 to a local food bank via GoodAPI charity API
fetch('https://app.thegoodapi.com/charities/donate', {
method: 'POST',
headers: { 'Authorization': process.env.GOODAPI_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
amount_cents: 100,
ein: '13-1837418',
idempotency_key: `${orderId}-donate`,
attribution: 'checkout',
metadata: { order_id: orderId }
})
})
]);
res.sendStatus(200);
});

The two calls run in parallel. Each tree is planted through GoodAPI’s partnership with Veritree, where trees are GPS-tracked and supported through their critical first years of growth. The charity donation is recorded against the nonprofit’s EIN. Both are consolidated on your monthly GoodAPI invoice.

Four E-Commerce Use Cases

Per-Order Donations at Checkout

The most common pattern: donate a fixed amount per order. Run the donation call in your order-created webhook. Use attribution: "checkout" and store the order_id in metadata. This gives you a clean record matching every charitable donation to a specific transaction.

Subscription Renewals

For subscription businesses, fire the donation on each renewal event rather than at signup. This way the giving is ongoing, which is a much stronger story for customers to share. Use attribution: "subscription-renewal" to separate these from one-time purchase donations.

Minimum Order Threshold Giving

If you want to give only on orders above a certain value (e.g., donate $2 to charity on orders over $50), run the threshold check on your server before calling the API. There’s no threshold logic built into the API itself, which keeps it simple and flexible.

Milestone and Loyalty Rewards

Trigger a donation when a customer hits a loyalty milestone, completes their 10th order, or refers a friend. Use attribution: "loyalty-milestone" to track these. Combined with Shopify Flow, you can build this as a no-code automation that fires the API via a webhook action.

Setting Up Your Integration

1

Get your API key

Sign up at app.thegoodapi.com and grab your API key. You’ll get both a production key and a test key. Use the test key during development, behaving identically to production but won’t create real charges or real donations.

2

Request charity donations access

Email saif@thegoodapi.com to get the charity donations API enabled on your account. This is an early-access product, so it requires a brief manual activation step.

3

Look up your charities

Call GET /charities/search to find the EINs for the nonprofits you want to support. Save those EINs in your config or environment variables and you won’t need to search again after the initial setup.

4

Add the donation call to your webhook handler

In your order-created webhook, call POST /charities/donate with amount_cents, the charity EIN, an idempotency_key derived from the order ID, and relevant metadata. Start with attribution: "checkout" to track which donations come from your main purchase flow.

5

Verify with the list endpoint

After your first test order, call GET /charities/donations to confirm the donation was recorded with the correct metadata and attribution. Switch to your production key when you’re ready to go live.

What Gets Validated

GoodAPI validates the charity against its search provider before recording the donation. If the EIN doesn’t match a known charity, the request returns a 400 error with a clear message. This prevents accidental donations to invalid or unverified organizations.

Building a Giving Dashboard

If you’re building a platform for multiple merchants, the metadata and attribution fields give you everything you need for per-merchant reporting. Store the merchant’s store ID in metadata, filter the donations list by that value, and aggregate totals by charity, date range, or attribution tag.

This is particularly useful if you’re building a Shopify app where merchants want to see charitable giving data alongside their tree planting and plastic removal impact in a single view.

Get Started

The charity donations API is live for early access users. To get enabled, email saif@thegoodapi.com with a note on your use case.

If you’re building a Shopify store rather than a custom app, the GoodAPI app handles tree planting and plastic removal with no code required. The charity donations feature is designed for developers building custom integrations on any platform.

For full documentation including request and response schemas, visit the GoodAPI charity donations docs.