I'm sucessfully getting a list from shareplum, and using "UpdateListItems" method to update a value.
sharepoint_site = authenticate(MY_SHAREPOINT_URL, MY_SHAREPOINT_SITE, MY_USERNAME, MY_PASSWORD)
sharepoint_list = get_sp_list(sharepoint_site , MY_SHAREPOINT_LIST)
# "Name" is the column that I am trying to update
data = [{'ID': "13", 'Name': 'Teste Python'}]
sharepoint_list.UpdateListItems(data=data, kind='Update')
time.sleep(3)
# at this point, my sharepoint online list is just the same as It was
I'm using ID as the index of certain row that I want to update (I'm trying to update the 13th element). But once I update the value, nothing happens on online sharepoint. The idea I had is that I would do some integration with other local databases, and use that data to upload certain things to a List (a csv/excel file) that is shared on Sharepoint. Currently my users are manually updating things on that sharepoint online list.
Is there any other command I should use to actually upload my new list to online sharepoint?
The 13th element doesn´t necessarily have ID=13 in SharePoint. If you remove items from a SharePoint list that ID is gone forever. Check if you got the right ID.
Also check that the ínternal name of the column (field) really is "Name". Go to list settings and click on the column and look at the URL and it will look something like this towards the end:
/_layouts/15/FldEdit.aspx?List=%7B681071B5-D6BB-4345-894A-69C2D9E27A3C%7D&Field=Prio
The internal name is what comes after Field= and it can be something else than you see when you view the list.
Related
so I know how to add item to a list by POST
f"{graph_url}/sites/{site_id}/lists/{list_id}/items"
But in this list I have specific folder where I want insert my item.
How the url should looks like?
Lets say {item_id} is the ID of the folder (which is another item on that list to be precise)
Should it be something like:
f"{graph_url}/sites/{site_id}/lists/{list_id}/item/{item_id}/items"
?
I went through documentation and couldnt find anything, is it even possible?
I just want to add item to a list to a specific folder in this list.
To update item in the folder of a SharePoint site you can use query:
PATCH /sites/{site-id}/drive/items/{item-id}
Permission for this query:
For more information:https://learn.microsoft.com/en-us/graph/api/driveitem-update?view=graph-rest-1.0&tabs=http#permissions
Hope this helps.
I'm going crazy trying to get data through an API call using request and pandas. It looks like it's nested data, but I cant get the data i need.
https://xorosoft.docs.apiary.io/#reference/sales-orders/get-sales-orders
above is the api documentation. I'm just trying to keep it simple and get the itemnumber and qtyremainingtoship, but i cant even figure out how to access the nested data. I'm trying to use DataFrame to get it, but am just lost. any help would be appreciated. i keep getting stuck at the 'Data' level.
type(json['Data'])
df = pd.DataFrame(['Data'])
df.explode('SoEstimateHeader')
df.explode('SoEstimateHeader')
Cell In [64], line 1
df.explode([0:])
^
SyntaxError: invalid syntax
I used the link to grab a sample response from the API documentation page you provided. From the code you provided it looks like you are already able to get the data and I'm assuming the you have it as a dictionary type already.
From what I can tell I don't think you should be using pandas, unless its some downstream requirement in the task you are doing. But to get the ItemNumber & QtyRemainingToShip you can use the code below.
# get the interesting part of the data out of the api response
data_list = json['Data']
#the data_list is only one element long, so grab the first element which is of type dictionary
data = data_list[0]
# the dictionary has two keys at the top level
so_estimate_header = data['SoEstimateHeader']
# similar to the data list the value associated with "SoEstimateItemLineArr" is of type list and has 1 element in it, so we grab the first & only element.
so_estimate_item_line_arr = data['SoEstimateItemLineArr'][0]
# now we can grab the pieces of information we're interested in out of the dictionary
qtyremainingtoship = so_estimate_item_line_arr["QtyRemainingToShip"]
itemnumber = so_estimate_item_line_arr["ItemNumber"]
print("QtyRemainingToShip: ", qtyremainingtoship)
print("ItemNumber: ", itemnumber)
Output
QtyRemainingToShip: 1
ItemNumber: BC
Side Note
As a side note I wouldn't name any variables json because thats also the name of a popular library in python for parsing json, so that will be confusing to future readers and will clash with the name if you end up having to import the json library.
I am trying to integrate SharePoint in one of my Python Scripts and I need to grab the users from a SP list. Until now, I managed to log in, search for a specific list, and enumerate all of its items.
def enum_items(list):
items = list.items # .top(1220)
ctx.load(items)
ctx.execute_query()
for index, item in enumerate(items):
print("{0}: {1}".format(index, item.properties['Email']))
The 'Email' column's value is set to User.email like so:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "[$User.email]"
}
Basically the Email is automatically set when a new user is added in the User column.
Some entries where manually added, and others use the above code. For those that were manually added it prints the email, but for the other, it prints: "None".
If I change the 'Email' to 'User', I get the following error, like it cannot find that column or so:
print("{0}: {1}".format(index, item.properties['User']))
KeyError: 'User'
Is there anyway I can grab the USER object, and then use its properties (which ever those are) to grab some information about it?
Thanks!
Thanks for you help & time, here is my code, I am accessing a specific cell of a table and my goal is to modify the text context of this specific cell - by that I mean to overwrite the existing text in that cell with a new string value. How do I do that?
def main():
credentials = get_creds()
service = build("docs", "v1", credentials=credentials).documents()
properties_req = service.get(documentId=REQ_DOCUMENT_ID).execute()
doc_content_req = properties_req.get('body').get('content')
properties_des = service.get(documentId=DES_DOCUMENT_ID).execute()
doc_content_des = properties_des.get('body').get('content')
reqs = find_requirements(doc_content_req)
for (req, row) in zip(reqs, req_table.get('tableRows')):
loc = search_structural_elements(doc_content_des, req)
cell = get_cell(row, design_col)
print(f"Requirement {req} is located in section {loc} of the design doc.")
print(cell) # Need to modify the text content of this specific cell
You can easily modify the contents of a particular cell by using the Documents.batchUpdate() tool. First and foremost I strongly recommend you to familiarize yourself with the Table structure inside a Doc. There you can see how the table is first declared, then divided in rows and later formatted with some styles. After you write the desired change in the desired cell (from the desired row), then you can use Documents.batchUpdate() and reach your goal.
As a tip, I want to add that you can run a small trick to easily find the desired cell. This operation can help you manage your first cell edit easily. First you will need to open the Doc in a browser, then you have to write a recognizable string (like 123ABC) in the desired cell. After that you could use Documents.get() to receive the Document object. You can search for the 123ABC string without difficulty in that object, change it to the desired value, and use that object as a template for the batch update. Please ask me any additional questions about this answer.
Instead of using get_by_id() method for getting the id of a specific entry and print the content of this entry from the google datastore, i am trying to get the name of the url and print the content. For example:
print all the content that have this specific name(may have more than one rows of content with this name)
print the content of the specific id
i am using get_by_id(long(id)) to get the id in the second part of my example, and its working. I am trying to use get_by_key_name(name) but it does not working. any ideas on that? thank you.
sorry, but since i couldn't leave a comment, i am editing my question. Basically, since now i can get all the name of animals from my datastore and i have made them clickable using an html code in template file. In the datastore, there are entries with the same name of animal more than one times (e.g. name= duck, content= water and name=duck, content=lake). Now, when i am clicking into every name of animals(i have use the DINSTINCT in my gql query to print redundant elements(e.g. duck) only one time).Since the name=duck has two contents, when i am clicking on the name of the duck i want to see both of the contents. My problem is if i am using get_by_id(long(id)) i get the unique id of every element. But this will not print me both of the content of the name=duck because every entry has a unique id. But i want all the content of the entries with the same name. I am trying the following but it does not working.
msg = MODEL.Animals.get_by_key_name(name)
self.response.write("%s" % msg.content)
With get_by_id() you can get entity only if you know this ID. This operations named "Small operations" in quota and they are cheaper than datastore reads, but to get list of entities filtered by indexed property - you should use filters.
query = MODEL.Animals.query()
query = query.filter(MODEL.Animals.name == 'duck')
ducks = query.fetch(limit=100) # limit number of returned animals
for duck in ducks:
self.response.write('%s - %s' % (duck.name, duck.content))
By default, all string properties are indexed, so you will be able to do such requests.