Get High-Quality Screenshots with ScreenshotOne Public API

Are you in need of high-quality screenshots for your website or application? Look no further than ScreenshotOne! Their public API allows you to take screenshots of any website with minimal effort. In this blog post, we will explore how to use ScreenshotOne's API with JavaScript.

Prerequisites

Before we begin, make sure you have an API key from ScreenshotOne. You can sign up for one on their website. Once you have your API key, you can start using their API to take screenshots.

Getting Started

To get started, let's create a JavaScript function that takes a screenshot of a website. We will call this function getScreenshot.

async function getScreenshot(url) {
  const apiUrl = `https://api.screenshotone.com/v1/screenshot?key=<your-api-key>&url=${encodeURIComponent(url)}`;
  const screenshot = await fetch(apiUrl);
  return await screenshot.blob();
}

This function takes a url parameter and returns a promise that resolves to a screenshot of the website. Notice that we are using the encodeURIComponent function to encode the URL. This is necessary to make sure that the URL is properly formatted for the API request.

Example Usage

Now that we have our getScreenshot function, let's see how to use it. Here's an example of how to take a screenshot of google.com:

const url = 'https://www.google.com';
getScreenshot(url)
  .then(blob => {
    const img = document.createElement('img');
    img.src = URL.createObjectURL(blob);
    document.body.appendChild(img);
  });

In this example, we create an image element and set its source to the screenshot blob. Finally, we append the image to the document body.

Conclusion

That's it! With just a few lines of code, you can use ScreenshotOne's API to take high-quality screenshots of any website. Remember to always keep your API key secure and never give out your private key. Happy screenshotting!

Related APIs

Public APIs — A directory of free and public apis

Built by @mddanishyusuf