dnx2710 Posted July 19, 2017 Report Posted July 19, 2017 I am trying to create a new Calendar Event using the api, but I think this is not currently being supported. The old api had a project.createPhase() method which is the one I am testing to create this entity. Is this the correct way to approach the creation of events through the api? FYI: I am currently using the 3.5 (latest) ftrack api for python.
Mattias Lagergren Posted July 20, 2017 Report Posted July 20, 2017 It is possible, but the new api works a bit differently. You can read some usage examples here: http://ftrack-python-api.rtd.ftrack.com/en/stable/example/index.html A calendar event could be created and committed like this: import moment import ftrack_api session = ftrack_api.Session() session.create( 'CalendarEvent', { 'name': 'Foo', 'start': arrow.get('2017-01-03'), 'end': arrow.get('2017-02-03') } ) session.commit()
dnx2710 Posted July 20, 2017 Author Report Posted July 20, 2017 Thank you for the example, I used the code you provided by was I see no new event in the "Overview". Whe trying to debug the issue I got "Duplicate entry" Here is the json used for my test: [{"action": "create", "entity_data": { "__entity_type__": "CalendarEvent", "end": {"__type__": "datetime", "value": "2017-07-21T23:59:59+00:00"}, "id": "0a645dfc-76c0-55e1-a052-5db8246fb86c", "name": "Random title used for test", "start": {"__type__": "datetime", "value": "2017-07-20T00:00:00+00:00"}}, "entity_key": ["0a645dfc-76c0-44e1-a052-5db8246fb86c"], "entity_type": "CalendarEvent"}] And the response: { "content": "(_mysql_exceptions.IntegrityError) (1062, "Duplicate entry '0a645dfc-76c0-44e1-a052-5db8246fb86c' for key 'PRIMARY'") [SQL: u'INSERT INTO calendar_event (name, start, end, `leave`, everyone, forecast, estimate, effort, project_id, type_id, id, created_by_id, created_at) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'] [parameters: ('Random title used for test', datetime.datetime(2017, 7, 20, 0, 0), datetime.datetime(2017, 7, 21, 23, 59, 59), 0, 0, 0, 0.0, 0.0, None, None, u'0a645dfc-76c0-44e1-a052-5db8246fb86c', 'abb865c6-d666-11e5-a91d-0026b94baeec', datetime.datetime(2017, 7, 20, 17, 49, 14, 499195))]", "exception": "IntegrityError", "error_code": null } Which means the event DOES exist, but I am unable to see it. When I try to list the CalendarEvents of the project, the new one does not appear. Also, when I try to update the dates of an existing event I get {"content": "'NoneType' object has no attribute 'date'", "exception": "AttributeError", "error_code": null}
Mattias Lagergren Posted July 21, 2017 Report Posted July 21, 2017 I suspect that this happens because the event is neither attached to user or a project. If you modify the example to attach it to a project, does it show up then? import moment import ftrack_api session = ftrack_api.Session() project = session.query('Project').first() session.create( 'CalendarEvent', { 'name': 'Foo', 'start': arrow.get('2017-01-03'), 'end': arrow.get('2017-02-03'), 'project_id': project['id'] } ) session.commit()
Tim Edelmann Posted February 14, 2018 Report Posted February 14, 2018 BUMP! We cannot get this to work or we do not understand, how this is to be used. When executing the example above, we can't see anything in the calendar (which is what we expected). Mattias you wrote: "I suspect that this happens because the event is neither attached to user or a project." Sounds like, we can attach a calendarEvent to a user? Thats what we'd like to do. What is the property-name to provide when setting a user-id? In the sample above 'project_id' indicates attaching to a project. Where is this documented? Thanks.
Mattias Lagergren Posted February 16, 2018 Report Posted February 16, 2018 To attach a calendar event to a user you will want to create a CalendarEventResource with the calendar_event_id and resource_id (the id of the user). Tim Edelmann 1
aline3d Posted August 26, 2021 Report Posted August 26, 2021 Hello, I`m trying to do something like this, but I get an error when try to create a CalendarEventResource. I want to create an event connected to a user Here is my code: CalendarEvent = session.create( 'CalendarEvent', { 'name': 'TEST_PIPELINE', 'start': arrow.get('2021-08-25'), 'end': arrow.get('2021-08-31'), } ) session.commit() user = session.query('User where username is "alima"').first() event = session.create( 'CalendarEventResource', { 'calendar_event_id': CalendarEvent['id'], 'resource_id ': user['id'] } ) session.commit() And here is the error: Traceback (most recent call last): File "/mnt/be-fs/home/alima/Documents/DEV/misc/ftrack/creating_booking.py", line 29, in <module> session.commit() File "/mnt/be-fs/rnd/pipe/dev/users/alima/ada/aux/libs/python/global/ftrack_api/session.py", line 1260, in commit result = self.call(batch) File "/mnt/be-fs/rnd/pipe/dev/users/alima/ada/aux/libs/python/global/ftrack_api/session.py", line 1654, in call raise ftrack_api.exception.ServerError(error_message) ftrack_api.exception.ServerError: Server reported error: OperationalError((MySQLdb._exceptions.OperationalError) (1048, "Column 'resource_id' cannot be null") [SQL: u'INSERT INTO calendar_event_resource (calendar_event_id, resource_id, id, created_at, created_by_id) VALUES (%s, %s, %s, %s, %s)'] [parameters: (u'6f4bb053-1233-4789-a33c-67ff04321855', None, u'0189ce13-861f-4cb9-a24b-67facbfbe30e', datetime.datetime(2021, 8, 26, 21, 27, 40, 711213), u'2da5a9dc-a9cf-11ea-b597-4e978d5f1569')] (Background on this error at: http://sqlalche.me/e/e3q8)) Looks like is not finding the resource_id, but I`m setting this parameter. What I`m doing wrong? Thank you.
aline3d Posted August 27, 2021 Report Posted August 27, 2021 ow.. super!! Works here.. thank you so much Henrik.
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