Python Connector for Dynamics 365 Business Central

Using the module - Python Connector for Dynamics 365 Business Central

Using the module

To retrieve data from Dynamics 365 Business Central:

  1. Import the module.
    import devart.dynamicsbc as dynamicsbc
  2. Connect to a database using the connect() module method and obtain a connection object:
    • If you're using basic authentication:
      my_connection = dynamicsbc.connect(
          Authentication="Basic",
      Server="your_dynamics365_url",
      UserId="your_username",
      AccessKey="your_access_key",
      CompanyId="your_company_id" )
    • If you're using OAuth 2.0 authentication:
      response = dynamicsbc.signin()
      my_environments = dynamicsbc.getenvironments(
          RefreshToken=response["Refresh Token"]
      )
      my_companies = dynamicsbc.getcompanies(
          RefreshToken=response["Refresh Token"],
          Environment=my_environments[0]
      )
      my_connection = dynamicsbc.connect(
          Authentication="OAuth",
          RefreshToken=response["Refresh Token"],
          Environment=my_environments[0],
          CompanyId=my_companies[0]["Company Id"]
      )
  3. Create a cursor object using the cursor() connection method.
    my_cursor = my_connection.cursor()
  4. Execute the SQL statement using the execute() cursor method.
    my_cursor.execute("SELECT * FROM Company")
  5. Retrieve the result set using one of the fetch*() cursor methods.
    for row in my_cursor.fetchall(): 
        print(row)
© 2022-2025 Devart. All Rights Reserved. Request Support Python Connectors Forum Provide Feedback