Cannot "Add" List Item to SharePoint List using shareplum

484 Views Asked by At

I am trying to update a Sharepoint list using shareplum. I am able to read information but for some reason I am not able to add a new list item. What is going wrong here?

from shareplum import Site
from requests_ntlm import HttpNtlmAuth

# variables

username = "myusername"
password = "mypassword"
site_url = "https://mycompansharepointsite.org/sites"
domain = "myCompanyDomain"
my_list_name = "listTitle"
my_data = [{

'Project_Field': 'TESTING'

}]

cred = HttpNtlmAuth(f'{domain}\\{username}', password)
site = Site(site_url, auth=cred)

mylist = site.List(my_list_name, exclude_hidden_fields=True)

incoming_list.UpdateListItems(data=my_data, kind='Update')

For example, after importing the library and declaring the variables to log me in, these lines work to read the Sharepoint list:

sp_list = site.List(my_list_name)
data = sp_list.GetListItems()
print(data)

I've thought maybe I need to use a different library like Office365-REST-Client but I thought, since I finally figured out how to get this far to read a Sharepoint list using shareplum, I would exhaust my resources before going down another rabbit hole.

1

There are 1 best solutions below

2
Gaurav T On

I haven't used shareplum but I am sure you need to update the my_data variable to include the type specification like below:

my_data = [{
  "__metadata": {"type": "SP.Data.LISTNAMEListItem"},
  'Project_Field': 'TESTING'
}]

replace LISTNAME with the my_list_name variable.