Abstract: Learn how to automate file uploads from a local drive to a SharePoint On-Premise library using Way API.
2024-06-16 by DevCodeF1 Editors
Automating File Uploads to a Local SharePoint On-Premises Library using the WAY API
In this article, we will explore how to automate file uploads from a local drive to a SharePoint 2019 On-Premises library using the WAY API. This API provides a simple and efficient way to interact with SharePoint libraries, making it an ideal solution for automating file uploads.
What is the WAY API?
The WAY API is a RESTful API that provides a simple way to interact with SharePoint libraries. It is built on top of the SharePoint CSOM (Client-Side Object Model) and allows developers to perform CRUD (Create, Read, Update, Delete) operations on SharePoint libraries using HTTP requests. The WAY API supports both SharePoint Online and SharePoint On-Premises environments.
Prerequisites
To follow along with this article, you will need the following:
- A SharePoint 2019 On-Premises environment
- A SharePoint library to upload files to
- The WAY API installed on your SharePoint environment
- A local folder containing files to upload
Getting Started
To get started, you will need to create a new project in your preferred programming language. In this example, we will be using Python. First, install the requests
library using pip:
pip install requests
Next, create a new Python script and import the requests
library:
import requests
Configuring the API Endpoint
To configure the API endpoint, you will need to know the URL of your SharePoint site and the name of the library you want to upload files to. In this example, we will be using the following endpoint:
https://[sharepoint-site]/_api/way/Library('[library-name]')
Replace [sharepoint-site]
with the URL of your SharePoint site and [library-name]
with the name of your library.
Authenticating with the API
To authenticate with the API, you will need to provide a valid SharePoint username and password. In this example, we will be using the following code to authenticate:
headers = {'Authorization': 'Basic ' + b64encode(bytes('username:password', 'utf-8')).decode(),'Accept': 'application/json;odata=verbose','Content-Type': 'application/json;odata=verbose'}response = requests.get(endpoint, headers=headers)
Replace username
and password
with your SharePoint credentials.
Uploading Files
To upload a file, you will need to send a POST request to the API endpoint with the file content in the request body. In this example, we will be using the following code to upload a file:
file_path = 'C:/folder/file.txt'with open(file_path, 'rb') as file:file_content = file.read()headers = {'Authorization': 'Basic ' + b64encode(bytes('username:password', 'utf-8')).decode(),'Accept': 'application/json;odata=verbose','Content-Type': 'application/octet-stream','X-RequestDigest': response.headers['X-RequestDigest']}response = requests.post(endpoint + '/RootFolder/Files/Add(url=' + file_path.replace('C:\\', '') + ')', headers=headers, data=file_content)
Replace file_path
with the path to the file you want to upload.
In this article, we explored how to automate file uploads to a SharePoint 2019 On-Premises library using the WAY API. We covered the following key concepts:
- What is the WAY API?
- Prerequisites for using the WAY API
- Configuring the API endpoint
- Authenticating with the API
- Uploading files using the API
References
- Get to know the SharePoint Client-Side Object Model (CSOM)
- Get to know the SharePoint REST service
- Working with folders and files with REST
Discover the process of configuring Way API to upload files from your local drive to a SharePoint On-Premise library, streamlining your workflow.
Type Inferred Property Generic Argument Constraint Not Satisfied in TypeScript: Airplane and Boat Inheritance Example
In this article, we'll explore an issue encountered when using type inferred property generic arguments in TypeScript. We'll provide a concrete example using inheritance relationships between interfaces, such as Vehicle, Airplane, and Boat.
On Window FocusChanged Event and Clipboard Access in Software Development
This article explores the use of the onWindowFocusChanged event to access clipboard content in software development. Learn how this event can be used to share data over a network using QR codes with the ZXing library.
Copying and Extending Formula for Excel Cells Vertically: Determining Max Heart Rate Percentage
Learn how to copy and extend a formula to determine your maximum heart rate percentage based on your actual heart rate in Excel.
Handling Image Loading with React Suspense and Fallback: A Cautionary Tale
In this article, we'll discuss a common issue when using React Suspense with image components and provide a solution to prevent fallback re-rendering.
Highlighting Specific Text in PDFs and Exporting Percentages to Excel
In this article, we'll explore how to use Python to highlight specific text in PDFs and export the percentage of highlighted text to Excel cells.
Simple Contrasts Output in SPSS: Estimating Interaction Effects with GENLINMIXED
In this article, we will explore how to estimate simple contrasts for interaction variables in SPSS using the GENLINMIXED command. We will provide an example model and explain the output.