I'm trying to Update a test.json file hosted on a Azure DevOps Repo. I'm using a Logic App. Having trouble identifying the order of operations from the documentation.
I think I need to...
Issue a GET HTTP request to the
Itemsendpoint:https://dev.azure.com/myOrg/myProject/_apis/git/repositories/myRepoID/items?scopePath=/data/test.json&$format=json&api-version=6.0- Response:
{ "count": 1, "value": [ { "objectId": "<longGUID>", "gitObjectType": "blob", "commitId": "<longGUID>", "path": "/data/test.json", "url": "https://dev.azure.com/myOrg/longGUID/_apis/git/repositories/myRepoID/items?path=%2Fdata%2Ftest.json&versionType=Branch&versionOptions=None" } ] }Use the
objectIdin the response to issue a POST HTTP request to thePushesendpoint- Body:
{
"refUpdates": [
{
"name": "refs/heads/main",
"oldObjectId": "<longGuid from previous response>"
}
],
"commits": [
{
"changes": [
{
"changeType": "edit",
"item": {
"path": "/data/test.json"
},
"newContent": {
"content": "CHECK CHECK!",
"contentType": "rawtext"
}
}
],
"comment": "My commit message"
}
]
}
Error:
- Status 409 Conflict
{
"$id": "1",
"innerException": null,
"message": "TF401028: The reference 'refs/heads/main' has already been updated by another client, so you cannot update it. Please try again.",
"typeName": "Microsoft.TeamFoundation.Git.Server.GitReferenceStaleException, Microsoft.TeamFoundation.Git.Server",
"typeKey": "GitReferenceStaleException",
"errorCode": 0,
"eventId": 3000
}
Questions:
- Am I correct on the order of operations?
- How do I overcome this issue?
FIX: (Thank you @Leo_Liu-MSFT)
GET request to
https://dev.azure.com/myOrg/myProject/_apis/git/repositories/repoID/commits?searchCriteria.$top=1&searchCriteria.itemVersion.version=main&api-version=6.0POST request to
https://dev.azure.com/myOrg/myProject/_apis/git/repositories/repoID/pushes
- Body:
{
"commits": [
{
"changes": [
{
"changeType": "edit",
"item": {
"path": "<Your File To Update>"
},
"newContent": {
"content": "CHECK CHECK!",
"contentType": "rawtext"
}
}
],
"comment": "<YOUR COMMIT MSG>"
}
],
"refUpdates": [
{
"name": "refs/heads/main",
"oldObjectId": "<commitId from previous response>"
}
]
}
