Discussions

Ask a Question
Back to All

POST Attendances

why does this transfer not work? (Employee ID and token have been replaced)


[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]'Tls11,Tls12'
$headers=@{}
$headers.Add("accept", "application/json")
$headers.Add("content-type", "application/json")
$headers.Add("authorization", "$Token")

$response = Invoke-WebRequest -Uri 'https://api.personio.de/v1/company/attendances' -Method POST -Headers $headers -ContentType 'application/json' -Body '{"attendances":[{"employee":XXXXXXX,"date":"2024-01-18","start_time":"06:37","end_time":"16:47","break":45,"comment":"Test5 Übertragung von TA Zeitblick"},{"employee":XXXXXXX,"date":"2024-01-19","start_time":"06:35","end_time":"15:37","break":30,"comment":"Test6 Übertragung von TA Zeitblick"}]}'

Server response
Invoke-WebRequest : Der Remoteserver hat einen Fehler zurückgegeben: (400) Ungültige Anforderung.
In D:\Scripte\TA_Zeitblick_Archiv\Hilfe\Personio\Anwesenheiten_nach_Personio_uebertragen_JSON.PS1:55 Zeichen:13

  • $response = Invoke-WebRequest -Uri 'https://api.personio.de/v1/compan ...
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

{"success":true,"data":{"token":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","expires_in":86400,"scope":"employees:read employees:write attendances:read attendances:write absences:read absences:write documents
:read documents:write reports.custom:read reports.custom:write"}}

Thanks Bert

Admin

Hi Bert,

when encountering a 400 Bad Request error, it is important to check if the error response from the API includes detailed information about the issue. For example, a typical error response may look like this:
{
"success": false,
"error": {
"code": 400,
"message": "Error when trying to insert Attendances periods rows",
"detailed_message": [
{
"success": true,
"error_msg": null,
"id": 1,
"employee": 1234,
"date": "202-01-01",
"start_time": "09:00",
"end_time": "18:00",
"break": 60,
"comment": "",
"project_id": 5
},
{
"success": false,
"error_msg": "Existing overlapping attendances periods",
"id": null,
"employee": 1234,
"date": "2024-01-01",
"start_time": "09:00",
"end_time": "18:00",
"break": 60,
"comment": "",
"project_id": null
}
]
}
}
In the example above, the detailed_message section provides specific information about each attendance period. This can help identify the exact cause of the error. In this case, it indicates an "Existing overlapping attendances periods" issue for the employee with ID 1234 on the date "2024-01-01".

Please verify if your error response contains similar detailed messages. If you do see such details, they will guide you on what needs to be corrected in your request. Common issues include overlapping attendance periods or incorrect data formats.

If there is no further explanation provided, which is unlikely, please check proactively for already existing and therefore overlapping attendance periods.

Best,
Christoph

Marked as answered by Christoph

Hello Christoph,
I have already ruled out such possibilities. I sent the data in the developer hub. Everything worked there. Then I copied the data, changed the day (the new days are completely empty) and sent it via powershell with the script mentioned above. That gives an error.
What else can I try?

Regards Bert

Admin

Hi Bert,

in this case I would ask you to check if there is anymore details provided in the error message. It appears that the issue is not a bug in the API but rather a problem within your code. Unfortunately, we cannot provide support for code-related issues as they fall outside the scope of our support services.

Best,
Christoph