type ScreenshotResponse = {
  store: {
    location: string;
  }
}

client.defineJob({
  id: "screenshot-one-example",
  name: "Screenshot One Example",
  version: "1.0.0",
  trigger: invokeTrigger({
    schema: z.object({
      url: z.string().url().default("https://trigger.dev"),
    }),
  }),
  run: async (payload, io, ctx) => {
    const result = await io.waitForRequest<ScreenshotResponse>(
      "screenshot-one",
      async (url) => {
        await fetch(`https://api.screenshotone.com/take`, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            access_key: process.env.SCREENSHOT_ONE_API_KEY,
            url: payload.url,
            store: "true",
            storage_path: "my-screeshots",
            response_type: "json",
            async: "true",
            webhook_url: url, // this is the URL that will be called when the screenshot is ready
            storage_return_location: "true",
          }),
        });
      },
      {
        timeoutInSeconds: 300,
      }
    );
  },
});

These are the docs for Trigger.dev v2 which will be deprecated on January 31st, 2025. You probably want the v3 docs.

Parameters

cacheKey
string
required

Should be a stable and unique cache key inside the run(). See resumability for more information.

callback
function
required

A callback function that is called with a single url parameter. When the URL is POSTed to, the task will be completed and the POST request body will be returned.

options
object

Returns

Returns a Promise that resolves to the request body when the request is made.

type ScreenshotResponse = {
  store: {
    location: string;
  }
}

client.defineJob({
  id: "screenshot-one-example",
  name: "Screenshot One Example",
  version: "1.0.0",
  trigger: invokeTrigger({
    schema: z.object({
      url: z.string().url().default("https://trigger.dev"),
    }),
  }),
  run: async (payload, io, ctx) => {
    const result = await io.waitForRequest<ScreenshotResponse>(
      "screenshot-one",
      async (url) => {
        await fetch(`https://api.screenshotone.com/take`, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            access_key: process.env.SCREENSHOT_ONE_API_KEY,
            url: payload.url,
            store: "true",
            storage_path: "my-screeshots",
            response_type: "json",
            async: "true",
            webhook_url: url, // this is the URL that will be called when the screenshot is ready
            storage_return_location: "true",
          }),
        });
      },
      {
        timeoutInSeconds: 300,
      }
    );
  },
});