To create new list entries in SharePoint using Python, you can use the SharePoint REST API. The code provided in the question sets up a connection to a SharePoint site using a client certificate. Once you have a connection, you can use the ListItem
class to create a new list item and add it to a list.
Here is an example of how to create a new list item using the SharePoint REST API in Python:
from office365.sharepoint.listitems.listitem import ListItem
# Set the URL of the SharePoint site and the list name
site_url = 'https://xxx.sharepoint.com/sites/xxx/xxx/'
list_name = 'Sales Records'
# Get the list by name
list_obj = ctx.web.lists.get_by_title(list_name)
# Create a new list item
new_item = ListItem(list_obj)
new_item.set_property('Title', 'New Sales Record')
new_item.set_property('Sales_x0020_Amount', 1000)
new_item.set_property('Sales_x0020_Date', datetime.datetime.now())
# Add the new list item to the list
new_item.add().execute_query()
This code creates a new list item in the "Sales Records" list with a title of "New Sales Record", a sales amount of 1000, and a sales date of the current date and time.
Note that you will need to replace the site_url
and list_name
variables with the URL of your SharePoint site and the name of your list, respectively. You will also need to set up the ctx
object to connect to your SharePoint site using the appropriate credentials.
References: