0

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.

ai88
  • 33
  • 4

1 Answers1

1

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.

Gaurav T
  • 257
  • 1
  • 6
  • Thank you for your help. Looks like I'm getting this error: "Exception: __metadata not a column in current List." (That's "__metadata" with two underscores right?) Where may I ask are you getting this metadata thing you suggested? What docs? – ai88 Mar 07 '23 at 02:07
  • 1
    See here - https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest#update-list-item – Gaurav T Mar 07 '23 at 02:59