Krivo
October 20, 2020, 9:17pm
1
I have been trying to access an api to import json data from a interesting API (from cloudmersive.com ) 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
/*====================================================================================================================================*
ImportJSON by Brad Jasper and Trevor Lohrbeer
====================================================================================================================================
Version: 1.5.0
Project Page: https://github.com/bradjasper/ImportJSON
Copyright: (c) 2017-2019 by Brad Jasper
(c) 2012-2017 by Trevor Lohrbeer
License: GNU General Public License, version 3 (GPL-3.0)
http://www.opensource.org/licenses/gpl-3.0.html
------------------------------------------------------------------------------------------------------------------------------------
A library for importing JSON feeds into Google spreadsheets. Functions include:
ImportJSON For use by end users to import a JSON feed from a URL
ImportJSONFromSheet For use by end users to import JSON from one of the Sheets
ImportJSONViaPost For use by end users to import a JSON feed from a URL using POST parameters
ImportJSONAdvanced For use by script developers to easily extend the functionality of this library
ImportJSONBasicAuth For use by end users to import a JSON feed from a URL with HTTP Basic Auth (added by Karsten Lettow)
For future enhancements see https://github.com/bradjasper/ImportJSON/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement
This file has been truncated. show original
The function is:
function ImportJSONBasicAuthentication3() {
var url = “https://api.cloudmersive.com/barcode/scan/image ”;
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’ : ‘https://res.cloudinary.com/kristianvoigt/image/fetch/v1599185827/https://storage.googleapis.com/glide-prod.appspot.com/uploads-v2/bQioPfXCnHjAe1djmsCu/pub/HOfHjRt56v7ndkhrM1mm.png ’
},
muteHttpExceptions: true
};
return ImportJSONAdvanced(url, fetchOptions, query, parseOptions, includeXPath_, defaultTransform_);
}
Expected result:
{
“Successful”: true,
“BarcodeType”: “QR_CODE”,
“RawText”: “https://qrcode.glideapp.io ”
}
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?
Krivo
October 21, 2020, 4:58am
4
@Jeff_Hager yes I got that. Just didn’t want to share in the community
Krivo
October 21, 2020, 5:03am
5
@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
Krivo
November 13, 2020, 7:33am
8
@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 = 'https://res.cloudinary.com/kristianvoigt/image/fetch/v1599185827/https://storage.googleapis.com/glide-prod.appspot.com/uploads-v2/bQioPfXCnHjAe1djmsCu/pub/HOfHjRt56v7ndkhrM1mm.png';
var image_blob = UrlFetchApp.fetch(image_url).getBlob();
var api_endpoint = 'https://api.cloudmersive.com/barcode/scan/image';
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();
console.log(json);
}
3 Likes
MaxB
November 23, 2021, 10:44am
12
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?
Krivo
November 23, 2021, 7:28pm
13
You should probably try to explain what you want to achieve.
1 Like
MaxB
December 2, 2021, 4:38pm
14
Upload pictures to external service