Skip to content

Latest commit

 

History

History
650 lines (453 loc) · 46.5 KB

README.md

File metadata and controls

650 lines (453 loc) · 46.5 KB

Webhook

(webhook)

Overview

Operations related to webhook api

Available Operations

getAll

Retrieve a Webhook

Example Usage

import { Livepeer } from "livepeer";

const livepeer = new Livepeer({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await livepeer.webhook.getAll();
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { LivepeerCore } from "livepeer/core.js";
import { webhookGetAll } from "livepeer/funcs/webhookGetAll.js";

// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await webhookGetAll(livepeer);

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
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.GetWebhooksResponse>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

create

To create a new webhook, you need to make an API call with the events you want to listen for and the URL that will be called when those events occur.

Example Usage

import { Livepeer } from "livepeer";
import { Events } from "livepeer/models/components";

const livepeer = new Livepeer({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await livepeer.webhook.create({
    name: "test_webhook",
    projectId: "aac12556-4d65-4d34-9fb6-d1f0985eb0a9",
    events: [
      Events.StreamStarted,
      Events.StreamIdle,
    ],
    url: "https://my-service.com/webhook",
    sharedSecret: "my-secret",
    streamId: "de7818e7-610a-4057-8f6f-b785dc1e6f88",
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { LivepeerCore } from "livepeer/core.js";
import { webhookCreate } from "livepeer/funcs/webhookCreate.js";
import { Events } from "livepeer/models/components";

// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await webhookCreate(livepeer, {
    name: "test_webhook",
    projectId: "aac12556-4d65-4d34-9fb6-d1f0985eb0a9",
    events: [
      Events.StreamStarted,
      Events.StreamIdle,
    ],
    url: "https://my-service.com/webhook",
    sharedSecret: "my-secret",
    streamId: "de7818e7-610a-4057-8f6f-b785dc1e6f88",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request components.WebhookInput ✔️ 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.CreateWebhookResponse>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

get

Retrieve a webhook

Example Usage

import { Livepeer } from "livepeer";

const livepeer = new Livepeer({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await livepeer.webhook.get("<id>");
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { LivepeerCore } from "livepeer/core.js";
import { webhookGet } from "livepeer/funcs/webhookGet.js";

// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await webhookGet(livepeer, "<id>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
id string ✔️ N/A
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.GetWebhookResponse>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

update

Update a webhook

Example Usage

import { Livepeer } from "livepeer";
import { Events } from "livepeer/models/components";

const livepeer = new Livepeer({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await livepeer.webhook.update("<id>", {
    name: "test_webhook",
    projectId: "aac12556-4d65-4d34-9fb6-d1f0985eb0a9",
    events: [
      Events.StreamStarted,
      Events.StreamIdle,
    ],
    url: "https://my-service.com/webhook",
    sharedSecret: "my-secret",
    streamId: "de7818e7-610a-4057-8f6f-b785dc1e6f88",
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { LivepeerCore } from "livepeer/core.js";
import { webhookUpdate } from "livepeer/funcs/webhookUpdate.js";
import { Events } from "livepeer/models/components";

// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await webhookUpdate(livepeer, "<id>", {
    name: "test_webhook",
    projectId: "aac12556-4d65-4d34-9fb6-d1f0985eb0a9",
    events: [
      Events.StreamStarted,
      Events.StreamIdle,
    ],
    url: "https://my-service.com/webhook",
    sharedSecret: "my-secret",
    streamId: "de7818e7-610a-4057-8f6f-b785dc1e6f88",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
id string ✔️ N/A
webhook components.WebhookInput ✔️ N/A
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.UpdateWebhookResponse>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

delete

Delete a webhook

Example Usage

import { Livepeer } from "livepeer";

const livepeer = new Livepeer({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await livepeer.webhook.delete("<id>");
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { LivepeerCore } from "livepeer/core.js";
import { webhookDelete } from "livepeer/funcs/webhookDelete.js";

// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await webhookDelete(livepeer, "<id>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
id string ✔️ N/A
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.DeleteWebhookResponse>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

getLogs

Retrieve webhook logs

Example Usage

import { Livepeer } from "livepeer";

const livepeer = new Livepeer({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await livepeer.webhook.getLogs("<id>");
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { LivepeerCore } from "livepeer/core.js";
import { webhookGetLogs } from "livepeer/funcs/webhookGetLogs.js";

// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await webhookGetLogs(livepeer, "<id>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
id string ✔️ N/A
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.GetWebhookLogsResponse>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

getLog

Retrieve a webhook log

Example Usage

import { Livepeer } from "livepeer";

const livepeer = new Livepeer({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await livepeer.webhook.getLog("<id>", "<value>");
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { LivepeerCore } from "livepeer/core.js";
import { webhookGetLog } from "livepeer/funcs/webhookGetLog.js";

// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await webhookGetLog(livepeer, "<id>", "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
id string ✔️ N/A
logId string ✔️ N/A
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.GetWebhookLogResponse>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

resendLog

Use this API to resend the same webhook request. This is useful when developing and debugging, allowing you to easily repeat the same webhook to check or fix the behaviour in your handler.

Example Usage

import { Livepeer } from "livepeer";

const livepeer = new Livepeer({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await livepeer.webhook.resendLog("<id>", "<value>");
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { LivepeerCore } from "livepeer/core.js";
import { webhookResendLog } from "livepeer/funcs/webhookResendLog.js";

// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await webhookResendLog(livepeer, "<id>", "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
id string ✔️ N/A
logId string ✔️ N/A
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.ResendWebhookResponse>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /