Skip to content

avadev/Avalara-SDK-DotNet

Repository files navigation

Avalara.SDK - the C# library for the foundation

Platform foundation consists of services on top of which the Avalara Compliance Cloud platform is built. These services are foundational and provide functionality such as common organization, tenant and user management for the rest of the compliance platform.

Frameworks supported

  • .NET Core >=1.0
  • .NET Framework >=4.6
  • Mono/Xamarin >=vNext

Dependencies

The DLLs included in the package may not be the latest version. We recommend using NuGet to obtain the latest version of the packages:

Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
Install-Package System.ComponentModel.Annotations

Getting Started

using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using Avalara.SDK.Api.Avatax;
using Avalara.SDK.Client;
using Avalara.SDK.Model.Avatax;

namespace Example
{
    public class Example
    {
        public static void Main()
        {

           Configuration config = new Configuration();
            config.Environment = AvalaraEnvironment.Sandbox;
            config.BearerToken = "<Your Bearer Token>";

            ApiClient apiClient= new ApiClient(config);

            var apiInstance = new AddressesApi(apiClient);
            var requestParameters = new ResolveAddressPostRequest();
            requestParameters.xAvalaraClient = "\"Swagger UI; 22.7.0; Custom; 1.0\"";  // string | Identifies the software you are using to call this API.  For more information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) . (optional)  (default to "Swagger UI; 22.7.0; Custom; 1.0")
            requestParameters.body = new AddressValidationInfo(); // AddressValidationInfo | The address to resolve (optional)

            try
            {
                // Retrieve geolocation information for a specified address
                AddressResolutionModel result = apiInstance.ResolveAddressPost(requestParameters);
                Debug.WriteLine(result);
            }
            catch (ApiException  e)
            {
                Debug.Print("Exception when calling AddressesApi.ResolveAddressPost: " + e.Message );
                Debug.Print("Status Code: "+ e.ErrorCode);
                Debug.Print(e.StackTrace);
            }

        }
    }
}

Documentation for Authorization

OAuth Client Credentials

  • Type: OAuth
  • Flow: client_credentials
  • Scopes:
    • avatax_api: avatax_api scope.
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using Avalara.SDK.Api.IAMDS;
using Avalara.SDK.Client;
using Avalara.SDK.Model.IAMDS;

namespace Example
{
    public class Example
    {
        public static void Main()
        {

            Configuration configuration = new Configuration();
            configuration.Environment = AvalaraEnvironment.Sandbox;
            // Avalara Identity Client ID, it can be hard coded or stored as an environment variable as per the example.
            configuration.ClientID = Environment.GetEnvironmentVariable("CLIENT_ID");
            // Avalara Identity Client Secret, do not check in this value to source control.
            configuration.ClientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET");

            configuration.AppName = "Test";
            configuration.AppVersion = "1.0";
            configuration.MachineName = "LocalBox";

            apiclient = new ApiClient(configuration);

            var apiInstance = new AddressesApi(apiClient);

            var requestParameters = new ResolveAddressPostRequest();

            requestParameters.xAvalaraClient = "\"Swagger UI; 22.7.0; Custom; 1.0\"";  // string | Identifies the software you are using to call this API.  For more    information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) . (optional)  (default to "Swagger UI; 22.7.0; Custom; 1.0")
            requestParameters.body = new AddressValidationInfo(); // AddressValidationInfo | The address to resolve (optional)

            try
            {
                // OAuth 2 Client Credential Flow will automatically be invoked, retrieve the JWT token from Avalara Identity,
                // and append the token into the Authorization header of the request.
                AddressResolutionModel result = apiInstance.ResolveAddressPost(requestParameters);
                Debug.WriteLine(result);
            }
            catch (ApiException  e)
            {
                Debug.Print("Exception when calling AddressesApi.ResolveAddressPost: " + e.Message );
                Debug.Print("Status Code: "+ e.ErrorCode);
                Debug.Print(e.StackTrace);
            }

        }
    }
}

OAuth Device Code

  • Type: OAuth
  • Flow: device_code
  • Scopes:
    • avatax_api: avatax_api scope.
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using Avalara.SDK.Api.IAMDS;
using Avalara.SDK.Client;
using Avalara.SDK.Model.IAMDS;

namespace Example
{
    public class Example
    {
        public static void Main()
        {

            Configuration configuration = new Configuration();
            configuration.Environment = AvalaraEnvironment.Sandbox;
            // Avalara Identity Client ID, it can be hard coded or stored as an environment variable as per the example.
            configuration.ClientID = Environment.GetEnvironmentVariable("CLIENT_ID");
            configuration.AppName = "Test";
            configuration.AppVersion = "1.0";
            configuration.MachineName = "LocalBox";

            // Pass in the scope (avatax_api in this instance), and the configuration object, clientID is a required property for the flow.
            // Fetches the device code and verification url required for the user part of the flow (where they open the URI in their web browser and authenticate)
            var deviceResponse = OAuthHelper.initiateDeviceAuthorizationFlow("avatax_api", configuration);
            // Retrieves the accessToken and other metadata relating to the auth request.
            var tokenResponse = OAuthHelper.getAccessTokenForDeviceFlow(deviceResponse.DeviceCode, configuration);
            // Token retrieved from the device code flow will be used in the Authorization header for the requests.
            configuration.BearerToken = tokenResponse.AccessToken;

            apiclient = new ApiClient(configuration);

            var apiInstance = new AddressesApi(apiClient);

            var requestParameters = new ResolveAddressPostRequest();

            requestParameters.xAvalaraClient = "\"Swagger UI; 22.7.0; Custom; 1.0\"";  // string | Identifies the software you are using to call this API.  For more    information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) . (optional)  (default to "Swagger UI; 22.7.0; Custom; 1.0")
            requestParameters.body = new AddressValidationInfo(); // AddressValidationInfo | The address to resolve (optional)

            try
            {
                // OAuth 2 Client Credential Flow will automatically be invoked, retrieve the JWT token from Avalara Identity,
                // and append the token into the Authorization header of the request.
                AddressResolutionModel result = apiInstance.ResolveAddressPost(requestParameters);
                Debug.WriteLine(result);
            }
            catch (ApiException  e)
            {
                Debug.Print("Exception when calling AddressesApi.ResolveAddressPost: " + e.Message );
                Debug.Print("Status Code: "+ e.ErrorCode);
                Debug.Print(e.StackTrace);
            }

        }
    }
}

Documentation for API Endpoints

EInvoicing V1 API Documentation

Class Method HTTP request Description
DataInputFieldsApi GetDataInputFields GET /data-input-fields Returns the mandatory and conditional invoice or creditnote input fields for different country mandates
DocumentsApi DownloadDocument GET /documents/{documentId}/$download Returns a copy of the document
DocumentsApi GetDocumentList GET /documents Returns a summary of documents for a date range
DocumentsApi GetDocumentStatus GET /document/{documentId}/status Checks the status of a document
DocumentsApi SubmitDocument POST /documents Submits a document to Avalara E-Invoicing API
MandatesApi GetMandates GET /mandates List country mandates that are supported by the Avalara E-Invoicing platform

Documentation for Models

EInvoicing V1 Model Documentation