Skip to content

theapsgroup/go-freshservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-freshservice

An unofficial Go client for the FreshService API.

Usage

import "github.com/theapsgroup/go-freshservice/freshservice"

Simply create a new FreshService client, then use the various services on the client to access the different resource types on the FreshService API.

ctx := context.Background()
fs, err := freshservice.NewClient(ctx, "company", "MY-API-TOKEN")
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}

By default, domain parameter are complete with freshservice url company ==> https://company.freshservice.com/api/v2/. If you set a full domain http(s)://fresh.my.corp/api/v2 it will be used as is.

Example

The below example aims to give a short introduction in how to use the client and services.

package main

import (
    "context"
    "github.com/theapsgroup/go-freshservice/freshservice"
    "log"
)

func main() {
    ctx := context.Background()
    fs, err := freshservice.NewClient(ctx, "company", "MY-API-TOKEN")
    if err != nil {
        log.Fatalf("Failed to create client: %v", err)
    }

    // Obtain info for a user (Requester)
    requester, _, err := fs.Requesters.GetRequester(123)
    log.Printf("%s %s - %s\n", requester.FirstName, requester.LastName, requester.Email)

    // Obtain second page of Tickets for the Requester
    opt := freshservice.ListTicketsOptions{
        Email: &requester.Email,
        ListOptions: freshservice.ListOptions{
            Page: 2,
        },
    }

    tickets, _, err := fs.Tickets.ListTickets(&opt)
    for _, ticket := range tickets.Collection {
        log.Printf("Ticket: %d (%s)\n", ticket.ID, ticket.Subject)
    }
}