# Importjson from api (post)

**URL:** https://community.glideapps.com/t/importjson-from-api-post/17386
**Category:** Ask for Help
**Created:** [October 20, 2020, 9:17pm UTC](https://community.glideapps.com/t/importjson-from-api-post/17386 "2020-10-20T21:17:29Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Krivo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krivo/32/5363_2.png) [@Krivo](https://community.glideapps.com/u/Krivo)
#### Post date: [October 20, 2020, 9:17pm UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/1 "2020-10-20T21:17:29Z")

</div>

I have been trying to access an api to import json data from a interesting API (from [cloudmersive.com](http://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

> <https://github.com/bradjasper/ImportJSON/blob/master/ImportJSON.gs>

The function is:

> function ImportJSONBasicAuthentication3() {  
> var url = “[https://api.cloudmersive.com/barcode/scan/image](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](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](https://qrcode.glideapp.io)”  
> }

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [October 20, 2020, 11:41pm UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/2 "2020-10-20T23:41:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [October 20, 2020, 11:42pm UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/3 "2020-10-20T23:42:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Krivo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krivo/32/5363_2.png) [@Krivo](https://community.glideapps.com/u/Krivo)
#### Post date: [October 21, 2020, 4:58am UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/4 "2020-10-21T04:58:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Krivo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krivo/32/5363_2.png) [@Krivo](https://community.glideapps.com/u/Krivo)
#### Post date: [October 21, 2020, 5:03am UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/5 "2020-10-21T05:03:35Z")

</div>

@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

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [November 13, 2020, 3:32am UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/6 "2020-11-13T03:32:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [November 13, 2020, 3:41am UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/7 "2020-11-13T03:41:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Krivo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krivo/32/5363_2.png) [@Krivo](https://community.glideapps.com/u/Krivo)
#### Post date: [November 13, 2020, 7:33am UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/8 "2020-11-13T07:33:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [November 13, 2020, 8:00am UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/9 "2020-11-13T08:00:25Z")

</div>

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](https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#fetch(String,Object)).  
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.

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [November 13, 2020, 3:00pm UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/10 "2020-11-13T15:00:48Z")

</div>

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);
}
```

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [November 13, 2020, 3:39pm UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/11 "2020-11-13T15:39:32Z")

</div>

Excellent!

---

<div class="post-metadata">

### Author: ![MaxB](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maxb/32/15623_2.png) [@MaxB](https://community.glideapps.com/u/MaxB)
#### Post date: [November 23, 2021, 10:44am UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/12 "2021-11-23T10:44:16Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Krivo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krivo/32/5363_2.png) [@Krivo](https://community.glideapps.com/u/Krivo)
#### Post date: [November 23, 2021, 7:28pm UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/13 "2021-11-23T19:28:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![MaxB](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maxb/32/15623_2.png) [@MaxB](https://community.glideapps.com/u/MaxB)
#### Post date: [December 2, 2021, 4:38pm UTC](https://community.glideapps.com/t/importjson-from-api-post/17386/14 "2021-12-02T16:38:21Z")

</div>

Upload pictures to external service
