diffbot-api-node
TypeScript icon, indicating that this package has built-in type declarations

0.0.13 â€ĸ Public â€ĸ Published

diffbot-api-node

npm npm bundle size npm license github last commit

Diffbot-API-Node is a Promise-based library to use the Diffbot REST APIs.

Features

Currently supports the following features:

  • Analyze (with HTML POST support)
  • Article (with HTML and plaintext POST support)
  • Discussion (with HTML POST support)
  • Image (with HTML POST support)
  • Product (with HTML POST support)
  • Video (beta) (with HTML POST support)
  • Knowledge Graph
  • Crawl
    • New (supported params: name, seeds, apiUrl, useCanonical, maxHops, maxToCrawl, maxToProcess, notifyWebhook)
    • Get (retrieve crawl job results)
    • Details (retrieve crawl job details)
    • Pause
    • Resume
    • Restart
    • Delete
  • Search

Install

npm install diffbot-api-node

Usage

const Diffbot = require('diffbot-api-node')
const diffbot = new Diffbot('your-api-key-goes-here');

Analyze API

Diffbot documentation: https://www.diffbot.com/dev/docs/analyze/

  let analyze = await diffbot.analyze({
    url: 'https://four-all-ice-creame.myshopify.com/collections/ice-cream-cubes-individual/products/ice-cream-cubes-individual',
    discussion: false,
    body: 'optional-html-post-body-goes-here',
  });
  console.log(analyze.humanLanguage);
  console.log(analyze.title);
  console.log(analyze.type);
  console.log(analyze.objects);

Article API

Diffbot documentation: https://www.diffbot.com/dev/docs/article/
Note: url is optional if including plaintext POST body

  let article = await diffbot.article({
    url: 'https://www.theverge.com/2020/8/25/21400240/epic-apple-ruling-unreal-engine-fortnite-temporary-restraining-order',
    body: 'optional-html-or-plaintext-post-body-goes-here',
  });
  console.log(article.objects[0].authors);
  console.log(article.objects[0].publisherRegion);
  console.log(article.objects[0].sentiment);
  console.log(article.objects[0].tags);

Discussion API

Diffbot documentation: https://www.diffbot.com/dev/docs/discussion/

  let discussion = await diffbot.discussion({
    url: 'https://www.theverge.com/2020/8/25/21400240/epic-apple-ruling-unreal-engine-fortnite-temporary-restraining-order',
    body: 'optional-html-post-body-goes-here',
  });
  console.log(discussion.objects[0].title);
  console.log(discussion.objects[0].posts);
  console.log(discussion.objects[0].participants);
  console.log(discussion.objects[0].sentiment);

Image API

Diffbot documentation: https://www.diffbot.com/dev/docs/image/

  let image = await diffbot.image({
    url: 'https://www.deviantart.com/up-tchi/art/Coral-village-852927725',
    body: 'optional-html-post-body-goes-here',
  });
  console.log(image.objects[0].title);
  console.log(image.objects[0].url);
  console.log(image.objects[0].naturalHeight);

Product API

Diffbot documentation: https://www.diffbot.com/dev/docs/product/

  let product = await diffbot.product({
    url: 'https://www.amazon.com/Resistance-Avalon-Social-Deduction-Game/dp/B009SAAV0C',
    body: 'optional-html-post-body-goes-here',
    discussion: false,
  });
  console.log(product.objects);

Video API (beta)

Diffbot documentation: https://www.diffbot.com/dev/docs/video/

  let video = await diffbot.video({
    url: 'https://www.youtube.com/watch?v=HeiPdaTQTfo',
    body: 'optional-html-post-body-goes-here',
  });
  console.log(video.objects[0].title);
  console.log(video.objects[0].html);

Knowledge Graph API

Diffbot documentation: https://docs.diffbot.com/kgapi

  // Knowledge Graph
  let kg = await diffbot.knowledgeGraph({
    query: 'type:LocalBusiness location.{country.name:"Canada" city.name:"Ottawa" isCurrent:true}'
  });
  console.log(kg.hits);
  console.log(kg.data);

Crawl API

Diffbot documentation: https://www.diffbot.com/dev/docs/crawl/api.jsp

  // Crawl (new)
  let crawl = await diffbot.crawl().new({
    name: 'my-diffbot-crawl',
    seeds: [
      'https://www.cruisebar.com.au/',
      'https://www.sydneyharbourdinnercruises.com.au/',
    ],
  });
  console.log(crawl.response);
  console.log(crawl.jobs);

  // Crawl (get)
  let crawlData = await diffbot.crawl().get({
    name: 'my-diffbot-crawl',
  });
  console.log(crawlData);

  // Crawl (details)
  let crawlDetails = await diffbot.crawl().details({
    name: 'my-diffbot-crawl',
  });
  console.log(crawlDetails.jobs);

  // Crawl (pause)
  let crawlPause = await diffbot.crawl().pause({
    name: 'my-diffbot-crawl',
  });
  console.log(crawlPause);

  // Crawl (resume)
  let crawlResume = await diffbot.crawl().resume({
    name: 'my-diffbot-crawl',
  });
  console.log(crawlResume);

  // Crawl (restart)
  let crawlRestart = await diffbot.crawl().restart({
    name: 'my-diffbot-crawl',
  });
  console.log(crawlRestart);

  // Crawl (delete)
  let crawlDeletion = await diffbot.crawl().delete({
    name: 'my-diffbot-crawl',
  });
  console.log(crawlDeletion);

Search API

Diffbot documentation: https://www.diffbot.com/dev/docs/search/

  let search = await diffbot.search({
    name: 'my-diffbot-crawl',
    query: 'type:product',
  });
  console.log(article.objects[0].title);
  console.log(article.objects[0].pageUrl);

Testing

You must make a .env file with your diffbot API token in order to run the test suite.

e.g. echo "DIFFBOT_API_TOKEN=YOURTOKENGOESHERE" > .env

Then just run mocha.

Readme

Keywords

Package Sidebar

Install

npm i diffbot-api-node@0.0.13

Version

0.0.13

License

MIT

Unpacked Size

205 kB

Total Files

11

Last publish

Collaborators

  • therealpadster