Google Apps Script question

Hi there,

I am trying to write a simple code to extract text from an image using Google Apps Script. I have spent hours and can’t get the POST method work. Can someone tell me what’s wrong with my code? Thanks!

function callOCR() {

var apiKey = “Your Key Goes Here”;
var imgUrl = “”;

var request = “

// Create the header
const headers = {
‘apikey’: apiKey

var formData = {
‘url’: imgUrl,
‘scale’: true,
‘OCREngine’: 2

var options = {
‘method’: ‘POST’,
‘headers’: headers,
‘payload’ : formData

var response = UrlFetchApp.fetch(request, options);
var data = JSON.parse(response.getContentText());
var annotations = data.responses[0].textAnnotations;
var results = annotations[0].description.split(‘\n’);

if(results != null)

return results;

return null;

Have you seen this RPA OCR script for use in It works. Maybe you can adapt it for use with Google apps, since both is Javascript?