What's the argument name to be passed in for hiding a News Item from the navigation menu when using api.content.create?

Currently, I have a script that is used to import data into Plone, however, each News Item is added to navigation bar. I want to avoid this. At first, I tried exclude_from_nav=True and excludeFromNav=True, but it's not working.

My import code looks like this:

def create_news_item(level, id, base_path, path_, name, data):
    otherdata = {
        "excludeFromNav":True,
        "contributors":data["contributors"],
        "text":RichTextValue(data["text"]),
        "expirationDate":data["expirationDate"],
        "allowDiscussion":data["allowDiscussion"],
        "atrefs":data.get("_atrefs", {}),
        "imageCaption":data["imageCaption"]
    }
    if "image" in data:
        otherdata["image"] = data["image"]
        otherdata["imageCaption"] = data["imageCaption"]
    _path = "/".join(base_path.split('/')[:-1])
    if level > 1:
        container = api.content.get(path=_path)
    else:
        container = api.portal.get()
    if container and id not in container:
        obj = newsitem = api.content.create(
            type='News Item',
            title=name,
            id=id,
            safe_id=False,
            container=container,
            **otherdata)
        setuid(obj, data['_uid'])
        if '_datafield_image' in data:
            image_data = data['_datafield_image']
            newsitem.image = prep_image(
                                imagename=image_data['filename'],
                                data=image_data['data'],
                                content_type=data['_content_type'],
                               )
    else:
        print "content already present for {}".format(base_path)
    print "type is :{}, path is:{},{}".format(data['_type'],
                         data['_path'], level + 2)

Any ideas?

Tried to reindex the created object?
Check the portal_catalog -> Contents and inspect the indexed values for your content object.

Otherwise try

obj.setExcludeFromNav(True)
obj.reindexObject(idxs=['exclude_from_nav'])

-aj

Thanks. obj object doesn't have the method setExcludeFormNav, however, the reindexObject method did the trick.

I assume you're using a Dexterity-based content type and that's why you don't have the setExcludeFromNav method available.

reindexObject updates the catalog so your change is reflected there; most of Plone UI stuff uses the catalog to retrieve information about content items instead of accessing them directly, because is faster and uses less memory.