Skip to content

centre-for-effective-altruism/node-gocardless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lightweight API wrapper for making requests to GoCardless.

See the GoCardless docs for a list of valid resources.

Installation

npm install --save gocardless-api

Usage

Constructor

new GoCardless() => GoCardlessClient

Creates a new client instance using your GoCardless access token

const gocardless = new GoCardless(YOUR_ACCESS_TOKEN)

Client Methods

.request(options) => Promise(GoCardlessResource)

Makes an API request, then returns the resulting resource.

const GoCardless = require('gocardless-api')
const gocardless = new GoCardless(YOUR_ACCESS_TOKEN)
gocardless.request({
    method: 'GET',
    resource: 'customers'
    query: {
        limit: 10,
        after: 'CU123'
    }
})
.then(customers => {
    // customers => {
    //  "meta": {
    //      "cursors": {
    //        "before": "CU000",
    //        "after": "CU456",
    //      },
    //      "limit": 10
    //    },
    //    "customers": [{
    //      "id": "CU123",
    //      "created_at": "2014-05-08T17:01:06.000Z",
    //      "email": "user@example.com",
    //      "given_name": "Frank",
    //      "family_name": "Osborne",
    //      "address_line1": "27 Acer Road",
    //      "address_line2": "Apt 2",
    //      "address_line3": null,
    //      "city": "London",
    //      "region": null,
    //      "postal_code": "E8 3GX",
    //      "country_code": "GB",
    //      "language": "en",
    //      "metadata": {
    //        "salesforce_id": "ABCD1234"
    //      }
    //    }, {
    //    ...
    //    }]
    //  }
})

The request will automatically add the following headers:

  • Authorization: Bearer <YOUR_ACCESS_TOKEN>
  • GoCardless-Version: 2015-07-06

You can override these headers using options.headers (see below)

request options Object:

  • method (String): HTTP request method. One of GET, PUT, PATCH or DELETE
  • resource (String): Path to the requested resource (e.g. customers, mandates/123)
  • data (Object): Data to accompany PUT or PATCH requests
  • query (Object): Query string as key=>value pairs (e.g. { limit: 10, after: ID789 } becomes ?limit=10&after=ID789)
  • options (Object): Additional request options. Passed directly to needle.

About

Lightweight API wrapper for making requests to GoCardless

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages