<jupyter_start><jupyter_text>2 - Accessing Related Items through Relationships---<jupyter_code>import requests
import json
import string

# Importing the libraries we need to format the data in a more readable way. 
import pandas as pd
from pandas.io.json import json_normalize
base_url = 'https://www.fairdomhub.org'
def json_for_resource(type, id):    

  headers = {"Accept": "application/vnd.api+json",
           "Accept-Charset": "ISO-8859-1"}
  r = requests.get(base_url + "/" + type + "/" + str(id), headers=headers)
  r.raise_for_status()
  return r.json()<jupyter_output><empty_output><jupyter_text>Fetches the JSON for Project 60Shows just the relationships block, rather than the full JSON, as this is what we are interested in here.Relationships are grouped by type. Each relationship has a '*data*' block, which provides an array of relationship resource.Each resource is described with an '*id*' and '*type*'.SEEK supports Restful Routes, each resource can be identified by:    https:////    so,  *{'id': '18', 'type': 'institutions'}* would be https://fairdomhub.org/institutions/18**Note** that only visible resources are listed, any related items that are not visible due to sharing permissions, are omitted. (more in accessing as an authorized user later).<jupyter_code>project_id = 60

result = json_for_resource('projects',project_id)


print("Project: " + result['data']['attributes']['title'] + "\n")

result['data']['relationships']<jupyter_output><empty_output><jupyter_text>Here we iterate over each related data_file, and GET the resource JSON, and display the resulting id and title in a table<jupyter_code>files = []
type = 'data_files'

for item in result['data']['relationships'][type]['data']:
  j = json_for_resource(item['type'],item['id'])  
  files.append({
      'id':j['data']['id'],
      'title':j['data']['attributes']['title'],      
  })
  
print(str(len(files)) + " found") 

json_normalize(files)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1339421613394216, 'fraction_numerical': 0.007102993404363267, 'mean_word_length': 5.2405063291139244, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '278059', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 621, 'n_tokens_neox': 590, 'n_words': 186, 'path': '02_Project_data_files.ipynb', 'repo_name': 'FAIRdom/api-workshop', 'size': '1971'}