Search code examples
zapierzapier-cli

zapier performResume step not being waited for / run


I'm following the docs in zapier regarding the callbackUrl https://platform.zapier.com/cli_docs/docs#zgeneratecallbackurl however cannot seem to get the performResume step to be run. The zap I'm creating based on this integration also does not seem to wait for the callbackUrl to be hit.

const createScreenshot = (z, bundle) => {
  const callbackUrl = z.generateCallbackUrl();
  const promise = z.request({
    url: 'https://myapi.com/v1/render',
    method: 'POST',
    params: {},
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: {
      ...bundle.inputData,
      webhook_url: callbackUrl
    },
    removeMissingValuesFrom: {},
  });
  z.console.log("Returning from perform / createScreenshot");
  return promise.then((response) => ({ ...response.data, waiting_for: "performResume" }));
const onScreenshotFinished = (z, bundle) => {
  z.console.log("In performResume / onScreenshotFinished", bundle.cleanedRequest);
  const responseBody = bundle.cleanedRequest;
  let screenshotUrl;

  if (responseBody.event === "render.succeeded") {
    z.console.log("render was processed successfully", responseBody);
    screenshotUrl = responseBody.result.renderUrl;
    return { screenshotUrl, ...responseBody };
  }

  z.console.log("render was not processed", responseBody);
  throw z.errors.Error("Screenshot was not successful");
}
module.exports = {
  operation: {
    perform: createScreenshot,
    performResume: onScreenshotFinished,
    ...
  }
}

Solution

  • We talked through this question (and its solution) on GitHub (zapier/zapier-platform#398), but to summarize for SO readers:

    When setting up a resumable Zap, the editor uses the sample to populate the data in the callback. No actual waiting happens during the setup process. Once the zap is live, it works like normal.

    So, to implement:

    • perform should return sample data that matches the data the "resume" webhook sends
    • performSubscribe can read that data and operate normally

    See the GH issue for more info.