Publish via crud python api questions

Hi, I’ve searched around here and have a partial publish working via a script that runs after a render job has completed. I’m having trouble figuring out how to set certain fields. Basically I’m trying to mimic the standalone Publisher. I’d like to set Published File Name, File Type, link it to a task, and a user.
Is there a way to query all the options to set when using shotgrid.create() so I’m not fumbling around? The python crud api documentation doesn’t touch on publishing, just creating versions, which I am doing very well now.
Here is what I have so far:

 data = { 'project': {'type': 'Project','id': prjCode},
        'path': {'local_path': frame_path, 'name':shotcode}
 result = sg.create('PublishedFile', data)

We are trying to run without an advanced config so no tank - or is that wrong? Can I run the publisher API with just tk-core?


Update: I’m slowing figuring this out. I think I just misplaced where things go in the data dictionary. I’ve managed to get entity working so I’ll keep plugging away.

Hi @da_am !

I would highly suggest to have look at the implementation of the register_publish function in tk-core. If you can steal/mimic that you’ll be in a good spot publishing wise.

Hope that helps :cat:!

Cheers Fabian

1 Like

This dictionary will create you a PublishedFile via the python api instead of using core.

You do need to know the local storage to register to so it’s worth having some function iterate over them to find a match.

data = {
"project": {"id": 1, "type": "Project"},
'path': {'content_type': None,
        'link_type': 'local',
        'local_path': 'G:\\Projects\\test\\editorial\\publish\\luts\\foo.3dl',
        'local_path_linux': None,
        'local_path_mac': '/Volumes/g/Projects/test/editorial/publish/luts/foo.3dl',
        'local_path_windows': 'G:\\Projects\\test\\editorial\\publish\\luts\\foo.3dl',
        'local_storage': {'id': 1,
                        'name': 'primary',
                        'type': 'LocalStorage'},
        'name': 'foo.3dl',
        'type': 'Attachment',
        'url': 'file://G:\\Projects\\test\\editorial\\publish\\luts\\foo.3dl'},

shotgun.create("PublishedFile", data) 

Just make sure to add any more data fields like the Published File Type, Version number (if any) etc…
But this gets you a linked local storage file.

1 Like