OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Folder Creation in python using Graph creates empty child folder

  • Thread starter Thread starter GBilianis
  • Start date Start date
G

GBilianis

Guest
I am trying to automatically create an amount of folders in a Sharepoint site. Each time I call this function, it creates empty folder as well.

Code:
    def create_folder_in_drive(access_token, drive_id, parent_path, folder_name):
create_url = f'https://graph.microsoft.com/v1.0/drives/{drive_id}/root:/{parent_path}/{folder_name}:/children'
headers = {
    'Authorization': f'Bearer {access_token}',
    'Content-Type': 'application/json'
}
folder_data = {
    "name": folder_name,
    "folder": {},
    "@microsoft.graph.conflictBehavior": "rename"
}
create_response = requests.post(create_url, headers=headers, json=folder_data)
create_response.raise_for_status()
return create_response.json()

For example, if my folder structure would be : (Parent):foo->(child):bar, the result would be: (Parent):foo->(Children):foo,bar.

I have tried removing the :/children part, but it results in a 400 error. Any suggestions?
<p>I am trying to automatically create an amount of folders in a Sharepoint site.
Each time I call this function, it creates empty folder as well.</p>
<pre><code> def create_folder_in_drive(access_token, drive_id, parent_path, folder_name):
create_url = f'https://graph.microsoft.com/v1.0/drives/{drive_id}/root:/{parent_path}/{folder_name}:/children'
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
folder_data = {
"name": folder_name,
"folder": {},
"@microsoft.graph.conflictBehavior": "rename"
}
create_response = requests.post(create_url, headers=headers, json=folder_data)
create_response.raise_for_status()
return create_response.json()
</code></pre>
<p>For example, if my folder structure would be : (Parent):foo->(child):bar, the result would be: (Parent):foo->(Children):foo,bar.</p>
<p>I have tried removing the :/children part, but it results in a 400 error. Any suggestions?</p>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top