Simple net/http based Personio API client for go.
The required credentials file for authenticating with Personio API v1 looks like follows:
{
"clientId":"YOUR_CLIENT_ID",
"clientSecret":"YOUR_CLIENT_SECRET"
}
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:
- 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) } }
- Put
{"clientId": "CLIENT_ID", "clientSecret": "CLIENT_SECRET"}
into a file namedpersonio-credentials.json
- Run
go run main.go > output.json
- The file
output.json
should now contain the dumped data.