# importJSON from api with user and password

**URL:** <https://community.glideapps.com/t/importjson-from-api-with-user-and-password/12287>\
**Category:** Ask for Help\
**Created:** [July 10, 2020, 9:21pm UTC](https://community.glideapps.com/t/importjson-from-api-with-user-and-password/12287 "2020-07-10T21:21:06Z")\
**Posts on this page:** 7\
**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:** [July 10, 2020, 9:21pm UTC](https://community.glideapps.com/t/importjson-from-api-with-user-and-password/12287/1 "2020-07-10T21:21:06Z")

</div>

Anyone tried to importJSON from an api where username and password is required?  
@Vicio_Sciascia @ThinhDinh

The importJSON from this source:

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

As example - I’m trying to import data from Cloudinary  
https://\<API\_KEY\>:\<API\_SECRET\>@api.cloudinary.com/v1\_1/\<cloud\_name\>/resources/search

If you succeed - how do you do it?

---

<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:** [July 10, 2020, 11:39pm UTC](https://community.glideapps.com/t/importjson-from-api-with-user-and-password/12287/2 "2020-07-10T23:39:33Z")

</div>

Can you try if the method by thadk here works?

> <https://stackoverflow.com/questions/14555134/importing-json-with-authentication-in-google-spreadsheet-campaign-monitor>

---

<div class="post-metadata">

**Author:** ![Vicio\_Sciascia](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/vicio_sciascia/32/4940_2.png) [@Vicio\_Sciascia](https://community.glideapps.com/u/Vicio_Sciascia)\
**Post date:** [July 11, 2020, 2:50pm UTC](https://community.glideapps.com/t/importjson-from-api-with-user-and-password/12287/3 "2020-07-11T14:50:33Z")

</div>

Hi @Krivo, I don’t know if I understood correctly what you are trying to do man, but to me it’s seems easier than that: according to Cloudinary documentation you have to pass your **API Key** and **API Secret** (used for the authentication) as part of the API’s URL.

So what you have to do is: go to your Cloudinary dashboard and copy your API Key, API Secret and Cloud name:

 ![Schermata 2020-07-11 alle 16.40.13](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/2X/8/868ca50e1f1a44be38d5fa073e67ac5682023355.png)

And paste them as part of API URL. Here’s an example in Postman:

 ![Schermata 2020-07-11 alle 16.43.16](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/2X/6/609611d300a985410876d941d6bd7205d7660e0a.png)

Basically your importJSON formula would be something like that:

> =ImportJSON(“https://{{api\_key}}:{{api\_secret}}@api.cloudinary.com/v1\_1/{{cloud\_name}}/resources/image”;“”;“”)

I think that the piece of script in the link posted by @ThinhDinh is useful when you have to deal with APIs with [basic auth authorization method](https://learning.postman.com/docs/sending-requests/authorization/#basic-auth), but I think it’s not our case with Cloudinary 🙂

---

<div class="post-metadata">

**Author:** ![Vicio\_Sciascia](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/vicio_sciascia/32/4940_2.png) [@Vicio\_Sciascia](https://community.glideapps.com/u/Vicio_Sciascia)\
**Post date:** [July 11, 2020, 2:54pm UTC](https://community.glideapps.com/t/importjson-from-api-with-user-and-password/12287/4 "2020-07-11T14:54:16Z")

</div>

Forgotten to say: glad to read that you’re practicing with APIs!

Kudos and keep going 🤟

---

<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:** [July 11, 2020, 7:40pm UTC](https://community.glideapps.com/t/importjson-from-api-with-user-and-password/12287/5 "2020-07-11T19:40:29Z")

</div>

@Vicio_Sciascia @ThinhDinh

It is not possible to use a simple importJSON function as it will not allow login information which can be seen by the exception

> Exception: Login information disallowed:

But the link that Thinh supplied does work.

Add this to your importJSON script

> function ImportJSONBasicAuthentication(url, query, parseOptions, username, password) {
> 
> var fetchOptions = {  
> “headers” : {  
> “Authorization” : 'Basic ’ + Utilities.base64Encode(username + ‘:’ + password)  
> },  
> muteHttpExceptions: true  
> };
> 
> return ImportJSONAdvanced(url, fetchOptions, query, parseOptions, includeXPath\_, defaultTransform\_);  
> }

and supply the username and password from Cloudinary things then work perfectly

username = API Key  
password = API Secret

> =ImportJSONBasicAuthentication(“[https://api.cloudinary.com/v1\_1/\](https://api.cloudinary.com/v1_1/%5C)/resources/search?max\_results=100&expression=folder=\<foldername\>%20AND%20filename=2\*”,“noHeaders”,\<API Key\>,\<API Secret\>)

---

<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:** [July 12, 2020, 1:27am UTC](https://community.glideapps.com/t/importjson-from-api-with-user-and-password/12287/6 "2020-07-12T01:27:43Z")

</div>

Good to hear, Krivo. I will surely use this at some point in the future. Thank you 😄

---

<div class="post-metadata">

**Author:** ![Vicio\_Sciascia](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/vicio_sciascia/32/4940_2.png) [@Vicio\_Sciascia](https://community.glideapps.com/u/Vicio_Sciascia)\
**Post date:** [July 13, 2020, 7:11am UTC](https://community.glideapps.com/t/importjson-from-api-with-user-and-password/12287/7 "2020-07-13T07:11:51Z")

</div>

You’re right @Krivo, perhaps it is some some sort of a bug? I don’t know 😕  
Anyway, good to know and thank you for sharing
