Closed michaelbriordan closed 4 years ago
Could you add a little more context about what you are trying to do?
What API call resulted in template
? What are you hoping to pass it to?
I am trying to use the Zotero.create_items
method
exceptions are thrown when I try to assign a value to arrays or objects
template = zot.item_template(‘manuscript’) # I’m using ‘manuscript’ and ‘letter’ only with this script
…
template['collections'][0] = "UBJW58IP"
…
resp = zot.create_items([template])
Raises exception:
IndexError: list assignment index out of range
If I remove this code, or pass over the exception, the item is created but no collection assigned.
template = zot.item_template(‘letter’)
…
template['creators'][1]['creatorType'] = 'recipient'
template['creators'][1]['firstName'] = “Some Other Person”
template['creators'][1]['firstName'] = “Some Other Person”
...
resp = zot.create_items([template])
raises an Index Exception, but the first object, ie. template['creators'][0]['creatorType']
does not raise any exception. If I remove this code, or pass over the exception, the item is created, without the second creator.
I can't reproduce this:
template = zot.item_template("manuscript")
c = zot.collections()
template["collections"].append(c[0]['key'])
resp = zot.create_items([template])
Creates a new item as expected.
As for the second problem, unless I'm misunderstanding you, you need to append a dict
containing creator data to the creators
list first. You can't just specify a new key for a dict that doesn't exist yet: creators
is a list
with a single dict
entry, so the 1
index doesn't work.
template = zot.item_template("letter")
creators_dict = template['creators'][0]
template['creators'][0]['firstName'] = "foo"
creators_dict['firstName'] = "bar"
template['creators'].append(creators_dict)
resp = zot.create_items([template])
In the absence of a reproducible example demonstrating an error, I'm going to close this issue. Feel free to reopen if something isn't working.
General
Platform: MacOS X Python version: 3.7.5 Pyzotero version: latest release
Problem description
Unable to create JSON arrays (creators) and objects (collections) with new items.
template['creators'][0]['creatorType'] = "blah"
works
template['creators'][1]['creatorType'] = "blah"
does not
Seems to also apply to objects, thus
template['collections'][0] = "blah"
returns
Adding additional creatos raises no error but does not produce additional creators. Attempting to assign a collection returns:
If possible, paste the full traceback in a code block below, and fill in the summary