Patrick Steffensen
Patrick Steffensen

Reputation: 29

How to Move/Rename a file in TFS Source Control 2015, using the REST API?

I am trying to move files on our internal TFS using Python and the TFS REST API; the server appears to only support the API up-to version 2, but on MSDN I cannot find any docs for versions below v4.1.

The URL I'm posting to is https://<server>/tfs/<Collection>/<Project>/_apis/tfvc/changesets

Currently my best guess at the correct JSON body for the post request looks like this:

{
    "comment": "moved file",
    "changes": [{
        "changeType": "rename",
        "item": {
            "path": "<filepath>",
            "version": 468,
                    "sourceServerItem": "<filepath>"
        }

    }]
}

But i cannot get further than an HTTp error 400 bad request with the following message

{
  "$id": "1",
  "innerException": null,
  "message": "Exactly one value for PathActions is required.\r\nParameter name: change.SourceServerItem",
  "typeName": "System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
  "typeKey": "ArgumentException",
  "errorCode": 0,
  "eventId": 0
}

And for the life of me i cannot find any reference to PathActions on google, that is not for git instead of tfvc, or a correct way of providing a value for this item.

Does anybody have a way of renaming/moving files on a TFVC via a HTTP request?

Upvotes: 1

Views: 400

Answers (1)

Patrick Steffensen
Patrick Steffensen

Reputation: 29

It just occurred to me to do a rename using the TFS web interface and peek at the request sent by the browser.

Turns out this is the correct format:

{
  "comment": "Moved File",
  "changes": [
    {
      "changeType": 8,
      "sourceServerItem": "<old path>",
      "item": {
        "path": "<new path>",
        "version": 470
      }
    }
  ]
}

Upvotes: 1

Related Questions