+ Reply to Thread
Results 1 to 20 of 20

Automate Data From an API

  1. #1
    Registered User
    Join Date
    03-08-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    41

    Automate Data From an API

    Hi wonder if anyone can assist

    I have a spreadsheet (attached ) which collects start and end times for ISS Passes - a user manually enters,start and End times in to Col D and E

    Col, F,G,H and I are calculated within excel

    Col I produces a web reference like

    https://api.wheretheiss.at/v1/satell...s=1593336173.5

    If paste this into a browser it will return information in this format

    [{"name":"iss","id":25544,"latitude":48.179453792556,"longitude":-6.2230817001613,"altitude":422.01090410959,"velocity":27593.956540979,"visibility":"daylight","footprint":4517.6799214176,"timestamp":1593336173,"daynum":2459028.8908912,"solar_lat":23.24364499358,"solar_lon":40.127070726464,"units":"kilometers"}]

    I then manually cope the Latitude and longitude information into col J and K

    I do this paste into the browser and then copy and paste browser output to the xls


    Great for a few rows but eventually I will have hundreds of rows, I'm thinking how to use the Date From Web Function within excel to automate this process line by line. Any pointers really appreciated

    Regards
    John B
    Attached Files Attached Files

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Automate Data From an API

    John,

    what you need isn't really clear, as how you described it. yes you can get data from the web via excel, however it doesn't have the ability, as far as I know, for you to simply push a button and get the program to go to ''x'' number of pages in one operation and DL the info from each webpage. however, you could probably get that process done by writing a loop in code and using the get data from web feature, over and over again.

    what do you mean by this?
    Col I produces a web reference like
    furthermore, what do you mean by this?
    If paste this into a browser it will return information in this format

    [{"name":"iss","id":25544,"latitude":48.179453792556,"longitude":-6.2230817001613,"altitude":422.01090410959,"velocity":27593.956540979,"visibility":"daylight","footprint":4517.6799214176,"timestamp":1593336173,"daynum":2459028.8908912,"solar_lat":23.24364499358,"solar_lon":40.127070726464,"units":"kilometers"}]
    if you're saying that the data returned will be like in the URL you posted, those two formats and return data values are *not* the same between the 2.

  3. #3
    Registered User
    Join Date
    03-08-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    41

    Re: Automate Data From an API

    Hi Adam

    Sorry if i was not clear enough

    so each row produces a unique URL ie:https://api.wheretheiss.at/v1/satell...s=1593336173.5 and each unique will bring back the unique results ie:

    [{"name":"iss","id":25544,"latitude":48.179453792556,"longitude":-6.2230817001613,"altitude":422.01090410959,"velocity":27593.956540979,"visibility":"daylight","footprint":4517.6799214176,"timestamp":1593336173,"daynum":2459028.8908912,"solar_lat":23.24364499358,"solar_lon":40.127070726464,"units":"kilometers"}]

    and from these i want to extract these latitude":48.179453792556,"longitude":-6.2230817001613

    I am more than happy to do a few actions for each row to get the results and have them added to col j and K - currently I paste the unique URL into my web browser and then copy and paste the results into col j and k in the spreadsheet

    I have never really played around with macros but maybe thats a simpler route to follow ?


    Anyway hope this makes it a little clearer ?

    Regards

    John

  4. #4
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Automate Data From an API

    well John,

    I ran on a test on a page that you posted. this one: https://api.wheretheiss.at/v1/satell...s=1593336173.5

    and I went through the motions with powerquery. now keep in mind, I'm no PQ expert. however, after doing the basic moves with the tool, the following images depicts what came out of it. PQ is looking at the data as JSON format. and the source code of that page suggests that it IS actually that type. and it is certainly NOT in a table format via HTML, which is probably why I didn't get actual values parsed out of it. Now of course, I used PQ's splitter as did not specify a delimiter. and that could've caused the result i got. because JSON data is always delimited by something. Have you done this already?
    Attached Images Attached Images

  5. #5
    Registered User
    Join Date
    03-08-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    41

    Re: Automate Data From an API

    hi i tried something similar and it did list the results which I could see in a table, i think i did a close and load function, this may well be the way for me and as its all in excel i can record a macro do do it, i will try this and let you know

    thanks

    John

  6. #6
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Automate Data From an API

    yes you can record it. and yes, I did the "close and load" too

  7. #7
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,149

    Re: Automate Data From an API

    @john_berman;

    As an alternative, you can try this VBA code to get the JSon data.

    Note: Sample file is attached...

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Haluk; 09-26-2020 at 03:18 PM.

  8. #8
    Registered User
    Join Date
    03-08-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    41

    Re: Automate Data From an API

    Hi
    So i managed to records the steps into a macro

    1 - Copy the url from I3

    2 - Paste the url into data from Web (basic)

    3 - Click on Record

    4 - Click on convert to table

    5 - Click on Close and Load

    6 - copy lat and lng from the new table into cells J3 and K3

    7 - Delete the sheet that held the imported data

    8 - cut row 3 from sheet Source and past into sheet updated



    however when I run the macro Radio it stops with an error as its hard coded the url pastred in Step 1, I had hoped it would record that the url came from I3 rather than the actual url


    I think im close but help would be appreciated


    Regards
    John B
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    03-08-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    41

    Re: Automate Data From an API

    Hi thats interesting can this line strURL = "https://api.wheretheiss.at/v1/satellites/25544/positions?timestamps=1593336173.5" be changed to get the URL from a Cell thats on a different sheet ?

    John

  10. #10
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,149

    Re: Automate Data From an API

    If the active page is Sheet1 then put the URL in Sheet2 cell B2 as:

    Please Login or Register  to view this content.
    and change the related line to this in the VBA code:

    Please Login or Register  to view this content.

    Or; put this in Sheet2 cell B2 (formatted as "Text"):

    Please Login or Register  to view this content.
    and change the code line as:

    Please Login or Register  to view this content.
    Last edited by Haluk; 09-28-2020 at 06:53 AM.

  11. #11
    Registered User
    Join Date
    03-08-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    41

    Re: Automate Data From an API

    @haluk

    Thanks works a treat, I have added a second macro which then moves the data around and it seem to work a treat


    I have noticed an error (my doing) on the source sheet when i concat in col I and add col H its not exact it seems to add .5 sometimes consequently the data returned is not as expected


    John
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,149

    Re: Automate Data From an API

    Actually, your data in Column H has a formatting to show "0-zero" decimal places. If you change this to "2 decimal places", there will be no difference between Columns H and I.

  13. #13
    Registered User
    Join Date
    03-08-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    41

    Re: Automate Data From an API

    @Haluk

    Thanks but still a little confused

    Row 3 Col H is 1593759673 and that is the correct number

    Row 3 Col I shows 1593759673 but If I click on the cell it shows 1593759672.5 which is incorrect and so the incorrect value is passed to the URL etc


    John B

  14. #14
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,149

    Re: Automate Data From an API

    Well, in cell H3 try this and drag the formula down ...

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    03-08-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    41

    Re: Automate Data From an API

    Worked a treat - thank you for your help its really appreciated

  16. #16
    Registered User
    Join Date
    03-08-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    41

    Re: Automate Data From an API - Solved

    Thanks to all for the help

  17. #17
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,149

    Re: Automate Data From an API

    You're welcome...

  18. #18
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Automate Data From an API

    @vba_php

    You only needed to click on the records to expand the list.

    Where source is...
    Please Login or Register  to view this content.
    Then next line should be... i.e. first element of source table.
    Please Login or Register  to view this content.
    Result:
    0.JPG
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  19. #19
    Registered User
    Join Date
    03-08-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    41

    Re: Automate Data From an API

    Hi @ck76 the code you produced does not seem to work with Excel 2010 - is there anything i can do to fix this ?

    Regards
    John B

  20. #20
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Automate Data From an API

    Not sure to be honest. It should work as is with PowerQuery add-in, but I haven't had access to 2010 in years and can't test on my end.

    What sort of error message are you getting?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] automate column data
    By leo73pk in forum Excel General
    Replies: 8
    Last Post: 10-19-2017, 04:15 AM
  2. [SOLVED] How to automate, convert single column of data into two columns of data?
    By Dale Saukerson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-07-2012, 09:53 PM
  3. Automate extracting data based on existing data
    By krishnapunekar in forum Excel General
    Replies: 1
    Last Post: 07-18-2011, 08:18 AM
  4. Automate data from Web
    By MountainGoat in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-26-2008, 03:33 AM
  5. Replies: 2
    Last Post: 03-28-2008, 07:08 AM
  6. Automate import web data
    By huat08 in forum Excel General
    Replies: 0
    Last Post: 03-26-2008, 12:07 PM
  7. need to automate data into a column
    By Rick in forum Excel General
    Replies: 2
    Last Post: 09-01-2005, 05:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1