기술 자료

Unity Services Web APIs

Open Unity Dashboard

Unity Services Web APIs

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분최근 업데이트: 24일 전

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
    7178
    for unencrypted local access and
    7179
    for external HTTPS access.
경고
On an on-premises server, the REST API supports only user and password authentication and LDAP. To check the authentication mode of your server, open the WebAdmin and go to Configuration > Authentication.

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:
  1. Send a
    POST
    request to
    /api/v1/organizations/{orgName}/login
    with your user name and password in the request body:
    curl --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"}'
  2. Read
    accessToken
    and
    refreshToken
    from the response:
    { "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}
If the credentials are invalid, the server responds with a
401
status code.
When the access token expires, send the refresh token to
/api/v1/organizations/{orgName}/login/refresh
to get a new pair instead of sending your credentials again.

Call an endpoint

To call an endpoint with your access token:
  1. Set the
    Authorization
    header to
    Bearer
    followed by the access token.
  2. 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
401
status code, the access token is missing, invalid, or expired. Get a new token and send the request again.

Additional resources