Automating File Uploads from Local Drive to SharePoint On-Premise using Way API (2024)

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

Discover the process of configuring Way API to upload files from your local drive to a SharePoint On-Premise library, streamlining your workflow.

Automating File Uploads from Local Drive to SharePoint On-Premise using Way API (2024)

References

Top Articles
Latest Posts
Article information

Author: Trent Wehner

Last Updated:

Views: 5742

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.