Open Collective API Documentation

Open Collective is a platform that helps groups raise funds and manage expenses transparently by creating a community around a shared cause. The Open Collective API is public and allows developers to build applications on top of the Open Collective platform.

Getting Started

To get started with using the Open Collective API, you first need to obtain an API key. You can obtain an API key by creating an account on the Open Collective website.

The base URL for all API endpoints is https://api.opencollective.com/. All API requests require authentication using your API key.

To authenticate requests, set the Authorization header to Bearer [API Key] where [API Key] is your API key.

Examples

Here are some example API requests in JavaScript:

Get all collectives

async function getAllCollectives() {
  const url = "https://api.opencollective.com/graphql/v2";
  const query = `{
    allCollectives {
      nodes {
        id
        slug
        name
        currency
        balance
      }
    }
  }`;
  
  const options = {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${api_key}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({ query })
  }
  
  const response = await fetch(url, options);
  const data = await response.json();
  return data.data.allCollectives.nodes;
}

Create a donation

async function createDonation(collectiveSlug, amount, interval = "one-time") {
  const url = `https://api.opencollective.com/${collectiveSlug}/donations`;
  
  const options = {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${api_key}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      donation: {
        amount,
        interval
      }
    })
  }
  
  const response = await fetch(url, options);
  const data = await response.json();
  return data;
}

Get all expenses for a collective

async function getAllExpenses(collectiveSlug) {
  const url = `https://api.opencollective.com/${collectiveSlug}/expenses`;
  
  const options = {
    headers: {
      "Authorization": `Bearer ${api_key}`
    }
  }
  
  const response = await fetch(url, options);
  const data = await response.json();
  return data;
}

Conclusion

In this blog post, we have covered some basic examples of using the Open Collective API in JavaScript. The examples covered here should be enough to get you started with building applications on top of the Open Collective platform. For more information, check out the official Open Collective API documentation.

Related APIs

Public APIs — A directory of free and public apis

Built by @mddanishyusuf