Service Status Query

Function

This API is used to query the service enabling status.

Prerequisites:

URI

GET /v1/{project_id}/subscribe

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the ID, see Obtaining the Project ID, Account Name, and AK/SK.

Request Message

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

During API authentication using a token, the token is added to requests to obtain permissions for calling the API. The value of X-Subject-Token in the response header is the obtained token.

Response Message

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

max_face_set_number

Integer

Maximum number of facial image libraries.

This parameter is not included when the API fails to be called.

detect_service

Object

Sub-service information. For details about the ServiceInfo structure, see ServiceInfo.

This parameter is not included when the API fails to be called.

compare_service

Object

Sub-service information. For details about the ServiceInfo structure, see Table 4.

This parameter is not included when the API fails to be called.

live_detect_service

Object

Sub-service information. For details about the ServiceInfo structure, see Table 4.

This parameter is not included when the API fails to be called.

search_service

Object

Sub-service information. For details about the ServiceInfo structure, see Table 4.

This parameter is not included when the API fails to be called.

error_code

String

Error code returned after the API fails to be called. For details, see Error Codes.

This parameter is not included when the API is successfully called.

error_msg

String

Error message returned after the API fails to be called.

This parameter is not included when the API is successfully called.

Table 4 ServiceInfo

Parameter

Type

Description

subscribe_status

Boolean

Whether a sub-service is enabled

create_time

String

Time when a sub-service is enabled

Example Requests

For details about how to obtain the value of X-Auth-Token, see Authentication.

  • Sample code
    GET https://{endpoint}/v1/{project_id}/subscribe
    Request Header:
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDT...
  • Sample code for a Python 3 request (For codes in other languages, refer to the following sample or use the FRS SDK.)
    # -*- coding:utf-8 -*-
    import requests
    
    endpoint = 'Endpoint of the region where the service is enabled'
    project_id = 'Project ID of the region where the service is enabled'
    token = 'Actual token value obtained by the user'
    
    url = "https://{endpoint}/v1/{project_id}/subscribe".format(endpoint=endpoint, project_id=project_id)
    token = "Actual token value obtained by the user"
    headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}
    
    response = requests.get(url, headers=headers, verify=False)
    print(response.text)
  • Sample code for a Java request (For codes in other languages, refer to the following sample or use the FRS SDK.)
    import com.huawei.trace.http.apache.httpclient.TraceApacheHttpClientBuilder;
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpHeaders;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.config.RequestConfig;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.config.Registry;
    import org.apache.http.config.RegistryBuilder;
    import org.apache.http.conn.socket.ConnectionSocketFactory;
    import org.apache.http.conn.socket.PlainConnectionSocketFactory;
    import org.apache.http.conn.ssl.NoopHostnameVerifier;
    import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClientBuilder;
    import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
    import org.apache.http.ssl.SSLContextBuilder;
    import org.apache.http.ssl.TrustStrategy;
    import org.apache.http.util.EntityUtils;
    import java.io.IOException;
    import java.nio.charset.StandardCharsets;
    import java.security.KeyManagementException;
    import java.security.KeyStoreException;
    import java.security.NoSuchAlgorithmException;
    import java.security.cert.CertificateException;
    import java.security.cert.X509Certificate;
    import java.util.concurrent.TimeUnit;
    import javax.net.ssl.HostnameVerifier;
    import javax.net.ssl.SSLContext;
    
    /**
     * This demo is used only for tests. You are advised to use the SDK.
     * Before using this demo, configure the HttpClient JAR package. Obtain this package by downloading the SDK.
     */
    
    public class GetSubscribe {
        protected static HttpClientBuilder buildClient(HttpClientBuilder httpClientBuilder) {
            SSLContext sslContext = null;
            try {
                sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
                    public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                        return true;
                    }
                }).build();
            } catch (NoSuchAlgorithmException e) {
                throw new RuntimeException(e.getMessage());
            } catch (KeyManagementException e) {
                throw new RuntimeException(e.getMessage());
            } catch (KeyStoreException e) {
                throw new RuntimeException(e.getMessage());
            }
            httpClientBuilder.setSSLContext(sslContext);
            httpClientBuilder.setConnectionTimeToLive(30, TimeUnit.SECONDS);
            HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
            SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
            Registry<ConnectionSocketFactory> socketFactoryRegistry
                = RegistryBuilder.<ConnectionSocketFactory>create().register("http",
                PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
            PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
            connMgr.setMaxTotal(200);
            connMgr.setDefaultMaxPerRoute(100);
            httpClientBuilder.setConnectionManager(connMgr);
            return httpClientBuilder;
        }
    
        public static String doGet(String url, String token, CloseableHttpClient client) {
            HttpGet get = new HttpGet(url);
            get.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
            //time unit is milliseconds
            RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(3000).setSocketTimeout(3000).build();
            get.setConfig(requestConfig);
            get.setHeader("X-Auth-Token", token);
            HttpResponse response = null;
            String result = "";
            try {
                response = client.execute(get);
                HttpEntity responseBody = response.getEntity();
                if (responseBody == null) {
                    System.out.println("the response body is null.");
                    return result;
                } else {
                    byte[] byteStream = EntityUtils.toByteArray(responseBody);
                    System.arraycopy(byteStream, 0, new byte[byteStream.length], 0, byteStream.length);
                    result = new String(byteStream, StandardCharsets.UTF_8);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return result;
        }
    
        public static void main(String[] args) {
            CloseableHttpClient client = buildClient(TraceApacheHttpClientBuilder.create()).build();
            // Replace endpoint and project_id with the actual ones.
            String url = "https://{{endpoint}}/v1/{{project_id}}/subscribe";
            String token = "Token of the corresponding region";
            String result = doGet(url, token, client);
            System.out.println(result);
        }
    }

Example Responses

Status code: 200

Example response (successful request)
{
  "max_face_set_number": 10,
   "detect_service": {
        "subscribe_status": true,
        "create_time": "2018-09-03 08:16:48"
   },
   "compare_service": {
        "subscribe_status": true,
        "create_time": "2018-09-03 08:16:48"
   },
   "search_service": {
        "subscribe_status": true,
        "create_time": "2018-09-03 08:16:48"
   },
   "live_detect_service": {
        "subscribe_status": true,
        "create_time": "2018-09-03 08:16:48"
   }
}

Status code: 400

Example response (failed request)
{
  "error_code": "FRS.0019",
  "error_msg": "The service has not been subscribed."
}

Status Code

For details about the status code, see Status Codes.

Error Code

For details about the error code, see Error Codes.