Authenticate and call the Unity Version Control server REST API
Get an access token and use it to call the Unity Version Control server REST API on Unity Version Control Cloud or on an on-premises server.
阅读时间2 分钟最后更新于 11 天前
Every Unity Version Control server REST API endpoint belongs to an organization, and every endpoint except the login endpoints requires a bearer token. Authenticate first, then send the access token that the server returns with each request that follows.
Use any programming language capable of making HTTP calls to interact with the API. Make sure you use the right HTTP method and include the request body that the endpoint expects.
Prerequisites
Before you start, find the base URI of the server that hosts your organization:
- On Unity Version Control Cloud, look up the region that hosts your organization in the server table of the API Reference.
- On an on-premises server, the API listens on the same port as the WebAdmin. By default, this is for unencrypted local access and
7178for external HTTPS access.7179
Get an access token
The login endpoint returns two JSON Web Tokens: an access token that authorizes your requests, and a refresh token that you exchange for a new pair when the access token expires.
To get an access token:
-
Send arequest to
POSTwith your user name and password in the request body:/api/v1/organizations/{orgName}/logincurl --request POST \ --url https://prd-azure-westeu-01-cloud.plasticscm.com:7178/api/v1/organizations/my-organization/login \ --header 'Content-Type: application/json' \ --data '{"user":"my-user@example.com","password":"MY_PASSWORD"}' -
Readand
accessTokenfrom the response:refreshToken{ "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}
If the credentials are invalid, the server responds with a status code.
401When the access token expires, send the refresh token to to get a new pair instead of sending your credentials again.
/api/v1/organizations/{orgName}/login/refreshCall an endpoint
To call an endpoint with your access token:
-
Set theheader to
Authorizationfollowed by the access token.Bearer -
Send the request to the endpoint you need. For example, to list the repositories in an organization:curl --request GET \ --url https://prd-azure-westeu-01-cloud.plasticscm.com:7178/api/v1/organizations/my-organization/repos \ --header "Authorization: Bearer ${ACCESS_TOKEN}"
The server returns the repositories that your user can access. If the server rejects the request with a status code, the access token is missing, invalid, or expired. Get a new token and send the request again.
401