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,
}
);
},
});
io.waitForRequest()
waits for a request to be made to the provided URL.
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,
}
);
},
});
run()
. See
resumability for more information.url
parameter. When the URL is POSTed to, the
task will be completed and the POST request body will be returned.Hide fields
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,
}
);
},
});
Was this page helpful?