SharpSharpLes
SharpSharpLes

Reputation: 324

Update Sharepoint metadata using R

I have an Excel file that I am autopopulating using R and then uploading to my SharePoint site using the "openxlsx" package. After saving this item to SharePoint, I want to set some of the columns of metadata that are associated with my library. I am not really sure if this is possible, and if it is, I have been unable to find anything on Google about it. Has anyone done this before?

Thanks!

To make it easier, here is the code I want to replicate in R but it keeps throwing a "Bad error"

headers_update_metadata ={
    "Accept": "application/json;odata=verbose",
    'Authorization': 'Bearer '+access_token,
    "X-HTTP-Method":"MERGE",
    "If-Match": "*",
    'Content-Type': 'application/json;odata=verbose',
    'Connection':'keep-alive',
}


body = { '__metadata': { 'type': 'SP.Data.Shared_x0020_DocumentsItem' }, 'Author': authorName}

r = requests.post(update_file_url, json=body, headers=headers_update_metadata)

Upvotes: 2

Views: 188

Answers (1)

Emmanuel Hamel
Emmanuel Hamel

Reputation: 2213

You could consider the following approach :

library(RDCOMClient)

body <- '{"__metadata":{"type":"SP.Data.xxx"},"Title":"UpdatedTitle"}'
oXMLHTTP <- COMCreate("MSXML2.XMLHTTP.6.0")
oXMLHTTP$Open("POST", "https://sharepoint.xxx/xxx/xxx/_api/Web/Lists(guid'xxx')/Items(1)", TRUE)
oXMLHTTP$SetRequestHeader("Content-Type", "application/json; odata=verbose")
oXMLHTTP$SetRequestHeader("Accept", "application/json; odata=verbose")
oXMLHTTP$SetRequestHeader("X-HTTP-Method", "MERGE")
oXMLHTTP$SetRequestHeader("If-Match", "*")
oXMLHTTP$Send(body)
oXMLHTTP$Status()
oXMLHTTP$responseText()

Upvotes: 0

Related Questions