Forum

Getting data with t...
 
Notifications
Retirer tout

Getting data with the API using Python

1 Posts
1 Utilisateurs
0 Reactions
2,942 Vu
(@bgenolini)
Trusted Member
Inscription: Il y a 6 ans
Posts: 45
Début du sujet   [#8103]

Hello,
I have tetsed a simple way to get data from the API with Python.
I'm working under Windows 10, with Anaconda, Python 3.9.7
This is quick and dirty code I have validated after validating the settings of the server with a colleague of mine.

Cheers

import requests
import pandas as pd

SERVER="your.server.here"
URL=f"http://{SERVER}/api"
MY_AUTH = ('user', 'password')

def GetData(req):
    # Returns a dictionnary structure form the request "req"
    return requests.get(f"{URL}/{req}", auth = MY_AUTH).json()

def GetDataPd(req):
   # Converts into a panda DataFrame
    return pd.DataFrame.from_dict(GetData(req)['items'])

if __name__ == '__main__':
   # Get the list of projects and print the names and parent's name of non closed projects
    projs = GetDataPd("Project/all")
    print(projs[projs['nameStatus'] != 'closed'][['name', 'nameProject']])
 


Bernard


   
Citation
Share:
Retour en haut