How to take a screenshot in Google Sheets?

This is a tutorial that explains how to take a screenshot in Google Sheets and how to automate bulk screenshot processes.

How to take a screenshot in Google Sheets?
🤔
This is a tutorial that explains how to take screenshots with Google Sheets and GetScreenshot. GetScreenshot is a paid service that starts at 5 USD a month.

One common task that people often want to perform on their Google Sheets, is the ability to take a screenshot of a URL that is inserted in the Google Sheet.

For example, let's imagine you have to track a series of Search Engine Result Pages (SERPs) and for the purpose of doing that, you have a Google Sheet with all the URLs of those SERPs.

Now, let's imagine that you want to get visual evidence of your positions in those SERPs and for that, you would like to take screenshots of all those URLs.

To achieve this you can use a Screenshot API such as GetScreenshot or similars. You can create a script inside the Google Sheet that creates a function that takes a webpage URL and then screenshots it and serve the screenshot back to a cell in your Google Sheet.

For the purpose of this tutorial, we will use our own Screenshot API (GetScreenshot) but you're free to adapt the code provided before with any screenshot API of your choice.

Steps to Create a Google Sheets Screenshot Function

1) Create the function in Google AppScript

To accomplish this first you need to go to Google Sheets and open the Script editor. You can do this by clicking Tools > Script Editor in the top bar.

Once you are in Script Editor you will see a screen like the following one:

Simply delete the boilerplate code and paste the following function into the Script Editor:

// You need to replace the API_KEY value with an actual API Key from GetScreenshot.
// You can sign-up for an account at https://getscresenshot.rasterwise.com to get an API Key.

var API_KEY = "Your-API-Key"
function retrieveScreenshot(url) {
 var apiEndpoint = `https://api.rasterwise.com/v1/get-screenshot?apikey=${API_KEY}&url=${url}`;
 // Create our json request, w/ text, language, type & encoding
  var nlData = {
   document: {
     type: 'PLAIN_TEXT',
     language: 'en',
   }
  }   ;
 //  Package all of the options and the data together for the call
 var nlOptions = {
   method : 'GET',
 };
  
 //  And make the call
 var response = UrlFetchApp.fetch(apiEndpoint, nlOptions);
 var jsonified = JSON.parse(response).screenshotImage;
 var stringA = JSON.stringify(jsonified);
 return stringA;
};

Your script editor should look like this:

Now simply save your function by clicking on the save button and close the editor:

2) Invoke New Function from Your Google Sheet

Now that you have a function to retrieve screenshots, you just need to use it on your Google Sheet. If you go to your Sheet you will be able to call the function the same way you call some other standard function, e.g +SUM(). Usually, the function doesn't show up in the typeahead suggestions, but it's there! Just call it the same way it was named in the script. In this case that was: retrieveScreenshot(URL)

For the URL you can pass anything. It can be the content of another cell or a URL you want to pass verbatim into the function. When you hit enter the sheet will retrieve the screenshot.

It will read Loading... for a moment and then the screenshot URL will show up:

One final important recommendation is once you’re done with the retrieval process to copy and paste only the values of retrieved URLs in the same column. This means selecting the whole column and right-click copy the whole selection and paste in the same position as Values Only.

If you don’t do this the next time you open the Google Sheet, it will attempt to retrieve screenshots again for all the URLs you previously took a screenshot of. Unless that’s what you want in your functionality this will turn out in new API calls counted against your quota.

That's it! You now have a workflow to take a screenshot on Google Sheets.

If you want to give this a try visit https://www.getscreenshotapi.com and use code FREE5 to get a 1-Month free trial on the Lincoln Plan.