Skip to content

Conversation

@aaronbartell
Copy link
Collaborator

I included a unit test file though also ran tests against sandbox with the following script.

using System;
using System.IO;

using Avalara.SDK.Client;
using Avalara.SDK.Helpers;
using Avalara.SDK.Api.EInvoicing.V1;
using Avalara.SDK.Api.A1099.V2;
using Avalara.SDK.Model.A1099.V2;
using System.Threading.Tasks;
using System.Diagnostics;
// See https://aka.ms/new-console-template for more information
Configuration configuration = new Configuration
{
    Environment = AvalaraEnvironment.Sandbox,
    BearerToken = Environment.GetEnvironmentVariable("BEARER_TOKEN"),
    AppName = "Test",
    AppVersion = "1.0",
    MachineName = "LocalBox"
};

ApiClient apiClient = new ApiClient(configuration);
var issuersApi = new Issuers1099Api(apiClient);
var formsApi = new Forms1099Api(apiClient);
string correlationId = Guid.NewGuid().ToString();

try {
    var issuer = new IssuerRequest(
        name: "SDK test",
        telephone: "206-555-0100",
        taxYear: DateTime.Now.Year,
        countryCode: "US",
        address: "456 Business Ave",
        city: "Seattle",
        state: "WA",
        zip: "98101",
        lastFiling: false,
        tin: "123000000",
        email: "contact@testcompany.com",
        referenceId: $"ISSUER-{Guid.NewGuid().ToString().Substring(0, 8)}"
    );
    var createdIssuer = await issuersApi.CreateIssuerAsync(new CreateIssuerRequestSdk { IssuerRequest = issuer, XCorrelationId = correlationId });
    Console.WriteLine($"Issuer created successfully! ID: {createdIssuer.Id}, Name: {createdIssuer.Name}\n");


    var form1099Nec = new Form1099Nec(
        type: Form1099Nec.TypeEnum._1099NEC,
        issuerId: createdIssuer.Id.ToString(),
        nonemployeeCompensation: 5000.00,
        recipientName: "John Doe",
        address: "123 Main Street",
        city: "Seattle",
        state: "WA",
        zip: "98101",
        countryCode: "US",
        tin: "123-00-6789",
        tinType: Form1099Nec.TinTypeEnum.SSN,
        email: "john.doe@example.com",
        referenceId: $"TEST-{Guid.NewGuid().ToString().Substring(0, 8)}"
    );
    form1099Nec = (Form1099Nec)(await formsApi.Create1099FormAsync(new Create1099FormRequestSdk { Get1099Form200Response = new Get1099Form200Response(form1099Nec), XCorrelationId = correlationId })).ActualInstance;
    Console.WriteLine($"Created 1099-NEC form ID: {form1099Nec.Id}, Reference ID: {form1099Nec.ReferenceId}, Recipient: {form1099Nec.RecipientName}\n");


    var form1099Misc = new Form1099Misc(
        type: Form1099Misc.TypeEnum._1099MISC,
        issuerId: createdIssuer.Id.ToString(),
        rents: 3000.00,
        recipientName: "Jane Smith",
        address: "456 Oak Avenue",
        city: "Portland",
        state: "OR",
        zip: "97201",
        countryCode: "US",
        tin: "123-00-6543",
        tinType: Form1099Misc.TinTypeEnum.SSN,
        email: "jane.smith@example.com",
        referenceId: $"TEST-{Guid.NewGuid().ToString().Substring(0, 8)}"
    );
    form1099Misc = (Form1099Misc)(await formsApi.Create1099FormAsync(new Create1099FormRequestSdk { Get1099Form200Response = new Get1099Form200Response(form1099Misc), XCorrelationId = correlationId })).ActualInstance;
    Console.WriteLine($"Created 1099-MISC form ID: {form1099Misc.Id}, Reference ID: {form1099Misc.ReferenceId}, Recipient: {form1099Misc.RecipientName}\n");


    form1099Nec = (Form1099Nec)(await formsApi.Get1099FormAsync(new Get1099FormRequestSdk { Id = form1099Nec.Id, XCorrelationId = correlationId })).ActualInstance;
    Console.WriteLine($"Retrieved 1099-NEC: {form1099Nec.Id} {form1099Nec.ReferenceId} {form1099Nec.RecipientName}\n");

    form1099Misc = (Form1099Misc)(await formsApi.Get1099FormAsync(new Get1099FormRequestSdk { Id = form1099Misc.Id, XCorrelationId = correlationId })).ActualInstance;
    Console.WriteLine($"Retrieved 1099-MISC: {form1099Misc.Id} {form1099Misc.ReferenceId} {form1099Misc.RecipientName}\n");



    var formsListResponse = await formsApi.List1099FormsAsync(new List1099FormsRequestSdk { Filter = $"issuerId eq '{createdIssuer.Id}'", XCorrelationId = correlationId });
    foreach (var formWrapper in formsListResponse.Value)
    {
        dynamic form = formWrapper.ActualInstance;
        Console.WriteLine($"  - Form ID: {form.Id}, Type: {form.Type}, Recipient: {form.RecipientName}, Reference: {form.ReferenceId}");
    }


    var necPdfFile = await formsApi.Get1099FormPdfAsync(new Get1099FormPdfRequestSdk { Id = form1099Nec.Id, XCorrelationId = correlationId });
    string necPdfPath = $"Form1099NEC_{form1099Nec.Id}.pdf";
    using (var fileStream = File.Create(necPdfPath))
    {
        necPdfFile.Content.Position = 0;
        await necPdfFile.Content.CopyToAsync(fileStream);
    }
    Console.WriteLine($"1099-NEC PDF saved to: {necPdfPath}");

    var miscPdfFile = await formsApi.Get1099FormPdfAsync(new Get1099FormPdfRequestSdk { Id = form1099Misc.Id, XCorrelationId = correlationId });
    string miscPdfPath = $"Form1099MISC_{form1099Misc.Id}.pdf";
    using (var fileStream = File.Create(miscPdfPath))
    {
        miscPdfFile.Content.Position = 0;
        await miscPdfFile.Content.CopyToAsync(fileStream);
    }
    Console.WriteLine($"1099-MISC PDF saved to: {miscPdfPath}");


    await new Issuers1099Api(apiClient).DeleteIssuerAsync(new DeleteIssuerRequestSdk { Id = createdIssuer.Id.ToString(), XCorrelationId = correlationId });
    Console.WriteLine($"\nIssuer deleted successfully! ID: {createdIssuer.Id}");
} catch (ApiException e) {
    Console.WriteLine($"API Exception occurred: {e.Message}\nStatus Code: {e.ErrorCode}\n{e.StackTrace}");
} catch (Exception e) {
    Console.WriteLine($"Unexpected exception occurred: {e.Message}\n{e.StackTrace}");
}

@svc-developer svc-developer merged commit 2fb68c6 into main Dec 1, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants