REST API: How to find which VCS root a change is mapped to

Hello,

I'm using the getChange method by using a build id and build number in the build locator of the request like so:

/app/rest/changes?locator=build:(id:my_build,number:1)

The request returns a list of changes like so:

{
'count': 70,
'change': [
{
'id': 291856,
'version': '46704',
'username': 'jny',
'date': '20230109T064010+0000',
'href': '/app/rest/changes/id:291856',
'webUrl': 'https://teamcity.project.zone/viewModification.html?modId=291856&personal=false'
},
{
'id': 291854,
'version': '46702',
'username': 'avilrz',
'date': '20230109T062552+0000',
'href': '/app/rest/changes/id:291854',
'webUrl': 'https://teamcity.project.zone/viewModification.html?modId=291854&personal=false'
},
# ... etc.
]
}

The problem I have here is that the change entities do not have a vcsRootInstance attribute. How can I determine which VCS these changes are associated with?

0
2 comments

Hello Sean!

When TeamCity returns multiple entities, it tends to reduce the number of fields returned for each entity to minimum, as to ensure the response is lightweight. You may specify the fields you need the API to return, though. The Change entity (link to autodoc) has a vcsRootInstance field listed, so you may do the following request:

```
/app/rest/changes?locator=<locator>&fields=change(id,version,vcsRootInstance(id,vcs-root-id))
```

This will, for each listed change, yield its vcsRootInstance along with id and vcs-root-id fields. 

While developing a request, it is often convenient to request all available fields for the entity:

```
/app/rest/changes?locator=<locator>&fields=change(id,version,vcsRootInstance(*))
```

The wildcard will request all available fields for vcsRootInstance, so you may review the data and narrow the request. I strongly recommend not to use wildcards in production requests, though - some of the fields may be more pricey to calculate than others, and for the requests that return a lot of entities (say, you request several hundred pages of builds) this can make a difference in the performance. 

I hope this helps.

0

Thank you, Fedor. This does help.

0

Please sign in to leave a comment.