Skip to content

kathanjain/python-dataverse-batch-azure-function

Repository files navigation

Dataverse Batch Operations

This project demonstrates how to perform bulk create and delete operations in Microsoft Dataverse using the Web API $batch endpoint.

Features

  • Azure AD authentication using MSAL
  • Batch create and delete for Dataverse tables
  • Error handling for partial failures
  • Configurable via .env file

Structure

  • auth.py: Handles Azure AD authentication using MSAL and environment variables
  • batch_builder.py: Builds robust $batch payloads for Dataverse create/delete operations
  • dataverse_client.py: Sends batch requests, parses responses, and handles errors
  • main.py: CLI entry point for local testing and demonstration
  • BatchDataverseFunction/__init__.py: Azure Function entry point (uses modularized code)

Setup

  1. Install dependencies:
    pip install -r requirements.txt
  2. Copy .env.example to .env and fill in your Azure/Dataverse credentials.
  3. To test locally (CLI):
    python main.py
  4. To run as an Azure Function:
    • Make sure you have Azure Functions Core Tools installed.
    • Start the function host:
      func start
    • POST an Excel file to the function endpoint (see below).

Requirements

  • Python 3.8+
  • requests, msal, python-dotenv, openpyxl, azure-functions

Usage

Local CLI

Run the sample with:

python main.py

This will load an Excel file, map columns, and perform batch create operations in Dataverse.

Azure Function

Start the function host:

func start

Then upload your Excel file using Postman or curl:

curl -X POST http://localhost:7071/api/BatchDataverseFunction -F "file=@test/PowerPlatform_All_Users_Synthetic.xlsx"

The function will log progress and return a JSON result for each record.

Notes

  • All values for string columns are now explicitly cast to strings to avoid Dataverse type errors.
  • Only batch creation (insert) is supported in this version. Batch delete/update is planned.

Troubleshooting

  • 400 Bad Request / Edm.String error: Ensure all values for string columns are sent as strings (this is now handled automatically).
  • 404 Resource not found: Check your table/entity set name and column logical names.
  • 401/403 Unauthorized: Ensure your app registration has correct permissions and is added as an Application User in Dataverse.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages