+ Reply to Thread
Results 1 to 21 of 21

VBA - downloading JSON from API with password

  1. #1
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    VBA - downloading JSON from API with password

    I had this code written for me to extract JSON files. It has been exactly what I need until now.
    The data I'm trying to pull is from the API from a site I have a paid subscription to.
    I have a username/login and not an API key.
    When I access the API link through a browser I am logged into I am able to retrieve all the data, but when I try to use my VBA code some of the data is restricted and is left off the JSON file.
    I have been googling to find any info, but my lack of coding skills limits me.
    The only thing I could decipher was I may need the login cookie data.

    Does anyone know any options I have ?

    here is the code:

    Please Login or Register  to view this content.
    here is the login page:

    HTML Code: 
    I have also attached my excel file
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA - downloading JSON from API with password

    Difficult to give you an insight as the site requires an authorisation to access it and can't see the underlying data. The data source might have changed or the code which retrieves the JSON might have have bugs.

  3. #3
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    wanted to add a little more info:

    I found the API by inspecting the data in the network tab on my Firefox browser

    here is the link to the actual webpage
    HTML Code: 
    here is the link to the api
    HTML Code: 
    there is a lot of data available but you need to be logged in to remove the restricted data

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA - downloading JSON from API with password

    It looks like, you are retrieving a text file rather than a JSON as I could not see JSON code. Suggestion: download the text file and see what it looks like.

  5. #5
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    nope, its defiantly a JSON file.

    I am attaching two JSON files (in ZIP)
    1 - from my VBA
    2 - from my Firefox (logged in)
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA - downloading JSON from API with password

    Okay! But I do not see JSON's parser code

  7. #7
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    I don't know about the parser code. All I know what kind of file I can download when extracting the data from the API.

    Thanks anyways.
    Hopefully someone else has a suggestion.

  8. #8
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    when viewing the network tab while inspecting the page with my firefox browser i notice the cookie information is different when im logged into the site, compared to when im not.

    heres the cookie info

    Please Login or Register  to view this content.
    i also attached a picture
    Attached Images Attached Images
    Last edited by Josephrandall; 01-19-2022 at 11:41 AM.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA - downloading JSON from API with password

    If the data is in JSON format, you need a JSON parser. In other words, once you load the data as one big junk(What you have attached), you need to extract the data using either text parser or JSON. The code appears to use text parser, not JSON.

  10. #10
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    I don't have any issue viewing the data inside in the file.
    The problem I have is not all of the data goes in the file without the login details

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA - downloading JSON from API with password

    Okay! This is just my guess. There is a reason for the API. APIs usually have JSON file, hence for my suspicion that the code is not accessing the right page as the code does not include an API line.

  12. #12
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    what i think needs to happen is: my login details are in the cookie data, and i need to get these details incorporated into my VBA.

    this is from the cookie details

    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA - downloading JSON from API with password

    Yes, you might be right. The issue is always: you can't disclose the logging credentials and no one could help to read the code with out accessing the site. Effectively, you are on your own, unfortunately.
    Sorry!

  14. #14
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    if someone is willing to help they can pm me and i can create a temporary password for them.

  15. #15
    Valued Forum Contributor
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (24 H2) 64 Bit
    Posts
    1,187

    Re: VBA - downloading JSON from API with password

    Are you OK if the Json data in the API link provided in your message #3, dumped into Excel sheet?

  16. #16
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    Haluk - I would like the data to be saved to my hard-drive which then i can later dump into excel

  17. #17
    Valued Forum Contributor
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (24 H2) 64 Bit
    Posts
    1,187

    Re: VBA - downloading JSON from API with password

    OK... then try this;

    Note that, the JSON file file will be saved in the folder where the Excel file is present. So, the Excel file must be saved before running the code.

    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    sorry haluk - this doesn't solve my issue with the restricted data.

    i need to add the cookie data from post #8 into the request header when i call for the json file

  19. #19
    Valued Forum Contributor
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (24 H2) 64 Bit
    Posts
    1,187

    Re: VBA - downloading JSON from API with password

    I couldn't see the cookie in response headers....

    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    i pulled this info from the postman app
    maybe it will help

    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    01-20-2015
    Location
    NB, Canada
    MS-Off Ver
    365
    Posts
    164

    Re: VBA - downloading JSON from API with password

    considering I'm looking to create an automated system which will pull multiple files the only consistent i see in the cookie response header is the premium key.

+ 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. Parsing JSON
    By Lana74 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 08-28-2020, 09:01 PM
  2. JSON object in CSV
    By markhad in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2020, 03:26 AM
  3. Edit JSON parser code to add function to write JSON file
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-16-2020, 09:28 PM
  4. [SOLVED] Trouble with VBA-JSON
    By stusic in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-07-2017, 06:48 AM
  5. Replies: 9
    Last Post: 12-23-2016, 10:54 PM
  6. Excel VBA-JSON Example
    By manofcheese in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-28-2016, 11:52 AM
  7. Entering a username and password while downloading a file in a Excel macro
    By koltregaskes in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2011, 08:44 AM

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