Beginner struggling _all_ the data [edited]

Hi!
I’m still relatively new new to programming and slowly making my way through the API documentation. My end goal is to create a CSV with a list of teams, projects, folders, assets, and links.

I feel a bit stuck in a loop at the beginning of the API however with finding the root_asset_id. I’ve started with the “https://api.frame.io/v2/me” and the get account examples on the API. I’m able to pull the account_id from there, but when moving forward to teams I’m confused about the

query = {
“include”: “user_role”
}

part and what results to be expecting. Any guidance would be appreciated.

Nancy

I was able to push through my initial troubles – I was using the wrong account_id. However, now I’m at the point where I’d like to get all of the projects for the teams. I wrote this loop

projects_in_a_team = []
for n in range(len(teamsdata)):
     team_id = teamsdata[n]['id']
     url4 = "https://api.frame.io/v2/teams/" + team_id + "/projects"
     response4 = requests.get(url4, headers=headers)
     projectdata = response4.json()
     projects_in_a_team.append(projectdata)

but as you an imagine it’s sluggish and quite long. Is there a more efficient way to get all the projects on a team?

Looks like you’re writing this in Python which means you should definitely check out frameioclient, our Python SDK - frameioclient · PyPI.

The way our API is architected, you’re always going to have to navigate resources canonically, for example: Account > Team > Project - like you are here. What you could do to make this quicker though is to increase the page size from the default of 50 to say, 1,000 which should at least mean less API calls. Looking at your code I also don’t see any handling of pagination, but you can learn more about that here.

Lastly, here’s a trick you can do with your code to make it slightly more concise if you want:

for i, team enumerate(teamsdata):
     team_id = team['id']
     url4 = "https://api.frame.io/v2/teams/" + team_id + "/projects"
     response4 = requests.get(url4, headers=headers)
     projectdata = response4.json()
     projects_in_a_team.append(projectdata)
1 Like

Thanks. That helped a lot.
I’m still struggling with the frameioclient a bit.
I’ve gotten through the asset tree and am at the folder level. In the examples on github (as you know) there is a function that does what I’m looking to do:

def scrape_asset_data(client, asset_id, asset_list):
    """
    Takes an initialized client and an asset_id representing a position in a directory tree.
    Recursively builds a list of assets within the tree.  Returns a list of dicts.
    """
    assets = client.get_asset_children(asset_id)

    for asset in assets:
        # Recurse through folders but skip the empty ones
        if asset['type'] == "folder" and asset != []:
            # Include non-empty folders in the list of scraped assets
            asset_list.append(asset)
            scrape_asset_data(client, asset['id'], asset_list)

        if asset['type'] == "file":
            asset_list.append(asset)

        if asset['type'] == "version_stack":
            # Read about version stacks: https://docs.frame.io/docs/managing-version-stacks
            versions = client.get_asset_children(asset['id'])
            asset_list.append(asset)
            for v_asset in versions:
                asset_list.append(v_asset)

    return asset_list

But when I try to follow that, the .get_asset_children returns undefined. I had been using, seen in my original post, the requests.get(url...) method. I think I’m missing how to adapt the request.get(url...) with '/children?type=folder and /children?type = file into the function for scraping through a folder for subfolders and files.

Am I missing an import module? Or do I just need to loop through every folder separately? I’ll keep trying, just thought I’d ask the forum for any advice!

Okay, so the issue is that this example is out-dated and won’t work with this version of the SDK! Sorry about the confusion here.

If you want to use this code as is, then you’ll need to use a version of frameioclient < 1.0.0.

I will quickly try and update this so that it runs using any version of the SDK > 1.0.0 though.

1 Like

Just finished a big update to the example asset_scraper.py which you can find here, it’s now fully typed and fully functional using the latest version of the Python SDK!

1 Like

Oh goodness, thanks so much!