Apps Script UrlFetchApp API, Get JSON data, Build Google Sheets Function, Advanced Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ก.ย. 2017
  • Learn how to use UrlFetchApp Class to import external data to Goole Sheets or use it otherwise in Google Apps Scripts. This tutorial will also walk though creating UDF (user defined function) in Google Sheets, JSON parse in JavaScript and other related topics.
    You can find the final code here
    www.chicagocomputerclasses.co...
    Google Sheets
    www.google.com/sheets/about/
    Company Page
    www.chicagocomputerclasses.com/

ความคิดเห็น • 117

  • @jervimagpantay4366
    @jervimagpantay4366 3 ปีที่แล้ว +16

    The best teacher on youtube! You should get an award. :)

  • @Fredsiika
    @Fredsiika 6 ปีที่แล้ว

    Thanks for posting this video. You literally saved me 2 hours of frustration. Well done.

    • @tomisinabimbola3336
      @tomisinabimbola3336 4 ปีที่แล้ว

      Please I need assistance on a google app script.

  • @jodhvirsingh8677
    @jodhvirsingh8677 3 ปีที่แล้ว +2

    Absolutely brilliant...your best video...was looking for something like this for a long time

  • @brandonpillay9025
    @brandonpillay9025 5 ปีที่แล้ว

    Well-put-together. Worth the subscription!

  • @gari981
    @gari981 6 ปีที่แล้ว

    Excellent Video. Very good and clear explanations about API calls, and JSON object data extraction.

  • @ChunderHorse
    @ChunderHorse 4 ปีที่แล้ว +1

    Exactly what I was looking for

  • @moellerseo
    @moellerseo 4 ปีที่แล้ว

    Mind blown! awesome stuff! thanks

  • @evil_inside1332
    @evil_inside1332 11 หลายเดือนก่อน

    exactly what i was searching for, thanks

  • @0911jedi
    @0911jedi 3 ปีที่แล้ว +1

    Thanks a lot for a very important learning 🙏

  • @MicahJohns
    @MicahJohns 3 ปีที่แล้ว

    Thank you so much for posting this

  • @bobykumar3960
    @bobykumar3960 2 ปีที่แล้ว

    .एक टिप्पणी कहती है कि आप सबसे अच्छे शिक्षक हैं .... आप अनमोल हैं ..... उन लोगों के लिए जो ... यूट्यूब से भाषा सीखते हैं

  • @paulhewett8376
    @paulhewett8376 6 ปีที่แล้ว +1

    Great function. Thanks.

  • @denicolas260
    @denicolas260 6 ปีที่แล้ว

    Excelenteeeee es lo que buscaba

  • @clovispimentel572
    @clovispimentel572 ปีที่แล้ว

    You're amazing! A reference for us!

  • @mikemccartneyable
    @mikemccartneyable 5 ปีที่แล้ว +15

    Superb. One thing not covered is that sometimes the JSON has some of its data wrapped in an array with square brackets. This can result in an "undefined" error appearing when trying to access the data. Each array item needs to be opened before the data can be accessed by using ["data"][0] or ["data"][n] where n is being generated by a for loop to run through the entire array contents.

    • @Laura-zt8lx
      @Laura-zt8lx 5 ปีที่แล้ว +3

      THANK YOU!!

    • @erikiepeters
      @erikiepeters ปีที่แล้ว

      i just want you to know that this comment saved me probably like a few hours. i finally got there. it is weird to have an array like that within a object.

  • @DivitKalem
    @DivitKalem 4 ปีที่แล้ว +1

    Amazing. Thanks a lot.

  • @hadireg
    @hadireg 5 ปีที่แล้ว

    Awesome video! Thnx !

  • @kalidsherefuddin
    @kalidsherefuddin 11 หลายเดือนก่อน

    The great course

  • @billyhenrylopez519
    @billyhenrylopez519 ปีที่แล้ว

    You rock dude!!
    I've been learning a lot with your videos
    can you make a video of how to use the Smartsheet API in google app script?
    I will love that

  • @elysel9424
    @elysel9424 6 ปีที่แล้ว

    omg this makes my life so much easier!

  • @TheAbdAllah13
    @TheAbdAllah13 6 ปีที่แล้ว

    hello thank you for your great tutorials i learn a lots from you :)
    I'm a beginner in the scripting and i want to know if you can help me please to adapt this script to my needs. In fact i have a list of keywords in a spreadsheet column and i would like to use a script to search them one by one in google search and among the result obtained in the first page of search I would like to know if a "Specific word "(e.g "Time ")exists in all the page not only in the titles (it is as if I made CTRL + F and see the result) then if the result> 0 return "yes" in another column

  • @KingKong7658
    @KingKong7658 6 ปีที่แล้ว +1

    Excellent tutorial and teaching style. One issue I had (uncertain if an error with my code): When my xpath is for example data/stream1a/stream1b where stream1b does not exist, the error handler works 100% and returns "Node not available". However if I go for a deeper level in which the parent level does not exist like: data/stream1a/stream1b/stream1c then the error handler does not catch it - it throws an execution error.

  • @ChrisWherley
    @ChrisWherley 6 ปีที่แล้ว +1

    I have learned a great deal from your videos and have some ideas of things I would like to experiment with.
    One project would be connecting to Twitter API to be able to parse URLs for the image of a post and then be able to use that insert the image in a Slide. Do you have some knowledge or resources to share about connecting Apps Script to Twitter API?

  • @ianfinlayAustralia
    @ianfinlayAustralia 6 ปีที่แล้ว

    I found what I needed 5min in to the Video !- Thank you PS: I love that you speech-to-text.
    what package are you using for that?

    • @garybenezat3775
      @garybenezat3775 5 ปีที่แล้ว

      how did you do please? I'm looking for a way to insert xpath please

    • @bang-naim
      @bang-naim ปีที่แล้ว

      It's his natural voice 🥲

  • @akan57
    @akan57 5 ปีที่แล้ว

    very useful thank you. what if the remote server had a username/password for the query, I am struggling with Apache Solr.

  • @osmosebranding
    @osmosebranding 4 ปีที่แล้ว +1

    TY VERY MUCH U MADE ME SAVE HUNDRED OF HOURS! CAN U HELP ME USE FETCH FOR ZIPPED XTML DIRECT TO GOOGLE SHEETS?

  • @ianfinlayAustralia
    @ianfinlayAustralia 6 ปีที่แล้ว +6

    could I ask you to do a video on html data and xpath and apps script ;)
    .

  • @giamar3026
    @giamar3026 4 ปีที่แล้ว

    Hi!, need help on something: how can i measure the request by second as i have a system built on google app script, we are 20 usersusing it filling a form that download a big array of 150 elements. The system blocked for maybe 1 hour and after works again. I would like to see why but as i'm new on this i don't knnow how to check if we went over the 6 min allowed by google

  • @narnold113
    @narnold113 6 ปีที่แล้ว

    Great video. I would now like to have the data imported from the API URL update every minute. When I set a trigger, it does not do anything. How can I proceed with it updating every minute? Thanks in advance.

  • @rjmgcrypto9122
    @rjmgcrypto9122 6 ปีที่แล้ว +6

    This function works great!
    How can I set this function to reload or refresh the data every x amount of time? could you suggest a tutorial or link where I can find this?

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  6 ปีที่แล้ว +2

      You have to use google sheets events to refresh your formula. Look into Time-driven triggers developers.google.com/apps-script/guides/triggers/installable

  • @FAOU
    @FAOU 2 ปีที่แล้ว

    Thank you for sharing your knowledge!
    Please consider making a video like this (in depth) explaining how to mail merge emails with data from a Google Form/Sheet and SendGrid's API using Google Apps Script. The code should only send emails for new submissions. We need your help please.

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  2 ปีที่แล้ว

      Long story short, it should be a rest API request using URLFetchApp. As far as what the exact request structure should be, I would have to dig their documentation for at least a couple of hours to figure it out. Sorry, it's too niche for me to spend time on.

  • @Harekrishnatrading
    @Harekrishnatrading 3 ปีที่แล้ว

    Thank you for all the tutorials
    I am trying to fetch api from a software api when I am fetching it it's showing Authorization error
    I have user nam id and password but how I authorize it in google sheet please help me I am trying to solve this from last one month but not get any solution please help me.

  • @emanuelegiasi8784
    @emanuelegiasi8784 4 ปีที่แล้ว

    First of all thanks for your excellent videos, they are really helpful!!!
    I would like to ask you if is possible to import data that I normally get using "curl -d" command from terminal?
    Thanks a lot

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  4 ปีที่แล้ว

      What does curl -d do? is it download?

    • @emanuelegiasi8784
      @emanuelegiasi8784 4 ปีที่แล้ว

      ​@@ExcelGoogleSheets in this specific case when I call from terminal it gives me this:
      {
      "names": [
      "timestamp",
      "device_id",
      "topic",
      "message"
      ],
      "rows": [
      [
      "2020-01-20 07:57:09",
      "device1",
      "events",
      "{\"name\":\"created\"}"
      ],
      [
      "2020-01-20 08:04:36",
      "device1",
      "events",
      "{\"name\":\"created\"}"
      ]
      ]
      }
      My problem is that I don't know how to use the command:
      curl -d "query=select * from data limit 2" *****
      in Google Sheets.
      Thank you.

  • @farhanmuntaqo
    @farhanmuntaqo 2 ปีที่แล้ว

    What if for example I have a range containing a set of package tracking numbers I got from delivery services and I want to make the adjacent range to show me the last status of the package using a rest api. Kind of getting data from api based on data we have on Google Sheets. Any help would be great thanks...

  • @jiitmahe2584
    @jiitmahe2584 4 ปีที่แล้ว

    How can overcome the time limit at a urlFetchApp.fetch method, Because in my app take this time at above 30s in particular API. At this time not handle exception using try/catch.

  • @MrEgadwi
    @MrEgadwi 2 ปีที่แล้ว

    Great tutorial!, say could you make a tutorial series on like user login with authentication and all thanks!

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  2 ปีที่แล้ว

      Unlikely, it would be 10 hours long video just to make the authentication system and very few people would be interested in watching that. It's simply not worth the time spent, not even to mention that it would negatively impact the channel because that's what TH-cam does when people don't watch these videos.

  • @victorquintero7950
    @victorquintero7950 6 ปีที่แล้ว

    hola saludos y gracias... podrias explicar como hacer un snapshop u bufer para evitar el error de tiempo de ejecucion es decir evitar el limite de tiempo de ejecucuion ....

  • @visualx3881
    @visualx3881 ปีที่แล้ว

    Amazing video ! Is there a script to have automatically a blank space after every 15 rows please

  • @tedjammers
    @tedjammers 5 ปีที่แล้ว

    Thank you for this video! Very cool stuff. I have an API that requires a key. I have that key but when I use the UrlFetchApp.fetch(url), the API doesn't authorise the user. The API key is baked into the URL. Any idea how to get around this? Thanks!

    • @sneezer_0
      @sneezer_0 ปีที่แล้ว +1

      hey, I don't know if this is still useful, but you can pass the key in the second argument of UrlFetchApp(url,options). Create a var of options with the appropriate descriptor for the key. It's in the docs

  • @itdoeshurt
    @itdoeshurt ปีที่แล้ว

    impressive, how to get gold rates, and if fails get it from another link?

  • @TungHoang-in6hf
    @TungHoang-in6hf 5 ปีที่แล้ว

    How can I import data (in CSV file if downloaded) in Google Trend into Sheets?

  • @sieja
    @sieja 3 ปีที่แล้ว

    Thanks for the tutorial.
    I have a problem with error
    Exception: Attribute provided with no value: url
    aIMPORTJSON
    @
    I have done everything like on the video.
    For some reason it screams that url is undefined :/
    any help?

  • @aumerrpmp761
    @aumerrpmp761 6 ปีที่แล้ว

    Hi,
    the function .split() isnt available for me, is it possible I have to download extra add-on, was it depracated? Thank you

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  6 ปีที่แล้ว +1

      No, it's built in javascript function. If it doesn't work that usually means the variable is not a string, it will only show up for string type.

  • @thomasprevarin5840
    @thomasprevarin5840 5 ปีที่แล้ว +4

    Thanks for the video, what if the the external api I getting data from requires authentication? Would I pass the secret token to the "UrlFetchApp.fetch" method?

    • @TheresaWheeler
      @TheresaWheeler 4 ปีที่แล้ว

      Thomas Prevarin it would be its own function in the script.

  • @calebdoyel164
    @calebdoyel164 4 ปีที่แล้ว

    Thank you for all your videos on google apps. They are so freaking helpful it's ridiculous. I am having a problem where a function is updating a cell and the rest of the function relies on the updated data in the cell but when it runs the cell doesn't update fast enough and the function misses the updated data. I read something about utilities.sleep(milliseconds) and I use about 2000ms which should be plenty of time, but when I put it into my function nothing happens. When I type "Utilities." no other utilities popup after the period. Any ideas?

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  4 ปีที่แล้ว

      Unfortunately this can be 1000 different things.

    • @calebdoyel164
      @calebdoyel164 4 ปีที่แล้ว +1

      @@ExcelGoogleSheets Yes, I understand. I found a solution pretty easily after posting here lol.

    • @sultanularefin5674
      @sultanularefin5674 3 ปีที่แล้ว

      @@calebdoyel164 you may share with us your solution ? that extremely help us also.

    • @calebdoyel164
      @calebdoyel164 3 ปีที่แล้ว

      @@sultanularefin5674 In the end I used "Utilities.sleep(10000)" the number is in milliseconds so the function pauses for 10 seconds which is enough time to update the sheet.

  • @milkeshpotdar5451
    @milkeshpotdar5451 6 ปีที่แล้ว

    how do I export data from google spreadsheet to my web app ?

  • @IvanMohnatov
    @IvanMohnatov 6 ปีที่แล้ว

    Hello, I'm from Russia.
    I liked your code.
    but when I recreated it with me, this entry (= importjson ("api.fixer.io/latest?base=USD", "rates") in the cell produces a syntax error on all variants.
    To tozhe when I start to write (= import) that to me does not give out a variant for sampling of the punctured function.
    and still logged
    Perhaps I have somehow not properly tuned Google Sheets.
    tell me possible options?

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  6 ปีที่แล้ว

      make sure you save the script editor file, reload the spreadsheet & don't use spaces between =importjson(

  • @johndeoresearch2251
    @johndeoresearch2251 4 ปีที่แล้ว

    that is an example of get request... how about post request?

  • @tazulislam2698
    @tazulislam2698 2 ปีที่แล้ว

    is it posible to add bulk data using webapp api? If posible please help!

  • @luiscontreras7273
    @luiscontreras7273 ปีที่แล้ว

    Do you know if it is possible to do it the other way around? It is that from postman it reads the API but when I try to use it from appscript it gives me Exception: Bad request:

  • @hvhryan2888
    @hvhryan2888 3 ปีที่แล้ว

    You please help how to copy a shared google drive file on the internet to my drive using UrlFetchApp or another method. Thanks a lot. Have a nice weekend.

  • @farhanmuntaqo
    @farhanmuntaqo 2 ปีที่แล้ว

    Is it an example of webhook?

  • @erikiepeters
    @erikiepeters ปีที่แล้ว

    I wanna know what is the name of the chrome extension that you use to make JSON more readable?

  • @sohaibroomi7404
    @sohaibroomi7404 2 ปีที่แล้ว

    I am trying to get only two values (no. of reviews, no. of rating stars) from the Google maps search page, but UrlFetchApp does not seem to capture this information. Any guidance would be much appreciated? Thank you

  • @rpahlevy
    @rpahlevy 2 ปีที่แล้ว

    I got JSONInit is not defined (line 3, file "code") error when i try running myfunction

  • @haohuynh464
    @haohuynh464 3 ปีที่แล้ว

    If the json have many columns, how can we spit ?

  • @InspiringThings101
    @InspiringThings101 ปีที่แล้ว

    Has anyone tried doing this from a CRM ? Like in order to keep a spreadsheet that shows live registration data directly from a CRM that you have a log in to?

  • @abhiskek270
    @abhiskek270 4 ปีที่แล้ว

    any reason why: return(json["BTC"]["USD"]) and return(json.BTC.USD) is working
    but
    var curr = ss.getRange(i,1).getValue(); //BTC
    return(json[curr]["USD"]); and return(json.curr.USD); is not working. It throws the error: "Cannot read property 'USD' of undefined"
    I need to the pass the object as a variable from the sheet.

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  4 ปีที่แล้ว +1

      This should work return(json[curr]["USD"]);
      this should not return(json.curr.USD);

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  4 ปีที่แล้ว

      @UCFmxKyg324vY9PTvxUwdYZw That just means you have some error above that line and you need to figure out what it is. Your curr value is not BTC

  • @sultanularefin5674
    @sultanularefin5674 3 ปีที่แล้ว

    is that work with POST request as well ?

  • @alunana4447
    @alunana4447 2 ปีที่แล้ว

    How to change to data of json on Cell?

  • @tubesatsatt
    @tubesatsatt 6 ปีที่แล้ว

    Please help
    why do i get ERROR with this?
    www.bitstamp.net/api/ticker/
    =IMPORTJSON("www.bitstamp.net/api/ticker/","last")

  • @ChirathAkon
    @ChirathAkon 2 ปีที่แล้ว

    Can I get HTML Code of of a web page into Google Sheet ?

  • @ThalesTheDuck
    @ThalesTheDuck 4 ปีที่แล้ว

    No logs found. Use Logger API to add logs to your project.

  • @Thongtele
    @Thongtele 3 ปีที่แล้ว

    How to put headers in google script.

  • @wbgokarts3520
    @wbgokarts3520 2 ปีที่แล้ว

    var json = JSON.parse(content);
    isnt working how do I fix it?

  • @anphung4214
    @anphung4214 4 ปีที่แล้ว

    Does Json.parse not work for spreadsheet anymore? It kept throwing errors

  • @meri_lovelife
    @meri_lovelife 4 ปีที่แล้ว

    I want to parse html data from URL and find a id or class.
    how can i do?

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  4 ปีที่แล้ว

      check IMPORTXML function video.

    • @adrtutorial5711
      @adrtutorial5711 3 ปีที่แล้ว

      @@ExcelGoogleSheets hello, i want to ask something, can i?

  • @sacasgrigrmi8146
    @sacasgrigrmi8146 6 ปีที่แล้ว

    Isn't it easier to use an existing api such as www.sheetdb.io ?

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  6 ปีที่แล้ว +1

      2 completely different things.

    • @ciscoamine6520
      @ciscoamine6520 5 ปีที่แล้ว

      thanks man u made ma life easier hahahhaha

    • @Shkur777
      @Shkur777 4 ปีที่แล้ว

      Too much expensive

  • @SilverMiraii
    @SilverMiraii 6 ปีที่แล้ว

    Google Apps Script: You do not have permission to call fetch
    There was probably a problem while setting permission or whatever the fuck, and of course the bug will now stay there.
    This is actually the second bug from google sheets, the first one is that I'm not able to view the script from google chrome, only from firefox, and this bug has been there for months, and good luck trying to get a response from anyone on that shit.