Skip to main content
REST client

Payment Links

The 5 operations under payment-links, as typed calls on the generated REST client.

1 min read
View MarkdownEdit on GitHub

Payment Links

Available from @codespar/sdk 0.12.0, which is not on npm yet. The published version today is 0.11.0, and it has no cs.api; 0.12.0 is on the main branch of codespar-core. The examples below are not compiled against the installed package for that reason.

Every call below is cs.api reaching one operation of the OpenAPI document this page was generated from; the REST client overview explains request, response, the option bag and the errors. The values are placeholders shaped by the document.

import { CodeSpar } from "@codespar/sdk";

const cs = new CodeSpar({ apiKey: process.env.CODESPAR_API_KEY });
GET/v1/payment-links

List the payment links in this project

const result = await cs.api.get("/v1/payment-links");

Parameters, body and every documented response: GET /v1/payment-links in the HTTP reference.

POST /v1/payment-links

POST/v1/payment-links

Create a multi-rail payment link

const r = await cs.api.response("post", "/v1/payment-links", {
  body: {
    slug: "example",
    title: "Example",
    description: "string",
    accepts: [
      {
        rail: "x402",
        amount: "1000",
        currency: "USDC",
        pay_to: {
          kind: "byo",
          address: "string",
          consumer_id: "csm_0000000000000000"
        }
      }
    ],
    one_time: true,
    max_uses: 1,
    expires_at: "2026-01-15T12:00:00.000Z",
    redirect_url: "https://example.com/hook",
    metadata: {}
  }
});
// r.status is one of the documented statuses (200, 403),
// each with its own body shape in r.data; nothing here throws on 403.
if (r.ok) {
  console.log(r.data);
}

Parameters, body and every documented response: POST /v1/payment-links in the HTTP reference.

GET /v1/payment-links/{id}

GET/v1/payment-links/{id}

Read one payment link

const result = await cs.api.get("/v1/payment-links/{id}", {
  path: {
    id: "pl_0000000000000000"
  }
});

Parameters, body and every documented response: GET /v1/payment-links/{id} in the HTTP reference.

PATCH /v1/payment-links/{id}

PATCH/v1/payment-links/{id}

Update a payment link's title, copy, expiry, redirect or active flag

const r = await cs.api.response("patch", "/v1/payment-links/{id}", {
  path: {
    id: "pl_0000000000000000"
  },
  body: {
    title: "Example",
    active: true
  }
});
// r.status is one of the documented statuses (200, 403),
// each with its own body shape in r.data; nothing here throws on 403.
if (r.ok) {
  console.log(r.data);
}

Parameters, body and every documented response: PATCH /v1/payment-links/{id} in the HTTP reference.

DELETE /v1/payment-links/{id}

DELETE/v1/payment-links/{id}

Delete a payment link

const r = await cs.api.response("delete", "/v1/payment-links/{id}", {
  path: {
    id: "pl_0000000000000000"
  }
});
// r.status is one of the documented statuses (200, 403),
// each with its own body shape in r.data; nothing here throws on 403.
if (r.ok) {
  console.log(r.data);
}

Parameters, body and every documented response: DELETE /v1/payment-links/{id} in the HTTP reference.

Payment Links | CodeSpar