/OSTicketAPI.NET

A .NET Standard 2.0 API that interacts directly with the MySQL database to give you an API for OSTicket in C#.

Primary LanguageC#MIT LicenseMIT

OSTicketAPI.NET

Build status Azure DevOps builds GitHub Nuget (with prereleases) GitHub contributors

This project has been created to add more support for interfacing with OSTicket. The current web API provided my OSTicket is sufficient for submitting new Tickets. However, we found that we wanted to be able to do more with the data inside of OSTicket.

This project is a work in progress

Getting started

This project is currently incomplete and is available for testing and further development

This .NET Library tries to make setup as painless as possible.

This project is build using .Net Standard 2.0

Option 1

First, you want to update your appsettings.json to include the appropriate configuration.

{
    "OSTicket": {
        "BaseUrl": "https://YourOSTicketInstance.net/",
        "ApiKey": "__YourOSTicketApiKey__",
        "DatabaseConnectionString": "server=SERVERNAME;uid=USERID;pwd=PASSWORD;database=osticket;Convert Zero Datetime=True"
    }
}

Note: It is recommended to leave the Convert Zero Date as true.

Add the following to your .Net Core startup.cs file in the ConfigureServices

services.AddOSTicketServices();

Its Important to remember that you need to have the OSTicket configuration in the root off your appsettings.json because that is where this helper expects it to be.

Option 2

Instead of relying on the IConfiguration to be available complete the service setup, you can provide your own values using the OSTicketServiceOptions type.

services.AddOSTicketServices(new OSTicketServiceOptions()
{
    ApiKey = "KEY",
    BaseUrl = "https://localhost:5001/",
    ConnectionString = "YOUR-CONNECTION-STRING"
});

Option 3

In the event that you dont want to use one of the other methods available, you can simply initialize the OSTicketService yourself.

new OSTicketService(DatabaseConnectionString,
    new OSTicketOfficialApi(BaseUrl, ApiKey))

Remember to add it to your dependancy injection if you are using one

Q/A

Why do I need an API key if we are accessing the database directly?

When you are creating a new ticket using the official API, all the approrpriate triggers for emails and notifications will be sent as well. If we just manually inject those records into the database, then these triggers would never occur.

What versions of OSTicket does this work on?

It has been tested on the versions listed below:

osTicket Version osTicket Commit
v1.12 a076918
v1.12.2 a5d898b