Hi Toon,
The error:
{
"errorCode":"RS401",
"errorMessage":"You need to authenticate to be able to execute this request."
}
usually means the PAT is either:
A few things I'd verify:
Make sure you're sending the PAT as a Bearer token:
Authorization: Bearer <your_pat>
A common mistake is using:
Authorization: Basic <your_pat>
or passing the PAT as a query parameter.
Try calling:
curl -H "Authorization: Bearer <PAT>" </span>
https://repository.api.mendix.com/v1/repositories/<repoId>/branches
If this returns the same RS401, the issue is likely permissions or token configuration.
When creating the Personal Access Token, ensure it includes the permissions required for Repository APIs. A valid PAT for Platform APIs does not automatically guarantee access to every repository endpoint.
Verify that the Mendix account that created the PAT:
Also make sure:
$repoId
is the actual repository ID and not the App ID or Project ID. I've seen those mixed up frequently.
Try a simpler authenticated API endpoint first. If that also returns RS401, then the PAT is not being accepted at all. If other endpoints work and only /repositories/{repoId}/branches fails, then it's more likely a permission or repository access issue.
Most of the time with Repository APIs, RS401 comes down to the Authorization header not being passed as:
Authorization: Bearer <PAT>
or the PAT user lacking access to the target repository.
Hope this helps.