Creating new events using API
2 2

6 posts in this topic

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.

Share this post


Link to post
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()

 

Share this post


Link to post
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}

Share this post


Link to post
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()

 

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
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
2 2