How to check for "new" item in a list of results?

Say I have an action that pulls JSON for all videos I’ve added to a “collection” on Pexels.
Whenever I trigger this, I want to check if there are any “new” items added to the collection, and, if so, take some other action on the new items. (Basically I will add a bunch of videos to my collection from time to time, then I want to take action on the new videos only.)

There is no RSS feed for the collection, so what’s the best way to accomplish this?

Thanks!

Hi @dzg,

To accomplish this, you can create a Pipedream workflow with a trigger of your choice (e.g., an HTTP trigger or a scheduled trigger). In the workflow, you can use the Pexels API to fetch the videos from your collection and compare them with the previously fetched videos to identify the new ones. Then, you can take action on the new videos as needed.

Here’s an example Pipedream component that fetches videos from the Pexels API:

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

export default defineComponent({
  props: {
    pexels: {
      type: "app",
      app: "pexels",
    },
    collectionId: {
      type: "string",
      label: "Collection ID",
    },
  },
  async run({ steps, $ }) {
    const response = await axios($, {
      url: `https://api.pexels.com/v1/collections/${this.collectionId}`,
      headers: {
        "Authorization": `${this.pexels.$auth.api_key}`,
      },
    });

    const videos = response.data.videos;
    return videos;
  },
});

To check for new items, you can store the fetched videos in a Pipedream key-value store using this.$checkpoint. You can then compare the stored videos with the newly fetched videos to identify the new ones.

For example, after fetching the videos, you can add the following code to the run method:

const previousVideos = this.$checkpoint("videos") || [];
const newVideos = videos.filter(
  (video) => !previousVideos.some((prevVideo) => prevVideo.id === video.id)
);

// Take action on new videos here

// Update the checkpoint with the latest videos
this.$checkpoint("videos", videos);

This code checks for new videos and takes action on them. After that, it updates the checkpoint with the latest videos.
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.

1 Like

Your code gives

TypeError
this.$checkpoint is not a function

Never mind, I found the docs for v2 and data stores