Cancel/Delete Scheduled Task

I’m able to use the New Scheduled Task as a source in my workflow to schedule events, but I can’t seem to understand how to delete/cancel a task?

I see there is a cancel/delete method in the source’s code and the scheduled task supplied an ID to use in order to delete, but how does it get called?

I tried to create a workflow from the source, but when attempting to do a test event, nothing happens. Shouldn’t I be able to send a test event and then be able to call this API url directly to fire the delete?

Something like: https://b82093686310771e4b48423e0091e927.m.pipedream.net/cancel/<ID_OF_TASK_TO_DELETE>

Thanks for any help!

Hi @help,

It seems like you’re trying to delete or cancel a scheduled task. To do this, you can use the Pipedream REST API to delete events associated with a source. You can make a DELETE request to the following endpoint:

DELETE /sources/{id}/events

You can use the start_id and end_id parameters to delete a specific event or a range of events. You can retrieve these IDs using the GET /sources/{id}/event_summaries endpoint.

Here’s an example of how to delete an event using the Pipedream REST API:

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    apiKey: {
      type: "string",
      label: "API Key",
      secret: true,
    },
    sourceId: {
      type: "string",
      label: "Source ID",
    },
    eventId: {
      type: "string",
      label: "Event ID",
    },
  },
  async run({ $ }) {
    const url = `https://api.pipedream.com/v1/sources/${this.sourceId}/events?start_id=${this.eventId}&end_id=${this.eventId}`;
    const headers = {
      Authorization: `Bearer ${this.apiKey}`,
    };

    return await axios($, {
      method: "DELETE",
      url,
      headers,
    });
  },
});

Replace the apiKey, sourceId, and eventId with the appropriate values. This code will delete the specified event from the source.

If you need further assistance, please visit https://pipedream.com/support for more support options.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

I want to cancel scheduled tasks, not delete events.

Tasks are scheduled using this API:

I figured it out.

To delete scheduled tasks POST to the source endpoint with /cancel url param:

https://<scheduled-task-source-id>.m.pipedream.net/cancel

In the body send the id of the scheduled task that was provided when the task was scheduled:

{
  id: "id-of-the-scheduled-task"
}
2 Likes

Awesome, thanks for sharing!