TeamCity 2021.1 Help

Curl Examples

This article contains REST API examples for curl.

You can use the curl command-line tool to interact with the TeamCity REST API.

Example command:

curl -v --basic --user USERNAME:PASSWORD --request POST "http://<TeamCity Server host>:<port>/app/rest/users/" --data @data.xml --header "Content-Type: application/xml"

where USERNAME, PASSWORD, <TeamCity Server host>:<port> are to be substituted with real values, and data.xml file contains the data to send to the server.

Creating a new project

Using curl tool:

curl -v -u USER:PASSWORD http://<TeamCity Server host>:<port>/app/rest/projects --header "Content-Type: application/xml" --data-binary "<newProjectDescription name='New Project Name' id='newProjectId'><parentProject locator='id:project1'/></newProjectDescription>"

Making user a system administrator

  1. Get super user token.

  2. Issue the request.

  3. Get curl command line tool and use a command line:

curl -v -u :SUPERUSER_TOKEN --request PUT http://<TeamCity Server host>:<port>/app/rest/users/username:USERNAME/roles/SYSTEM_ADMIN/g/

where SUPERUSER_TOKEN is the super user token unique for each server start; <TeamCity Server host>:<port> — the TeamCity server URL; USERNAME — the username of the user to be made the system administrator.

Adding a parameter with the password type

This is how you can add a build parameter with the "Password" type:

curl -v -u ${USERNAME}:${PASSWORD} "${SERVER_URL}/app/rest/buildTypes/id:${BUILD_CONF_ID}/parameters/${PARAM_NAME}" --request PUT --header 'Content-Type: application/xml' --data "<property name=\"${PARAM_NAME}\" value=\"${PARAM_VALUE}\"><type rawValue=\"password display='normal'\"/></property>"

Note the \ in the --data argument allows escaping special characters. The escape character depends on the used command-line shell.

See also how to manage typed parameters.

Last modified: 05 July 2021