The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

Connect to web API to download a JSON file

realpongrealpong Member Posts: 4 Learner I
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?

Answers

  • realpongrealpong Member Posts: 4 Learner I
    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
  • realpongrealpong Member Posts: 4 Learner I
    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
  • sgenzersgenzer Administrator, Moderator, Employee-RapidMiner, RapidMiner Certified Analyst, Community Manager, Member, University Professor, PM Moderator Posts: 2,959 Community Manager
    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

Sign In or Register to comment.