Skip to content

POST /v1/projects/{id}/platforms/sms/numbers

Buys one US local number from the provider and records it as a resource with SMS enabled. Requires countryCode (US) and accepts an optional three-digit geographic areaCode. The server selects an exact matching number. While inventory is empty the operation keeps searching, and the caller can cancel it until ordering begins; a search still empty one minute after the operation was created fails it with NUMBER_INVENTORY_UNAVAILABLE. Always answers 202 with an operation: the work runs behind the response, and the Location points at the operation to poll. New area-specific requests must appear in current provider coverage; discover it with GET /sms/numbers/area-codes?countryCode=US. Coverage and subscription checks run before operation creation. Billing follows delivery. Replays return the original operation without checking current coverage. The Idempotency-Key is required and permanent: repeating it returns the same operation forever, never a second number. A further number always needs a NEW key, including while others are still running. An optional promotionCode is redeemed with the number's charge, which follows delivery: a code billing refuses hands the number back, and its release operation carries the refusal (reason charge_refused, with detail.chargeRefusal { code: "promotion_code_rejected", detail: <why> }). Requires the platforms:write permission bound to the project resource in the path. If the operation fails, its error is the problem of one of these codes: ENTITLEMENT_REQUIRED, NUMBER_INVENTORY_UNAVAILABLE, NUMBER_ORDER_FAILED, NUMBER_ORDER_RECONCILIATION_REQUIRED, NUMBER_SEARCH_FAILED.

photon.projects.platforms.purchaseSmsNumber(input: PurchaseSmsNumberInput, options?: RequestOptions): Promise<PurchaseSmsNumberOutput>
import { Photon } from "@photon-ai/api";

const photon = new Photon({
  headers: { Authorization: `Bearer ${process.env.PHOTON_API_TOKEN}` },
});
const result = await photon.projects.platforms.purchaseSmsNumber({
  path: {
    id: "id",
  },
  headers: {
    idempotencyKey: "idempotencyKey",
  },
  body: {
    countryCode: "US",
  },
});
{
  "cancellable": true,
  "createdAt": "2026-01-01T00:00:00.000Z",
  "detail": {},
  "endedAt": "2026-01-01T00:00:00.000Z",
  "error": {
    "code": "CHARGE_REFUSED",
    "remediation": {
      "action": "Check the payment method in Billing, then request the purchase again."
    },
    "status": 402,
    "title": "Charge Refused",
    "type": "https://photon.codes/docs/problems/charge-refused"
  },
  "operationId": "string",
  "projectId": "string",
  "reason": "charge_refused",
  "resourceId": "string",
  "resourceType": "string",
  "startedAt": "2026-01-01T00:00:00.000Z",
  "state": "pending",
  "type": "resource.provision",
  "updatedAt": "2026-01-01T00:00:00.000Z"
}

Parameters

Photon-VersionPhotonVersion

Selects the API contract date. Without it, the request is served as 2026-07-01.

Idempotency-Keystringrequired

Identifies one logical mutation across retries.

idstringrequired

Body

areaCodestring
countryCodeunknownrequired
promotionCodestring

A promotion code to redeem with this number's charge. Billing takes a fixed amount off the charge. The charge follows delivery, so a code Billing refuses hands the number back, and the release operation carries the refusal. Part of the request's identity: repeating the Idempotency-Key with a different code, or none, is refused.

Returns

202 The purchase was accepted and is running. GET the Location after the Retry-After interval until state is terminal; the response there carries the number once it exists. Operation

Headers: Location, Photon-Version. The raw response carries these headers; see Raw responses.

cancellablebooleanrequired
createdAtstring (date-time)required
detailobject
endedAtstring (date-time)
errorOperationError

Why the operation failed: the problem of its code, the same object the endpoint returns when it rejects a request, with the status that rejection would have had (the poll itself answers 200). Every code an operation can end with is a branch below, and the endpoint that starts the operation lists its codes. Branch on code, never on status, and keep a default: a code added after your client was generated arrives as a generic problem with type: about:blank and status: 500. That 500 means this document does not describe the code yet, not that the request failed on our side or that retrying will help.

operationIdstringrequired
projectIdstringrequired
reasonOperationReason
resourceIdstring
resourceTypestringrequired
startedAtstring (date-time)
stateOperationStaterequired
typeOperationTyperequired
updatedAtstring (date-time)required