Skip to content

Latest commit

 

History

History
416 lines (306 loc) · 29.9 KB

File metadata and controls

416 lines (306 loc) · 29.9 KB

CustomFields

Overview

Available Operations

  • list - List Custom Fields
  • create - Create Custom Field
  • get - Get Custom Field
  • delete - Delete Custom Field
  • update - Update Custom Field

list

List custom fields.

Scopes: custom_fields:read custom_fields:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.customFields.list({
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
  });

  for await (const page of result) {
    console.log(page);
  }
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { customFieldsList } from "@polar-sh/sdk/funcs/customFieldsList.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await customFieldsList(polar, {
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
  });
  if (res.ok) {
    const { value: result } = res;
    for await (const page of result) {
    console.log(page);
  }
  } else {
    console.log("customFieldsList failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CustomFieldsListRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.CustomFieldsListResponse>

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

create

Create a custom field.

Scopes: custom_fields:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.customFields.create({
    type: "select",
    slug: "<value>",
    name: "<value>",
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
    properties: {
      options: [],
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { customFieldsCreate } from "@polar-sh/sdk/funcs/customFieldsCreate.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await customFieldsCreate(polar, {
    type: "select",
    slug: "<value>",
    name: "<value>",
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
    properties: {
      options: [],
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("customFieldsCreate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request components.CustomFieldCreate ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.CustomField>

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

get

Get a custom field by ID.

Scopes: custom_fields:read custom_fields:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.customFields.get({
    id: "<value>",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { customFieldsGet } from "@polar-sh/sdk/funcs/customFieldsGet.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await customFieldsGet(polar, {
    id: "<value>",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("customFieldsGet failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CustomFieldsGetRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.CustomField>

Errors

Error Type Status Code Content Type
errors.ResourceNotFound 404 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

delete

Delete a custom field.

Scopes: custom_fields:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  await polar.customFields.delete({
    id: "<value>",
  });


}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { customFieldsDelete } from "@polar-sh/sdk/funcs/customFieldsDelete.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await customFieldsDelete(polar, {
    id: "<value>",
  });
  if (res.ok) {
    const { value: result } = res;
    
  } else {
    console.log("customFieldsDelete failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CustomFieldsDeleteRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<void>

Errors

Error Type Status Code Content Type
errors.ResourceNotFound 404 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

update

Update a custom field.

Scopes: custom_fields:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.customFields.update({
    id: "<value>",
    customFieldUpdate: {
      type: "date",
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { customFieldsUpdate } from "@polar-sh/sdk/funcs/customFieldsUpdate.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await customFieldsUpdate(polar, {
    id: "<value>",
    customFieldUpdate: {
      type: "date",
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("customFieldsUpdate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CustomFieldsUpdateRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.CustomField>

Errors

Error Type Status Code Content Type
errors.ResourceNotFound 404 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*