Ask a Question
Back to All

BadRequest when trying to post attendance record

Hello, I am trying to post multiple attendance records for an employee using the personio api. But I always get a BadRequest error in the response. I tried the exact same post body example with attendances in my code but still all I get in the response is "please enter attendances".

This is how I execute and create the request:

// Post new slots
var request = new RestRequest("company/attendances?", Method.Post);
request.AddHeader("accept", "application/json");
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", personioToken);
request.AddParameter("attendances", Attendance.TimeSlot.getJsonPost(toPost.ToArray(), pEmpId), ParameterType.RequestBody);
var response = client.Execute(request);
personioToken = extractToken(response);

This is how I build the attendances value as JsonFormat from my TimeSlot object:

public static string getJsonPost(TimeSlot[] timeSlots, int pEmpId)
string jsonFormat = "";
jsonFormat += "{"attendances":[";
foreach (TimeSlot timeSlot in timeSlots)
jsonFormat +=
"{" +
""employee":" + pEmpId +
","date":"" + timeSlot.date.ToString("yyyy-MM-dd") +
"","start_time":"" + timeSlot.start_time.ToString("HH:MM") +
"","end_time":"" + timeSlot.end_time.Value.ToString("HH:MM") +
"","break":" + timeSlot.getTotalMinBreak() +
","project_id": null" +
","comment":"" + timeSlot.comment + """ +
if (timeSlot != timeSlots.Last()) jsonFormat += ",";
jsonFormat += "]}";

        return jsonFormat;