# Examples

> Code examples for common OAuth API requests

- **URL**: https://orshot.com/docs/developers/examples

---

For workspace-specific endpoints, use the `x-workspace-id` header to target a specific workspace. If omitted, the first authorized workspace is used.

## Get Current User```javascript
const response = await fetch("https://api.orshot.com/v1/me", {
  headers: {
    Authorization: `Bearer ${accessToken}`,
  },
});

const user = await response.json();
// { id: "user_...", name: "John Doe", email: "john@example.com", ... }
```## List Templates```javascript
const response = await fetch("https://api.orshot.com/v1/studio/templates", {
  headers: {
    Authorization: `Bearer ${accessToken}`,
    "x-workspace-id": "50", // Optional: target specific workspace
  },
});

const templates = await response.json();
// [{ id: "123", name: "Social Card", ... }, ...]
```## Render Studio Template```javascript
const response = await fetch("https://api.orshot.com/v1/studio/render", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${accessToken}`,
    "Content-Type": "application/json",
    "x-workspace-id": "50", // Optional: target specific workspace
  },
  body: JSON.stringify({
    templateId: "123",
    modifications: [
      { name: "title", text: "Hello World" },
      { name: "logo", src: "https://example.com/logo.png" },
    ],
    response: {
      type: "url",
      format: "png",
    },
  }),
});

const { url } = await response.json();
// "https://cloud.orshot.com/renders/abc123.png"
```## Render Combined Multi-Page Video```javascript
const response = await fetch("https://api.orshot.com/v1/studio/render", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${accessToken}`,
    "Content-Type": "application/json",
    "x-workspace-id": "50", // Optional: target specific workspace
  },
  body: JSON.stringify({
    templateId: "123",
    modifications: {
      "page1@title": "Intro",
      "page2@title": "Features",
      "page3@title": "CTA",
    },
    response: {
      type: "url",
      format: "webm",
      includePages: [1, 2, 3],
    },
    videoOptions: {
      combinePages: true,
      pageTransition: "fade",
      pageTransitionDuration: 0.5,
      muted: true,
    },
  }),
});

const data = await response.json();
// { data: { content: "https://.../combined.webm", ... } }
```## Generate Image```javascript
const response = await fetch("https://api.orshot.com/v1/generate", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${accessToken}`,
    "Content-Type": "application/json",
    "x-workspace-id": "50", // Optional: target specific workspace
  },
  body: JSON.stringify({
    template_id: "123",
    modifications: [
      { name: "title", text: "Hello World" },
      { name: "avatar", src: "https://example.com/photo.jpg" },
    ],
    response_type: "url",
  }),
});

const { url } = await response.json();
// "https://storage.orshot.com/renders/abc123.png"
```## Generate with Base64 Response```javascript
const response = await fetch("https://api.orshot.com/v1/generate", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${accessToken}`,
    "Content-Type": "application/json",
    "x-workspace-id": "50", // Optional: target specific workspace
  },
  body: JSON.stringify({
    template_id: "123",
    modifications: [{ name: "title", text: "Hello World" }],
    response_type: "base64",
  }),
});

const { base64 } = await response.json();
// "data:image/png;base64,iVBORw0KGgo..."
```## Get Template Modifications```javascript
const response = await fetch(
  "https://api.orshot.com/v1/studio/templates/123/modifications",
  {
    headers: {
      Authorization: `Bearer ${accessToken}`,
      "x-workspace-id": "50", // Optional: target specific workspace
    },
  },
);

const modifications = await response.json();
// [{ name: "title", type: "text" }, { name: "avatar", type: "image" }, ...]
```## Delete Template```javascript
const response = await fetch(
  "https://api.orshot.com/v1/studio/templates/123/delete",
  {
    method: "DELETE",
    headers: {
      Authorization: `Bearer ${accessToken}`,
      "x-workspace-id": "50", // Optional: target specific workspace
    },
  },
);

const result = await response.json();
// { message: "Template successfully deleted", id: "123" }
```