Skip to content

Datably-Inc/AutotaskNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutotaskNet

This library assists in reading and writing from the Autotask REST API.

This library is currently in beta and is not recommended for production environments.

Getting Started

Add a reference to the NuGet package in your application:

Install-Package AutotaskNet
dotnet add package AutotaskNet

Register the library in the dependency injection container:

using AutotaskNet.Api;

builder.Services.AddAutotask(new AutotaskCredentials
{
    ApiIntegrationCode = "asdf",
    UserName = "asdf",
    Secret = "asdf"
});

If you have not yet set up your Autotask API User, refer to their documentation.

Finally, inject the IAutotaskNet interface as a dependency.

Usage Examples

Creating Entities

using IAutotaskNet service;

// Root entity
var ticket = new Ticket { ... };
await service.CreateAsync(ticket);

// Child entity
var ticketNote = new TicketNote { ... };
await service.CreateAsync(ticket.Id, ticketNote);

Querying Entities

// Root entity
Ticket ticket = await service.GetAsync<Ticket>(12345);
IEnumerable<Ticket> tickets = await service.QueryAsync<Ticket>(QueryFilter.All, 5); // 5 pages of 500 entities
int ticketUdfMatches = await service.QueryCountAsync<Ticket>(new QueryFilter
{
    Filters =
    [
        new QueryFilter.Filter
        {
            Operator = Operator.Equal,
            Field = "MyUdf",
            Value = "Value",
            IsUdf = true
        }
    ]
});

// Child entity
TicketNote ticketNotes = await service.QueryAsync<TicketNote>(ticket.Id);
TicketNote ticketNote = await service.GetAsync<TicketNote>(ticket.Id, 12345);

Updating Entities

// Root entity
Ticket ticket = await service.GetAsync<Ticket>(12345);
ticket.Title = "New title";
await service.UpdateAsync(ticket);

// Child entity
TicketNote ticketNote = await service.GetAsync<TicketNote>(ticket.Id, 12435);
ticketNote.Description = "New description";
await service.UpdateAsync(ticket.Id, ticketNote);

Deleting Entities

// Root entity
Ticket ticket = await service.GetAsync<Ticket>(12345);
await service.DeleteAsync<Ticket>(ticket.Id);

// Child entity
TicketNote ticketNote = await service.GetAsync<TicketNote>(ticket.Id, 12435);
await service.DeleteAsync<TicketNote>(ticket.Id, ticketNote.Id);

Retrieving Entity Metadata

// Root entity
EntityInformationResult entityInformation = await service.GetEntityInformationAsync<Ticket>();
EntityFieldsResult entityFields = await service.GetEntityFieldsAsync<Ticket>();
EntityUserDefinedFieldsResult entityUserDefinedFields = await service.GetEntityUserDefinedFieldsAsync<Ticket>();

// Child entity
EntityInformationResult entityInformation = await service.GetEntityInformationAsync<TicketNote>(ticket.Id);
EntityFieldsResult entityFields = await service.GetEntityFieldsAsync<TicketNote>(ticket.Id);
EntityUserDefinedFieldsResult entityUserDefinedFields = await service.GetEntityUserDefinedFieldsAsync<TicketNote>(ticket.Id);

Integration Testing

The dependency injection container may not always be available. This is especially the case when writing integration tests without the proper boilerplate for your application's testing framework already set up.

To make this process easier, we have a helper method you can use to create an instance of the IAutotaskNet interface:

using var service = AutotaskNetTestHelper.CreateAutotaskNet(new AutotaskCredentials
{
    ApiIntegrationCode = "", 
    UserName = "",
    Secret = ""
});

This method is recommended to only be used in testing. All other uses of IAutotaskNet should rely on the dependency injection container.

About

A .NET Standard library that assists in reading from and writing to the Autotask REST API.

Topics

Resources

License

Stars

Watchers

Forks

Languages