Connect to web API to download a JSON file

realpong
realpong New Altair Community Member
edited November 2024 in Community Q&A
I'm trying to connect to an API using the following URL.  
ratings/v1/companies/94063cdf-3bfa-4e16-b3b5-341da8b00c3c

I have a username and the password is NULL.  When I use Chrome, I enter these credentials.  When I use IE, I am presented the option to download a JSON file.

I tried using Enrich Data by Webservice but get an error "Could not access URL".  

Can anyone offer a solution?

Welcome!

It looks like you're new here. Sign in or register to get started.

Answers

  • realpong
    realpong New Altair Community Member
    edited February 2019
    https: // api.bitsighttech.com/ratings/v1/companies/94063cdf-3bfa-4e16-b3b5-341da8b00c3c

    Sorry, I'm new and had to add spaces around the // to post
  • realpong
    realpong New Altair Community Member
    edited February 2019
    Built something using Python instead to grab the JSON file and throw the data I needed into a table.  Sorry, the appropriate indentation didn't copy over.  Also, all the lines with 'rating%' or 'range%' is only relevant to the site I was using if anyone tries this using another URL.


    import requests
    import pandas as pd
    import json

    # rm_main is a mandatory function, 
    # the number of arguments has to be the number of input ports (can be none)
    def rm_main():
    username = YOUR USERNAME GOES HERE
    password = YOUR PASSWORD GOES HERE

    s = requests.Session()
    link = URL GOES HERE

    response = s.get(link, auth = (username, password), verify = False)
    data = json.loads((response.content).decode('utf-8'))
    temp = []
    ratings = data['ratings']
    for i in ratings:
    rating_date = i['rating_date']
    rating = i['rating']
    range_nm = i['range']
    rating_color = i['rating_color']
    temp.append([rating_date, rating, range_nm, rating_color])
            
    df = pd.DataFrame(temp,columns = ['rating_dt','rating', 'range_nm', 'rating_color'])

    # connect 2 output ports to see the results
    return df
  • sgenzer
    sgenzer
    Altair Employee
    hi @realpong I would use the Web Automation extension. Definitely the way to go here with both the API queries and the JSON parsing.

    Scott

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.