Jump to content

Creating new events using API


dnx2710

Recommended Posts

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.

Link to comment
Share on other sites

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()

 

Link to comment
Share on other sites

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}
Link to comment
Share on other sites

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()

 

Link to comment
Share on other sites

  • 6 months later...

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. 

Link to comment
Share on other sites

  • 3 years later...

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.

 

 

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...