# Send Your First API Request

Source: https://docs.gocardless.com/docs/getting-started/send-your-first-api-request

# Send your first API request

### Create your first test payment authorisation in 5 minutes

We'll walk you through making your first API requests by creating and completing a Billing Request, which allows customers to securely authorise payments.

> **Info: What you**
> - A GoCardless Sandbox account and your API access token ([set up guide](/docs/getting-started/set-up))
> - A developer environment capable of making requests to the GoCardless API

## Creating a billing request

A Billing Request enables you to collect all types of GoCardless payments. For now, we'll handle a recurring, direct debit (mandate) request.

### 01. Create your first billing request

Copy your access token from the Developers page in the GoCardless dashboard.

```bash
ACCESS_TOKEN="your_access_token_here"
```

Create your first billing request by sending the request below.

```http
POST https://api.gocardless.com/billing_requests HTTP/1.1
Content-Type: application/json
\
  \}
\}

HTTP/1.1 201 Created
Location: /billing_requests/BRQ123
Content-Type: application/json
\
\},
...
\}
```

```curl
curl --silent \\
-H "Content-Type: application/json" \\
-H "Gocardless-Version: 2015-07-06" \\
-H "Authorization: Bearer \$\" \\
"https://api.gocardless.com/billing_requests" \\
-d @- << EOF
\
\}
\}
EOF
```

```php
\$client = new \\GoCardlessPro\\Client([
'access_token' => 'your_access_token_here',
'environment' => \\GoCardlessPro\\Environment::SANDBOX
]);

\$client->billingRequests()->create([
"params" => [
"mandate_request" => [
"scheme" => "bacs"
]
]
]);
```

```python
import gocardless_pro
client = gocardless_pro.Client(access_token="your_access_token_here", environment='sandbox')

client.billing_requests.create(params=\
\})
```

```ruby
@client = GoCardlessPro::Client.new(
access_token: "your_access_token",
environment: :sandbox
)

billing_request = @client.billing_requests.create(
params: \
\}
)
```

```java
import static com.gocardless.GoCardlessClient.Environment.SANDBOX;
String accessToken = "your_access_token_here";
GoCardlessClient client = GoCardlessClient
.newBuilder(accessToken)
.withEnvironment(SANDBOX)
.build();

BillingRequest billingRequest = client.billingRequests().create()
.withMandateRequestScheme("bacs")
.execute();
```

```nodejs
import \ from "gocardless-nodejs/client";

export const client = new GoCardlessClient(
  process.env.GOCARDLESS_ACCESS_TOKEN,
  constants.Environments.Sandbox,
);

const billingRequest = await client.billingRequests.create(\,
\});
```

```net
String accessToken = "your_access_token";
GoCardlessClient gocardless = GoCardlessClient.Create(accessToken, Environment.SANDBOX);

var mandateRequest = new GoCardless.Services.BillingRequestCreateRequest.BillingRequestMandateRequest
\;

var resp = await gocardless.BillingRequests.CreateAsync(
new GoCardless.Services.BillingRequestCreateRequest()
\
);

GoCardless.Resources.BillingRequest billingRequest = resp.BillingRequest;
```

```go
package main

	gocardless "github.com/gocardless/gocardless-pro-go/v6"
)

accessToken := "your_access_token_here"
config, err := gocardless.NewConfig(accessToken, gocardless.WithEndpoint(gocardless.SandboxEndpoint))
if err != nil \
client, err := gocardless.New(config)
if err != nil \

billingRequestCreateParams := gocardless.BillingRequestCreateParams\,
\}

billingRequest, err := client.BillingRequests.Create(context, billingRequestCreateParams)
```

```ios
import GoCardlessSDK

let billingRequest = BillingRequest(
mandateRequest: MandateRequest(scheme: "bacs")
)

GoCardlessSDK.shared.billingRequestService.createBillingRequest(billingRequest: billingRequest)
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: \
\}) \
.store(in: &subscriptions)
```

```android
import com.gocardless.gocardlesssdk.GoCardlessSDK

GoCardlessSDK.initSDK(
"YOUR_ACCESS_TOKEN",
Environment.Sandbox
)

val billingRequest = BillingRequest(
mandateRequest = MandateRequest(scheme = "bacs")
)

runBlocking \
            is ApiError -> \")
            \}
        \}
    \}

\}
```

> **Tip: Save the billing request ID**
> Make a note of the billing request ID returned in the response (e.g. `BRQ123`). You'll need it to
>   create a payment link in the next step.

### 02. Create your payment link

Creating a Billing Request Flow, powered by GoCardless hosted payment pages, generates an authorisation link for collecting payments.

