POST /v1/referrals/code — Set custom referral slug
https://api.triport.io/v1/referrals/codeCreate or update the authenticated user's custom referral code (slug).
Every account automatically gets a uid referral code derived from its user
ID. This endpoint lets a signed-in user pick a friendlier, human-readable
custom code (kind = custom) to share instead.
The call is an upsert: the first request creates the custom code, and any
later request replaces the slug. The submitted value is normalized server-side
(lowercased and trimmed) before validation and storage, so MyCode and
mycode both resolve to mycode. A user has at most one active custom code;
the existing uid code keeps working alongside it.
To remove a custom code, send DELETE /v1/referrals/code — the uid code
remains active.
This route is part of the user-facing referral console and is protected by the session cookie set at login. There is no API-key form for it.
Parameters
Request body
slugstringrequireda-z, 0-9, and -, and may not start or end with -. Reserved words (e.g. admin) are rejected.Response
200 OK
codeobjectcode.IDstring (UUID)code.UserIDstring (UUID)code.Codestringcode.Kindstringcustom for this endpoint (the other kind is uid).code.CreatedAtstring (RFC 3339)code.DisabledAtstring (RFC 3339) | nullnull while active; set when the code is disabled via DELETE.Errors
| Code | error value | When it happens |
|---|---|---|
| 400 | invalid_json | Request body is missing or not valid JSON. |
| 400 | slug_invalid | Slug fails the format rules: wrong length (outside 3–32), disallowed characters, or a leading/trailing -. |
| 401 | unauthenticated | No valid session cookie. |
| 409 | slug_reserved | Slug is on the reserved/blocked list (e.g. admin). |
| 409 | slug_taken | Slug is already in use by another user. |
All errors use the shared error envelope — see errors.md for the full shape and handling guidance.
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/referrals/code", {
method: "POST",
headers: { "Content-Type": "application/json" },
credentials: "include", // send the session cookie
body: JSON.stringify({ slug: "trip-with-me" }),
});
if (!res.ok) {
const { error } = await res.json();
throw new Error(error); // e.g. "slug_taken"
}
const { code } = await res.json();
console.log(code.Code); // "trip-with-me"TypeScript SDK (@triport/sdk)
import { TriportClient } from "@triport/sdk";
const client = new TriportClient({ baseUrl: "https://api.triport.io" });
const { code } = await client.referrals.setSlug({ slug: "trip-with-me" });
console.log(code.Code, code.Kind); // "trip-with-me" "custom"Python (triport-sdk)
from triport import TriportClient
client = TriportClient(base_url="https://api.triport.io")
code = client.referrals.set_slug(slug="trip-with-me")
print(code["Code"], code["Kind"]) # trip-with-me customNotes
- Slug rules: length 3–32, charset
[a-z0-9-], no leading or trailing-. Input is lowercased and trimmed before these checks run, so casing and surrounding whitespace never cause a rejection on their own. - Idempotent upsert: repeating the request with the same slug is safe; sending a new slug replaces the previous custom code.
- Removing the slug:
DELETE /v1/referrals/codedisables the custom code (soft delete) and returns{"ok": true}; theuidcode continues to work. - Related:
GET /v1/referrals/mereturns the currentprimary_codeandcustom_slugalongside referral stats.