Skip to content

PascalTemel/personio-go

 
 

Repository files navigation

CircleCI

personio-go

Simple net/http based Personio API client for go.

Credentials File

The required credentials file for authenticating with Personio API v1 looks like follows:

{ "clientId":"YOUR_CLIENT_ID", "clientSecret":"YOUR_CLIENT_SECRET" } 

Usage Example

The following example exercises the v1.GetEmployees() and v1.GetTimeOffs() functions to dump all employees and time-offs.

To run this example, perform these steps:

  1. Put the following code into a file named main.go
    package main import ( "context" "encoding/json" "log" "os" v1 "github.com/giantswarm/personio-go/v1" ) // main dumps all data returned by the v1.GetEmployees() and v1.GetTimeOffs() functions to STDOUT func main() { credentials, err := os.ReadFile("personio-credentials.json") if err != nil { log.Fatal(err) } var personioCredentials v1.Credentials err = json.Unmarshal(credentials, &personioCredentials) if err != nil { log.Fatal(err) } personio, err := v1.NewClient(context.TODO(), v1.DefaultBaseUrl, personioCredentials) timeOffs, err := personio.GetTimeOffs(nil, nil, 0, 1000) if err != nil { log.Fatal(err) } employees, err := personio.GetEmployees() if err != nil { log.Fatal(err) } type dump struct { Employees []*v1.Employee `json:"employees"` TimeOffs []*v1.TimeOff `json:"timeOffs"` } jsonDump, _ := json.MarshalIndent(dump{Employees: employees, TimeOffs: timeOffs}, "", " ") os.Stdout.Write(jsonDump) log.Printf("EMPLOYEE\tDEPARTMENT\n") for _, employee := range employees { firstName := *employee.GetStringAttribute("first_name") lastName := *employee.GetStringAttribute("last_name") departmentName, _ := employee.GetMapAttribute("department")["name"].(string) log.Printf("%s\t%s\t%s\n", firstName, lastName, departmentName) } }
  2. Put {"clientId": "CLIENT_ID", "clientSecret": "CLIENT_SECRET"} into a file named personio-credentials.json
  3. Run go run main.go > output.json
  4. The file output.json should now contain the dumped data.

About

Personio Client for Go

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 87.5%
  • Makefile 12.5%