Portal
Redeem Gift Code
Redeem a gift code through the customer portal to activate a subscription.
POST
/
portal
/
api
/
redeem
Redeem a gift code as the logged-in customer
curl --request POST \
--url https://billing.example.com/portal/api/redeem \
--header 'Content-Type: application/json' \
--cookie portal_session= \
--data '
{
"code": "<string>"
}
'import requests
url = "https://billing.example.com/portal/api/redeem"
payload = { "code": "<string>" }
headers = {
"cookie": "portal_session=",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {cookie: 'portal_session=', 'Content-Type': 'application/json'},
body: JSON.stringify({code: '<string>'})
};
fetch('https://billing.example.com/portal/api/redeem', 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/portal/api/redeem",
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([
'code' => '<string>'
]),
CURLOPT_COOKIE => "portal_session=",
CURLOPT_HTTPHEADER => [
"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/portal/api/redeem"
payload := strings.NewReader("{\n \"code\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("cookie", "portal_session=")
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/portal/api/redeem")
.header("cookie", "portal_session=")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/portal/api/redeem")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["cookie"] = 'portal_session='
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"message": "<string>"
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
code | string | Yes | The gift code to redeem (e.g. GIFT-ABC123). |
This endpoint requires an active portal session. The customer must be logged into the portal before redeeming a gift code.
Example Request
curl -X POST https://api.recurso.dev/portal/api/redeem \
-H "Content-Type: application/json" \
-H "Cookie: portal_session=ps_abc123..." \
-d '{
"code": "GIFT-ABC123"
}'
Response
Returns the subscription object created from the redeemed gift.{
"id": "sub_9f8e7d6c5b4a3210",
"object": "subscription",
"customer_id": "cust_a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"plan_id": "plan_pro_monthly",
"status": "active",
"gift_code": "GIFT-ABC123",
"gifted_by": "cust_f0e1d2c3-b4a5-6789-0abc-def123456789",
"current_period_start": "2026-06-23T00:00:00Z",
"current_period_end": "2026-12-23T00:00:00Z",
"cancel_at_period_end": true,
"created_at": "2026-06-23T10:15:30Z",
"updated_at": "2026-06-23T10:15:30Z"
}
Each gift code can only be redeemed once. Attempting to redeem an already-used or
expired code returns a
422 validation error.⌘I
Redeem a gift code as the logged-in customer
curl --request POST \
--url https://billing.example.com/portal/api/redeem \
--header 'Content-Type: application/json' \
--cookie portal_session= \
--data '
{
"code": "<string>"
}
'import requests
url = "https://billing.example.com/portal/api/redeem"
payload = { "code": "<string>" }
headers = {
"cookie": "portal_session=",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {cookie: 'portal_session=', 'Content-Type': 'application/json'},
body: JSON.stringify({code: '<string>'})
};
fetch('https://billing.example.com/portal/api/redeem', 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/portal/api/redeem",
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([
'code' => '<string>'
]),
CURLOPT_COOKIE => "portal_session=",
CURLOPT_HTTPHEADER => [
"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/portal/api/redeem"
payload := strings.NewReader("{\n \"code\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("cookie", "portal_session=")
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/portal/api/redeem")
.header("cookie", "portal_session=")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/portal/api/redeem")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["cookie"] = 'portal_session='
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"message": "<string>"
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}