Importjson from api (post)

I have been trying to access an api to import json data from a interesting API (from to Google sheets - but having troubles doing a json post. Anyone that can help me out there - fx @Jeff_Hager @ThinhDinh?

I have added a new function to Brad Jaspers importJSON

The function is:

function ImportJSONBasicAuthentication3() {
var url = “”;
var query = “/RawText”;
var username = “Apikey”;
var password = “<password>”;
var parseOptions = “noHeaders”;
var fetchOptions = {
‘headers’ : {
‘Authorization’ : 'Basic ’ + Utilities.base64Encode(username + ‘:’ + password)
//‘method’ : {‘post’},
‘body’ : {
‘imageFile’ : ‘
muteHttpExceptions: true
return ImportJSONAdvanced(url, fetchOptions, query, parseOptions, includeXPath_, defaultTransform_);

Expected result:

“Successful”: true,
“BarcodeType”: “QR_CODE”,
“RawText”: “

Gonna ask an obvious question first. Have you obtained an api key?

1 Like

What result do you see when you try to run it?

@Jeff_Hager yes I got that. Just didn’t want to share in the community :stuck_out_tongue_winking_eye:

@ThinhDinh it says #ref. The path to the info in the response isn’t correct. But I think actually it is ok. I think that it is the post method that isn’t described correct. Or maybe the way the image is described as the api expects a form. I could DM the actual key

1 Like

@Krivo did you manage to get this working? (if not, I may be able to help)

1 Like

The script king is here, I hope you will be able to help him because I didn’t manage to get this to work.

1 Like

@Darren_Murphy I never got it to work. I would be awesome if it was possible to use post operations

1 Like

I’ve not used ImportJSON before, but I have done a lot of JSON API integration with GSheets using both GET and POST methods.

Just looking at your code, you seem to be missing some options.
For example, you definitely need to include 'method' : 'post' (I notice you have that commented out), and you would normally have a 'payload' option with a POST method.
Also, imageFile isn’t a recognised parameter, is that defined by the API?

If you haven’t already, I’d recommend studying the Apps Script documentation for UrlFetchApp.
If you’re still stuck after that and willing to share your API key with me privately, I’d be happy to have a fiddle and see if I can get it working.

1 Like

As per PM exchange with @Krivo, the following should work:

function scan_barcode() {
  var image_url = '';  
  var image_blob = UrlFetchApp.fetch(image_url).getBlob();
  var api_endpoint = '';
  var api_key = '<YOUR API KEY>';
  var form = {
    imageFile : image_blob,
  var options = {
    method : 'POST',
    payload : form
  options.headers = {
    Apikey : api_key,
    contentType : 'application/json',
  var response = UrlFetchApp.fetch(api_endpoint, options);
  var json = response.getContentText();


Sorry if I’m asking in the wrong place,

I’m looking for a way to make a post request, I’m not a lot familiar with coding language, is it possible atm to make a post request in glide?

You should probably try to explain what you want to achieve.

1 Like

Upload pictures to external service