Unleash the Power of Open Source Fundraising with OpenCollective

Welcome to OpenCollective

OpenCollective is a platform designed to help open source projects and communities transparently manage their collective funds. With OpenCollective, you can set up a collective, receive contributions, and allocate funds – all while maintaining full transparency and accountability.

Introducing OpenCollective APIs

The OpenCollective API is a powerful tool that enables developers to interact with the platform programmatically. Here are some useful APIs with code snippets.

API Endpoints

Create a Collective

  
    POST /graphql

    mutation {
      createCollective(collective: {
        name: "MyOpenSourceProject",
        slug: "myopensourceproject",
        description: "A project that solves problems",
        website: "https://myopensourceproject.org"
      }) {
        id
        slug
      }
    }
  

Get Collective Information

  
    GET /collectives/:slug

    {
      "data": {
        "collective": {
          "name": "MyOpenSourceProject",
          "description": "A project that solves problems",
          "website": "https://myopensourceproject.org"
        }
      }
    }
  

List Transactions

  
    GET /collectives/:slug/transactions

    {
      "data": [
        {
          "id": "1234",
          "amount": 1000,
          "currency": "USD",
          "description": "Donation from John"
        },
        {
          "id": "1235",
          "amount": -500,
          "currency": "USD",
          "description": "Expense for hosting"
        }
      ]
    }
  

Create an Expense

  
    POST /collectives/:slug/expenses

    {
      "amount": 500,
      "description": "Expense for hosting",
      "category": "Hosting",
      "createdByUserId": "user_123"
    }
  

Application Example

Let’s put everything together in a simple node.js application that interacts with OpenCollective’s API.

  
    const axios = require('axios');

    const createCollective = async () => {
      const response = await axios.post(
        'https://api.opencollective.com/graphql',
        {
          query: `
            mutation {
              createCollective(collective: {
                name: "MyOpenSourceProject",
                slug: "myopensourceproject",
                description: "A project that solves problems",
                website: "https://myopensourceproject.org"
              }) {
                id
                slug
              }
            }
          `
        }
      );

      return response.data;
    };

    const getCollectiveInfo = async (slug) => {
      const response = await axios.get(
        \`https://api.opencollective.com/collectives/\${slug}\`
      );
      
      return response.data;
    };

    const listTransactions = async (slug) => {
      const response = await axios.get(
        \`https://api.opencollective.com/collectives/\${slug}/transactions\`
      );

      return response.data;
    };

    const createExpense = async (slug, expense) => {
      const response = await axios.post(
        \`https://api.opencollective.com/collectives/\${slug}/expenses\`,
        expense
      );

      return response.data;
    };

    (async () => {
      const newCollective = await createCollective();
      console.log('Collective Created: ', newCollective);

      const collectiveInfo = await getCollectiveInfo('myopensourceproject');
      console.log('Collective Info: ', collectiveInfo);

      const transactions = await listTransactions('myopensourceproject');
      console.log('Collective Transactions: ', transactions);

      const expense = await createExpense('myopensourceproject', {
        amount: 500,
        description: 'Expense for hosting',
        category: 'Hosting',
        createdByUserId: 'user_123'
      });
      console.log('Expense Created: ', expense);
    })();
  

With these APIs, managing your open source collective becomes streamlined and efficient. Start leveraging the power of OpenCollective today!

Hash: 28090c1a1015040195c4795c0357d24e9e6873b3b476ad45fe5c735e9d605ae4

Leave a Reply

Your email address will not be published. Required fields are marked *