Pawel Starzynski Posted June 25 Report Posted June 25 Hi, I'm struggling with getting and setting custom attribute value for task, which type is a link to a user. Example: I have a shot that consists of 8 tasks. For every task I have Assignee and I created custom attribute (reviewer) as on screen below. Now I want to create two lists containing: all artists assigned to any task in this shot, and the same with reviewers. While getting assignees is quite straightforward, getting custom attribute link is the whole different story. Obviously I cannot do something like task['custom_attribute']['reviewer'], which would be awesome... So could you please help me out here and give some advice how to approach this problem?
Lorenzo Angeli Posted June 25 Report Posted June 25 Hi @Pawel Starzynski, we have some examples as part of our api documentation related to custom attribute link. Pease let us know in case you don't find help there. Cheers. L.
Pawel Starzynski Posted June 26 Author Report Posted June 26 Hi @Lorenzo Angeli. Thank you for quick response Yep I saw documentation but was hoping to get this data in more indirect way I've managed to get usernames this way: reviewers_ids = [] reviewers_result = ftrack.query( 'select to_id from CustomAttributeLink where ' 'configuration.key = "reviewer" and from_id in ({})'.format(', '.join(tasks_ids)) ) for i in reviewers_result: reviewers_ids.append(i['to_id']) users = ftrack.query('User where id in ({})'.format(', '.join(reviewers_ids))) for user in users: print(user['username']) Could you please verify if this is the right approach and most effective one? Maybe I could somehome merge all those querries into one to increase performance?
Lorenzo Angeli Posted June 26 Report Posted June 26 Hi @Pawel Starzynski, just reproduced your setup and your script seems to be doing the right thing. The only thing I'd change to further speed this up is to project username in the User query. If you are after perfomance tweaking please be sure to read our article about it ! Hope it helps. L.
Pawel Starzynski Posted June 26 Author Report Posted June 26 Thank you @Lorenzo Angeli, I will check the article you've linked for further queries improvements. Wish you a good day Lorenzo Angeli 1
Viluggi Posted July 4 Report Posted July 4 Assuming you are working with an API that supports tasks and custom attributes (such as Shotgun or a similar project management tool), here are some steps to follow: 1. Understanding the API Structure 2. Fetching Task Data 3. Extracting Custom Attribute Links 4. Setting Custom Attribute Links 5. Handling Edge Cases Example Implementation Here’s a more complete example putting all the steps together: import requests # Configuration api_base_url = "https://api.example.com" headers = { "Authorization": "Bearer YOUR_API_TOKEN", "Content-Type": "application/json" } # Helper function to fetch user details def fetch_user(user_link): response = requests.get(f"{api_base_url}/users/{user_link}", headers=headers) return response.json() # Fetch tasks tasks_response = requests.get(f"{api_base_url}/tasks", headers=headers) tasks = tasks_response.json() artists = [] reviewers = [] for task in tasks: custom_attributes = task.get("custom_attributes", {}) artist_link = custom_attributes.get("artist_link") reviewer_link = custom_attributes.get("reviewer_link") if artist_link: artists.append(fetch_user(artist_link)) if reviewer_link: reviewers.append(fetch_user(reviewer_link)) # Output the lists print("Artists:", artists) print("Reviewers:", reviewers) # Example of updating a task task_id = "12345" # Example task ID update_payload = { "custom_attributes": { "artist_link": "new_artist_link", "reviewer_link": "new_reviewer_link" } } update_response = requests.put(f"{api_base_url}/tasks/{task_id}", headers=headers, json=update_payload) if update_response.status_code == 200: print("Task updated successfully") else: print("Failed to update task:", update_response.content) Adjust the field names, endpoint URLs, and request structure according to the specific API https://tech-stack.com/blog/what-is-an-api/ you are using. This should give you a good starting point to manage custom attribute links for tasks effectively.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now