Skip to main content
REST client

Policies

The 6 operations under policies, as typed calls on the generated REST client.

1 min read
View MarkdownEdit on GitHub

Policies

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/policies

GET/v1/policies

List policy rules for the authenticated org, sorted by order ASC.

const result = await cs.api.get("/v1/policies");

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

POST /v1/policies

POST/v1/policies

Create a new policy rule.

const result = await cs.api.post("/v1/policies", {
  body: {
    name: "Example",
    type: "allow",
    agents: [],
    tools: [],
    enabled: true
  }
});

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

POST /v1/policies/reorder

POST/v1/policies/reorder

Reorder policy rules. Atomic: if any id does not belong to the org, the entire operation rolls back and returns 404.

const result = await cs.api.post("/v1/policies/reorder", {
  body: {
    ids: [
      "string"
    ]
  }
});

Parameters, body and every documented response: POST /v1/policies/reorder in the HTTP reference.

GET /v1/policies/{id}

GET/v1/policies/{id}

Read one policy rule

const result = await cs.api.get("/v1/policies/{id}");

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

PATCH /v1/policies/{id}

PATCH/v1/policies/{id}

Update a policy rule. Cross-org ids return 404. Invalidates the per-org cache on success.

const result = await cs.api.patch("/v1/policies/{id}", {
  path: {
    id: "policie_0000000000000000"
  },
  body: {
    name: "Example",
    type: "allow",
    agents: [
      "string"
    ],
    tools: [
      "string"
    ],
    enabled: true
  }
});

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

DELETE /v1/policies/{id}

DELETE/v1/policies/{id}

Delete a policy rule. Cross-org ids return 404. Invalidates the per-org cache on success.

const result = await cs.api.delete("/v1/policies/{id}", {
  path: {
    id: "policie_0000000000000000"
  }
});

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

Policies | CodeSpar