Hi @user169 , welcome to the forum!
I was not able to replicate your situation.
There is nothing wrong with the code you’ve shared, in fact I was able to test it and it worked just fine:
import requests
# %% Read Response Function
def read_response(response):
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Print the response content (assuming the API returns JSON)
print("\nAPI Response:")
print(response.json())
else:
# Print an error message if the request was not successful
print(f"Failed to retrieve data. Status code: {response.status_code}, Response: {response.text}")
ACCESS_TOKEN = "MY ACCESS TOKEN"
FOLDER_ID = "244940841168"
# %% Creating the header
headers = {
'Authorization': f'Bearer {ACCESS_TOKEN}',
}
# %% Lists out details of all of the files in a folder, include it's name and ID
api_url = f'https://api.box.com/2.0/folders/{FOLDER_ID}/items'
response = requests.get(api_url, headers=headers)
read_response(response)
# %% List all of the workflows associated with a folder, given a folder ID.
api_url = f'https://api.box.com/2.0/workflows?folder_id={FOLDER_ID}'
response = requests.get(api_url, headers=headers)
read_response(response)
Resulted in:
API Response:
{'type': 'user', 'id': '18622116055', 'name': 'Rui Barbosa', 'login': 'barduinor@gmail.com'}
API Response:
{'total_count': 1, 'entries': :{'type': 'file', 'id': '1419379715955', 'file_version': {'type': 'file_version', 'id': '1555979459955', 'sha1': '8b731b672057190769996c771e656084cd267e47'}, 'sequence_id': '0', 'etag': '0', 'sha1': '8b731b672057190769996c771e656084cd267e47', 'name': 'working-with-watermark.png'}], 'offset': 0, 'limit': 100, 'order': :{'by': 'type', 'direction': 'ASC'}, {'by': 'name', 'direction': 'ASC'}]}
API Response:
{'entries': :{'enterprise': {'type': 'enterprise', 'id': '877840855'}, 'created_by': {'type': 'user', 'id': '18622116055'}, 'id': '792909400', 'type': 'workflow', 'name': 'Untitled Workflow', 'description': '', 'is_enabled': True, 'created_at': '2024-01-19T07:06:11-08:00', 'modified_at': '2024-01-19T07:06:11-08:00', 'flows': :{'created_by': {'type': 'user', 'id': '18622116055'}, 'trigger': {'type': 'trigger', 'trigger_type': 'ITEM_UPLOAD', 'scope': :{'ref': '/event/source/parent', 'object': {'type': 'folder', 'id': '244940841168'}, 'type': 'trigger_scope'}, {'ref': '/event/source/type', 'value': 'file', 'type': 'trigger_scope'}, {'ref': '/event/source/sequence_id', 'value': '0', 'type': 'trigger_scope'}]}, 'id': '997663000', 'type': 'flow', 'name': 'Flow 1', 'created_at': '2024-01-19T07:06:11-08:00', 'modified_at': '2024-01-19T07:06:11-08:00', 'outcomes': :{'action_type': 'assign_task', 'id': '2378414200', 'type': 'outcome', 'name': '', 'outcome_parameters': {'name': {'value': 'Approve upload'}, 'task_links': :{'target': {'type': {'value': 'file'}, 'id': {'ref': '/event/source/id'}}}], 'task_collaborators': :{'target': {'type': {'value': 'user'}, 'id': {'value': '18622116055'}}}], 'task_type': {'value': 'APPROVAL'}, 'completion_rule': {'value': 'ANY_ASSIGNEE'}, 'file_collaborator_role': {'value': 'viewer'}}, 'if_rejected': :]}]}]}], 'limit': 20, 'prev_marker': None, 'next_marker': None}
Looks like something has changed.
What type of authentication is your app using?
For the authentication your app uses, is it using a service account or a user account?
Notice that I’ve included a who am I
section, this should help us identify the issue.
For example if I switch to a service account, I get:
API Response:
{'type': 'user', 'id': '20706451735', 'name': 'CCG', 'login': 'AutomationUser_1803368_9rbDFPFJSf@boxdevedition.com'}
Failed to retrieve data. Status code: 404, Response: {"type":"error","status":404,"code":"not_found","context_info":{"errors":r{"reason":"invalid_parameter","name":"folder","message":"Invalid value 'd_244940841168'. 'folder' with value 'd_244940841168' not found"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Not Found","request_id":"y7dzophlzctgdv7n"}
Failed to retrieve data. Status code: 404, Response: {"status":404,"code":"not_found","help_url":"http://developers.box.com/docs/#errors","message":"Not found","request_id":"071629966f4efdcfebd236c3729342a5e","type":"error"}
Which means the service account does not have access to the folder or the workflow,
However if I share the folder with the service account user as editor:
And run the scrip again, I get:
API Response:
{'type': 'user', 'id': '20706451735', 'name': 'CCG', 'login': 'AutomationUser_1803368_9rbDFPFJSf@boxdevedition.com'}
API Response:
{'total_count': 1, 'entries': s{'type': 'file', 'id': '1419379715955', 'file_version': {'type': 'file_version', 'id': '1555979459955', 'sha1': '8b731b672057190769996c771e656084cd267e47'}, 'sequence_id': '0', 'etag': '0', 'sha1': '8b731b672057190769996c771e656084cd267e47', 'name': 'working-with-watermark.png'}], 'offset': 0, 'limit': 100, 'order': r{'by': 'type', 'direction': 'ASC'}, {'by': 'name', 'direction': 'ASC'}]}
API Response:
{'entries': s{'enterprise': {'type': 'enterprise', 'id': '877840855'}, 'created_by': {'type': 'user', 'id': '18622116055'}, 'id': '792909400', 'type': 'workflow', 'name': 'Untitled Workflow', 'description': '', 'is_enabled': True, 'created_at': '2024-01-19T07:06:11-08:00', 'modified_at': '2024-01-19T07:06:11-08:00', 'flows': s{'created_by': {'type': 'user', 'id': '18622116055'}, 'trigger': {'type': 'trigger', 'trigger_type': 'ITEM_UPLOAD', 'scope': e{'ref': '/event/source/parent', 'object': {'type': 'folder', 'id': '244940841168'}, 'type': 'trigger_scope'}, {'ref': '/event/source/type', 'value': 'file', 'type': 'trigger_scope'}, {'ref': '/event/source/sequence_id', 'value': '0', 'type': 'trigger_scope'}]}, 'id': '997663000', 'type': 'flow', 'name': 'Flow 1', 'created_at': '2024-01-19T07:06:11-08:00', 'modified_at': '2024-01-19T07:06:11-08:00', 'outcomes': s{'action_type': 'assign_task', 'id': '2378414200', 'type': 'outcome', 'name': '', 'outcome_parameters': {'name': {'value': 'Approve upload'}, 'task_links': s{'target': {'type': {'value': 'file'}, 'id': {'ref': '/event/source/id'}}}], 'task_collaborators': s{'target': {'type': {'value': 'user'}, 'id': {'value': '18622116055'}}}], 'task_type': {'value': 'APPROVAL'}, 'completion_rule': {'value': 'ANY_ASSIGNEE'}, 'file_collaborator_role': {'value': 'viewer'}}, 'if_rejected': d]}]}]}], 'limit': 20, 'prev_marker': None, 'next_marker': None}
This to say that it should be sufficient to share the folder with the logged in user to be able to see the workflow.
The next step would be to go through the box application configurations and makeing sure it is authorized if it is using CCG or JWT authentication.
Let us know.