Time Tracking Log API

Hello,

I am trying to automate the download of our time tracking logs for our main board using the API.

The ideal download would be similar to the data provided in the “timer” tab of the spreadsheet but condensed to Task ID, User ID, Start Date/Time, End Date/Time, (including the subitems too in the same query ideally)

I had thought that I had done this using the activity_log function (screenshot below) but the duration there tracks the total time spent, not individual logs? Don’t think I am barking up the right tree.

Could anybody let me know if there is a simple query I am missing that I can run to get all time logs (filtered by start date)?

I am using python also in case that matters!

Thanks

Hello there @Milbourn and welcome to the community!

I hope you like it here :muscle:

The activity logs will not show individual logs.

I believe the closest you can get to that would be to check all the events for a specific items, check the “running” field to see when it was set to “running” and when it was paused, and with a script, build the individual logs.

Cheers,
Matias

1 Like

Hello! Thanks for the welcome and for responding!

Just in the meantime I’ve found this code:

{
  items(ids: 5256361xxx) {
    column_values {
      id
      value
      ... on TimeTrackingValue {
        history {
          status
          ended_at
          started_at
          started_user_id
          manually_entered_end_date
        }
      }
    }
    id
  }
}

Which appears to give me what i am after on the playground (historical time logs)

but when i run it through python

import requests
import json

# Your Monday.com API key
api_key = 'xxx'

# The GraphQL query
query = '''
{
  items(ids: 5256361524) {
    column_values {
      id
      value
      ... on TimeTrackingValue {
        history {
          status
          ended_at
          started_at
          started_user_id
          manually_entered_end_date
        }
      }
    }
    id
  }
}
'''

# The API endpoint
url = 'https://api.monday.com/v2'

# Headers for the request
headers = {
    'Authorization': api_key,
    'Content-Type': 'application/json'
}

# Send the request
response = requests.post(url, headers=headers, json={'query': query})

# Print the response
print(response.json())

I recieve the following error and I am struggling to find a work around. Do you or anyone else have any advice?

{'errors': [{'message': "Field 'on' doesn't exist on type 'ColumnValue'", 'locations': [{'line': 7, 'column': 7}], 'path': ['query', 'items', 'column_values', 'on'], 'extensions': {'code': 'undefinedField', 'typeName': 'ColumnValue', 'fieldName': 'on'}}, 
{'message': "Field 'TimeTrackingValue' doesn't exist on type 'ColumnValue'", 'locations': [{'line': 7, 'column': 10}], 'path': ['query', 'items', 'column_values', 'TimeTrackingValue'], 'extensions': {'code': 'undefinedField', 'typeName': 'ColumnValue', 'fieldName': 'TimeTrackingValue'}}], 'account_id': 10523xxx}

Hello again,

I do not have experience with Python, but it looks like the 3 dots might not be being taken as it should. I recreated this query in Postman and exported it to Python. I hope that helps!

Python - Requests:

import requests
import json

url = "https://api.monday.com/v2/"

payload = "{\"query\":\"{\\n  items(ids: 5256361524) {\\n    column_values {\\n      id\\n      value\\n      ... on TimeTrackingValue {\\n        history {\\n          status\\n          ended_at\\n          started_at\\n          started_user_id\\n          manually_entered_end_date\\n        }\\n      }\\n    }\\n    id\\n  }\\n}\",\"variables\":{}}"
headers = {
  'API-Version': '2023-10',
  'Authorization': 'MYAPITOKEN',
  'Content-Type': 'application/json',
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Python http.client:

import http.client
import json

conn = http.client.HTTPSConnection("api.monday.com")
payload = "{\"query\":\"{\\n  items(ids: 5256361524) {\\n    column_values {\\n      id\\n      value\\n      ... on TimeTrackingValue {\\n        history {\\n          status\\n          ended_at\\n          started_at\\n          started_user_id\\n          manually_entered_end_date\\n        }\\n      }\\n    }\\n    id\\n  }\\n}\",\"variables\":{}}"
headers = {
  'API-Version': '2023-10',
  'Authorization': 'MYAPITOKEN',
  'Content-Type': 'application/json',
}
conn.request("POST", "/v2/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Cheers,
Matias

1 Like

@Matias.Monday included it in his example but doesn’t seem to call it out directly, but you also need to set API-Version header to 2023-10 for the column value fragments for various column types to work.

2 Likes

Thank you @codyfrisch!

I totally missed that it was missing on the script that was posted, and is probably why this was not working!

Cheers,
Matias

1 Like

Thank you @Matias.Monday so so so so much! Can now run the time logs without issue!!

I had not being setting the API-Version header to 2023-10 in my other queries and had some success, but thank you @codyfrisch for letting me know. Will include that going forward.

Thank you both :grin: :grin: :grin: :grin: :grin:

2 Likes

Happy to help @Milbourn !

1 Like