How do I do a pin search with pinterest-node-api?

236 views Asked by At
import Pinterest from "pinterest-node-api";
const client = new Pinterest('pina_AMAS3KIWABUBCAA');

  try {
    // Search for pins with the keyword
    const res = await client.request('/pins', {
      method: 'GET',
      params: {
        query: `${keyword} ${modifier}`,
        fields: 'id,note,image'
      }
    });
    const pins = res.data;
  
    // Comment on each pin
    for await (const pin of pins) {
      await client.comment(pin.id, variation);
      console.log(`Commented on pin: https://pinterest.com/pin/${pin.id}`);
    }
  } catch (error) {
    console.error(`Failed to search for or comment on pins. Error: ${error.message}`);
  }

I get client.request is not a function

I'm trying to perform an API call to search globally for pins by keyword.

The docs on their page don't give me much confidence as none of the examples worked.

1

There are 1 answers

0
chovy On BEST ANSWER
   // Search for pins with the keyword
    const searchUrl = `https://api.pinterest.com/v5/search/pins?query=${encodeURIComponent(search)}&topic_based=true`;
    const res = await fetch(searchUrl, {
      headers: {
        'Authorization': `Bearer ${key}`,
      },
    });

    const pins = (await res.json()).items;