Making your first API request

Making your first request

To make it quick and easy for you to build your GoCardless integration, we maintain libraries in JavaPythonRubyPHPJavaScript.NET and Go to talk to our API in those languages without writing lots of boilerplate code.

Setting up your client library

Let’s install the API library using a package manager (you can also download the source yourself from the links in the code blocks):

pip install gocardless_pro
GitHub URL

Now we can import the library into our code so that it’s ready to use:

import gocardless_pro

Creating an access token

To start using the API, you’ll need an access token.

First, sign up for an account in our sandbox: the sandbox is our dedicated testing environment where you can build and test your integration without touching real money.

Next, create an access token. Head to https://manage-sandbox.gocardless.com/developers/access-tokens/create, then give your access token a name and make sure you give it read-write access. Click “Create access token”, and copy the token to your clipboard.

Your very first API request

You’re now ready to initialise the client:

1import os 2import gocardless_pro 3 4client = gocardless_pro.Client( 5 # We recommend storing your access token in an 6 # environment variable for security 7 access_token=os.environ['GC_ACCESS_TOKEN'], 8 # Change this to 'live' when you are ready to go live. 9 environment='sandbox' 10)

Now, let’s check that the client is working by making our first request to the API: List customers

1$customers = $client->customers()->list()->records; 2print_r($customers);

Run that code and you should get an empty array, as you haven’t added any customers yet - but the fact that you got a response back shows that you’re authenticated and ready to go.

1Array 2( 3)

What's Next?

Adding your first customer