'How do I join ndjson files inside a REST API call in python?

When I make calls from a REST API using python, I receive a couple of ndjson files in a link.

However, it would be very tedious to call each one individual to get the ndjson file.

Is there anyway to join the ndjson files in the call so I don't have copy and past each file individually?

Output:

{requiresAccessToken":true,"output":[{"type":"Patient","url":"https://api.bcda.cms.gov/data/12265/3f3539a6-6728-43bc-b984-78bd4fe8d43c.ndjson"},{"type":"Patient","url":"https://api/3o7381ejq8s0d.ndjson"},{"type":"Patient","url":"https://api.172187eea19.ndjson"}],"error":[],"JobID":12265}

Then I have to do the following to get the following data for each ndjson file:

headers = {
    'Accept-Encoding': 'gzip',
    'Authorization': f'Bearer {access_token}',
}
response1 = requests.get("https://api/3o7381ejq8s0d.ndjson",
                       headers = headers)
response2 = requests.get("https://api.172187eea19.ndjson",
                       headers = headers)
print(response1)
print(response2)

import pandas as pd 
from io import StringIO
import ndjson
import json
items1 = response1.json(cls=ndjson.Decoder)
items2 = response2.json(cls=ndjson.Decoder)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source