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 = “https://builtin.com/sites/www.builtin.com/files/styles/ckeditor_optimize/public/inline-images/1_python-ocr.jpg”;

var request = “https://api.ocr.space/parse/image

// 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)
{
Logger.log(results[0]);
Logger.log(results[1]);

return results;

}
else
{
return null;
}
}

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