Referrals
Generate Referral Code
Generate a unique, shareable referral code for a customer.
POST
/
v1
/
referrals
/
generate-code
Generate a referral code for a customer
curl --request POST \
--url https://billing.example.com/v1/referrals/generate-code \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'import requests
url = "https://billing.example.com/v1/referrals/generate-code"
payload = { "customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({customer_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a'})
};
fetch('https://billing.example.com/v1/referrals/generate-code', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://billing.example.com/v1/referrals/generate-code",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://billing.example.com/v1/referrals/generate-code"
payload := strings.NewReader("{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://billing.example.com/v1/referrals/generate-code")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/referrals/generate-code")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"code": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
customer_id | string (UUID) | Yes | The unique identifier of the customer who will own this referral code. |
Example Request
curl -X POST https://api.recurso.dev/v1/referrals/generate-code \
-H "Authorization: Bearer rsk_live_7f3a9b2c1d4e8f0a" \
-H "Content-Type: application/json" \
-d '{
"customer_id": "d4e5f6a7-b8c9-4d0e-a1f2-b3c4d5e6f7a8"
}'
Response
{
"data": {
"code": "RECURSO-D4E5F6",
"customer_id": "d4e5f6a7-b8c9-4d0e-a1f2-b3c4d5e6f7a8",
"url": "https://recurso.dev/r/RECURSO-D4E5F6",
"created_at": "2026-06-23T17:15:00Z",
"expires_at": null
}
}
Response Fields
| Field | Type | Description |
|---|---|---|
code | string | The generated referral code. Alphanumeric, uppercase, prefixed with RECURSO-. |
customer_id | string | The customer who owns this referral code. |
url | string | A shareable URL that embeds the referral code. New customers who sign up via this link are automatically associated as referred. |
created_at | string | ISO 8601 timestamp of when the code was generated. |
expires_at | string or null | ISO 8601 expiration timestamp, or null if the code does not expire. |
Notes
- Each customer can have one active referral code at a time. Calling this endpoint again for the same customer returns the existing code.
- The referral code is case-insensitive when redeemed but is returned in uppercase for consistency.
- When a new customer signs up using the referral URL, a referral record is automatically created linking the referrer to the new customer.
- To invalidate a referral code, contact support or use the dashboard.
Embed the
url field directly into email campaigns or share buttons to make referrals seamless for your customers.⌘I
Generate a referral code for a customer
curl --request POST \
--url https://billing.example.com/v1/referrals/generate-code \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'import requests
url = "https://billing.example.com/v1/referrals/generate-code"
payload = { "customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({customer_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a'})
};
fetch('https://billing.example.com/v1/referrals/generate-code', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://billing.example.com/v1/referrals/generate-code",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://billing.example.com/v1/referrals/generate-code"
payload := strings.NewReader("{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://billing.example.com/v1/referrals/generate-code")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/referrals/generate-code")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"code": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}