```http
POST https://api.gocardless.com/billing_request_flows HTTP/1.1
Content-Type: application/json
\
  \}
\}

HTTP/1.1 201 Created
Location: /billing_request_flows/BRF123456
Content-Type: application/json
\,
...
\}
\}
```

```curl
BRQ_ID="your_billing_request_id"

curl --silent \\
-H "Content-Type: application/json" \\
-H "Gocardless-Version: 2015-07-06" \\
-H "Authorization: Bearer \$\" \\
"https://api.gocardless.com/billing_request_flows" \\
-d @- << EOF
\
\}
\}
EOF
```

```php
\$client = new \\GoCardlessPro\\Client([
'access_token' => 'your_access_token_here',
'environment' => \\GoCardlessPro\\Environment::SANDBOX
]);

\$client->billingRequestFlows()->create([
"params" => [
"links" => [
"billing_request" => "your_billing_request_id"
]
]
]);
```

```python
import gocardless_pro
client = gocardless_pro.Client(access_token="your_access_token_here", environment='sandbox')

client.billing_request_flows.create(params=\
\})
```

```ruby
@client = GoCardlessPro::Client.new(
access_token: "your_access_token",
environment: :sandbox
)

@client.billing_request_flows.create(
params: \
\}
)
```

```java
import static com.gocardless.GoCardlessClient.Environment.SANDBOX;
String accessToken = "your_access_token_here";
GoCardlessClient client = GoCardlessClient
.newBuilder(accessToken)
.withEnvironment(SANDBOX)
.build();

BillingRequestFlow billingRequestFlow = client.billingRequestFlows().create()
.withLinksBillingRequest("your_billing_request_id")
.execute();
```

```nodejs
const constants = require('gocardless-nodejs/constants');
const gocardless = require('gocardless-nodejs');
const client = gocardless('your_access_token_here', constants.Environments.Sandbox);

const billingRequestFlow = await client.billingRequestFlows.create(\
\});
```

```net
String accessToken = "your_access_token";
GoCardlessClient gocardless = GoCardlessClient.Create(accessToken, Environment.SANDBOX);

var resp = await gocardless.BillingRequestFlows.CreateAsync(
new GoCardless.Services.BillingRequestFlowCreateRequest()
\,
\}
);

GoCardless.Resources.BillingRequestFlow billingRequestFlow = resp.BillingRequestFlow;
```

```go
package main

  gocardless "github.com/gocardless/gocardless-pro-go/v6"
)

func main() \
client, err := gocardless.New(config)
if err != nil \

billingRequestFlowCreateParams := gocardless.BillingRequestFlowCreateParams\,
\}

billingRequestFlow, err := client.BillingRequestFlows.Create(context, billingRequestFlowCreateParams)

\}
```

```ios
import GoCardlessSDK

GoCardlessSDK.initSDK(accessToken: "YOUR_ACCESS_TOKEN", environment: .sandbox) \

let billingRequestFlow = BillingRequestFlow(
links: Links(billingRequest: "your_billing_request_id")
)

GoCardlessSDK.shared.billingRequestFlowService.createBillingRequestFlow(billingRequestFlow: billingRequestFlow)
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: \
\}) \
.store(in: &subscriptions)
```

```android
import com.gocardless.gocardlesssdk.GoCardlessSDK

GoCardlessSDK.initSDK(
accessToken = "YOUR_ACCESS_TOKEN",
environment = Environment.SANDBOX
)

val billingRequestFlow = BillingRequestFlow(
links = Links(billingRequest = "YOUR_BILLING_REQUEST_ID")
)

runBlocking \")
            \}
            is ApiError -> \")
            \}
        \}
    \}

\}
```

Copy the `authorisation_url` from the response — you can share this with customers to complete the billing request via a button on your website, SMS, email, or any other channel.

### 03. Customer completes billing request

You can now act as your customer would. Go to the authorisation link and enter the details.

> **Warning: Sandbox only**
> Do not use real customer email addresses or banking information in the Sandbox environment.
>   Payments will not be processed but email notifications may still be triggered.

For testing purposes, use sort code **200000** and account number **55779911** to complete the billing request.

![Customer completing the billing request flow](/images/docs/getting-started/send-your-first-api-request/customer-completes-billing-request.png)

### 04. View your first customer

You should now be able to see your newly created customer on the customers page in the dashboard.

![Your first customer on the GoCardless dashboard](/images/docs/getting-started/send-your-first-api-request/customer.png)

## Next steps

  
#### [Create a payment](/docs/getting-started/create-a-payment)

Create your first test payment using the mandate you just set up.

  
#### [Partner integrations](/docs/partner-integrations)

Accept bank payments directly within your software. Connect to your users' GoCardless accounts
    with OAuth 2.0.