# 获取方案信息 - SearchTemplateById
#### 功能介绍
该接口可根据执行方案id查询执行方案详情。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-aom/aom_04_0057.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-aom/aom_04_0031.html)。
- 如果使用身份策略授权，当前API调用无需身份策略权限。
#### URI
GET /v1/{project_id}/cms/template/{template_id}
表1路径参数 
| 参数          | 是否必选 | 参数类型   | 描述                                                     |
|:---|:---|:---|:---|
| project_id  | 是    | String | 租户从IAM申请到的projectid，一般为32位字符串。 最小长度：**32** 最大长度：**32** |
| template_id | 是    | String | 方案id。 最小长度：**1** 最大长度：**64**                           |
表2Query参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                        |
|:---|:---|:---|:---|
| share_type | 是    | String | 模板共享类型，默认为private。可选public private 最小长度：**1** 最大长度：**10** |
#### 请求参数
表3请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                            |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | 从IAM服务获取的用户Token。 最小长度：**1** 最大长度：**40960**   |
| Content-Type | 是    | String | 指定类型为application/json。 最小长度：**1** 最大长度：**32** |
   
#### 响应参数
**状态码：200**
表4响应Body参数 
| 参数                    | 参数类型                                                                                               | 描述                                                             |
|:---|:---|:---|
| approve_info          | [ApproveInfo] object       | 审批信息                                                           |
| create_by             | String                                                                                             | 模板创建人，从接口调用传入的token中获取。 最小长度：**1** 最大长度：**64**                 |
| create_time           | Long                                                                                               | 模板创建时间，为utc时间毫秒数。 最小值：**0** 最大值：**9999999999999**              |
| enterprise_project_id | String                                                                                             | 企业项目id 最小长度：**1** 最大长度：**64**                                  |
| id                    | String                                                                                             | 模板id，唯一标识，根据project_id和template_name生成。 最小长度：**1** 最大长度：**64** |
| is_collect            | Boolean                                                                                            | 模板是否收藏，不允许更新模板时修改，更改收藏状态调用单独的更新模板收藏状态接口                        |
| is_publish            | Boolean                                                                                            | 是否发布成服务                                                        |
| job_id                | String                                                                                             | 作业id 最小长度：**1** 最大长度：**64**                                    |
| job_version           | Integer                                                                                            | 作业版本 最小值：**1** 最大值：**999**                                     |
| name                  | String                                                                                             | 模板名称 最小长度：**1** 最大长度：**64**                                    |
| need_synchronize      | Boolean                                                                                            | 是否需要同步                                                         |
| nodes                 | Array of [Node] objects           | 任务执行时需要的参数列表。 数组长度：**1 - 20**                                  |
| parameters            | Array of [Parameter] objects | 任务执行时需要的参数列表。 数组长度：**0 - 20**                                  |
| project_id            | String                                                                                             | 项目id 最小长度：**32** 最大长度：**32**                                   |
| quote                 | Array of strings                                                                                   | 引用参数 最小长度：**1** 最大长度：**256** 数组长度：**0 - 999**                  |
| rate_control          | [RateControl] object       | 执行策略                                                           |
| share_type            | String                                                                                             | 默认模板为public，自定义模板为private 最小长度：**1** 最大长度：**16**               |
| steps                 | Array of [Step] objects           | 作业步骤 数组长度：**1 - 20**                                           |
| update_by             | String                                                                                             | 模板更新人，从接口调用传入的token中获取。 最小长度：**1** 最大长度：**64**                 |
| update_time           | Long                                                                                               | 模板更新时间，为utc时间毫秒数。 最小值：**0** 最大值：**9999999999999**              |
| version               | String                                                                                             | 模板版本 最小长度：**1** 最大长度：**32**                                    |
   
 表5ApproveInfo 
| 参数             | 参数类型    | 描述                                  |
|:---|:---|:---|
| topic_selected | String  | 审批人主题选择。 最小长度：**1** 最大长度：**2048**   |
| need_approve   | Boolean | 是否审核,默认是不审核，true，false。             |
| smn_urn_list   | String  | 审批主题urn集合。 最小长度：**1** 最大长度：**2048** |
   
 表6Node 
| 参数           | 参数类型                                                                                   | 描述                                    |
|:---|:---|:---|
| parent_node  | String                                                                                 | 父亲节点的名称。 最小长度：**1** 最大长度：**64**       |
| category     | String                                                                                 | 节点类型。 最小长度：**1** 最大长度：**32**          |
| description  | String                                                                                 | 节点描述。 最小长度：**1** 最大长度：**1024**        |
| id           | String                                                                                 | 节点id 最小长度：**1** 最大长度：**64**           |
| ignore_error | Boolean                                                                                | 是否忽略错误                                |
| metadata     | [Metadata] object | 元数据。                                  |
| name         | String                                                                                 | 节点名称,比如是Node。 最小长度：**1** 最大长度：**64**  |
| task_name    | String                                                                                 | 任务名称，节点上任务的名称。 最小长度：**1** 最大长度：**64** |
   
 表7Metadata 
| 参数            | 参数类型                 | 描述                           |
|:---|:---|:---|
| type          | String               | 节点类型。 最小长度：**1** 最大长度：**32** |
| configuration | Map\<String,Object\> | 配置信息。                        |
   
 表8Parameter 
| 参数            | 参数类型    | 描述                               |
|:---|:---|:---|
| param_name    | String  | 参数名称。                            |
| param_type    | String  | 参数类型。 最小长度：**1** 最大长度：**16**     |
| param_group   | String  | 参数分组。 最小长度：**1** 最大长度：**32**     |
| default_value | String  | 参数初始值。 最小长度：**1** 最大长度：**40960** |
| id            | String  | 参数id。 最小长度：**1** 最大长度：**64**     |
| encryption    | Boolean | 是否加密。                            |
| hint          | String  | 参数提示。 最小长度：**1** 最大长度：**1000**   |
| quote_param   | Boolean | 是否从参数库选择。                        |
| required      | Boolean | 是否为必填参数。                         |
| description   | String  | 参数描述。 最小长度：**1** 最大长度：**1000**   |
   
 表9RateControl 
| 参数                | 参数类型    | 描述                                |
|:---|:---|:---|
| have_rate_control | Boolean | 是否分批发布，默认值是false。                 |
| time_delay        | Integer | 每批间隔。 最小值：**1** 最大值：**60**        |
| max               | Integer | 每批支持的最大实例数。 最小值：**0** 最大值：**100** |
   
 表10Step 
| 参数           | 参数类型                 | 描述                             |
|:---|:---|:---|
| id           | String               | 步骤id。 最小长度：**1** 最大长度：**64**   |
| name         | String               | 步骤名称。 最小长度：**1** 最大长度：**32**   |
| type         | String               | 步骤类型。 最小长度：**1** 最大长度：**16**   |
| input        | Map\<String,String\> | 步骤参数。                          |
| ignore_error | Boolean              | 是否自动忽略错误。                      |
| description  | String               | 步骤说明。 最小长度：**1** 最大长度：**1000** |
   
**状态码：400**
表11响应Body参数 
| 参数         | 参数类型    | 描述                                   |
|:---|:---|:---|
| error_code | String  | 响应码。 最小长度：**1** 最大长度：**64**          |
| error_msg  | String  | 调用失败响应信息描述。 最小长度：**1** 最大长度：**1024** |
| http_code  | Integer | http返回码 最小值：**0** 最大值：**999**        |
   
**状态码：401**
表12响应Body参数 
| 参数         | 参数类型    | 描述                                   |
|:---|:---|:---|
| error_code | String  | 响应码。 最小长度：**1** 最大长度：**64**          |
| error_msg  | String  | 调用失败响应信息描述。 最小长度：**1** 最大长度：**1024** |
| http_code  | Integer | http返回码 最小值：**0** 最大值：**999**        |
   
#### 请求示例
用template_id和share_type查询执行方案。
share_type：默认为private。
```
https://{Endpoint}/v1/{project_id}/cms/template/{template_id}?share_type=private
```
#### 响应示例
**状态码：200**
请求响应成功，返回执行方案详情。
```
{
  "approve_info" : {
    "need_approve" : false
  },
  "create_by" : "xxxxxxxxx",
  "create_time" : 1600026634837,
  "enterprise_project_id" : "0",
  "id" : "xxxxxx",
  "is_collect" : false,
  "is_publish" : false,
  "job_id" : "xxxxxx",
  "job_version" : 1,
  "name" : "1",
  "need_synchronize" : false,
  "nodes" : [ {
    "category" : "pause",
    "description" : "xxxxxx",
    "id" : "xxxxxx",
    "ignore_error" : false,
    "metadata" : {
      "type" : "pause"
    },
    "name" : "xxx",
    "task_name" : "CMS::PAUSE"
  } ],
  "parameters" : [ {
    "default_value" : "",
    "description" : "",
    "encryption" : false,
    "hint" : "",
    "id" : "xxxxxx",
    "param_group" : "",
    "param_name" : "xxx",
    "param_type" : "STRING",
    "quote_param" : false,
    "required" : true
  }, {
    "default_value" : "",
    "description" : "xxxxxx",
    "encryption" : false,
    "hint" : "xxxxxxx",
    "id" : "xxxxxxx",
    "param_group" : "",
    "param_name" : "xxx",
    "param_type" : "STRING",
    "quote_param" : false,
    "required" : true
  } ],
  "project_id" : "xxxxxx",
  "quote" : [ ],
  "rate_control" : {
    "have_rate_control" : false,
    "max" : 0,
    "time_delay" : 0
  },
  "share_type" : "private",
  "steps" : [ {
    "description" : "xxxxxx",
    "id" : "xxxxxx",
    "ignore_error" : false,
    "input" : { },
    "name" : "xxx",
    "type" : "pause"
  } ],
  "update_by" : "xxx",
  "update_time" : 1600026634837,
  "version" : "v1"
}
```
**状态码：400**
BadRequest。非法请求。建议直接修改该请求，不要重试该请求。
```
{
  "error_code" : "AOM.31001202",
  "error_msg" : "Invalid plan parameter.",
  "http_code" : 400
}
```
**状态码：401**
Unauthorized。在客户端提供认证信息后，返回该状态码，表明服务端指出客户端所提供的认证信息不正确或非法。
```
{
  "error_code" : "AOM.31009002",
  "error_message" : "auth failed.",
  "http_code" : "401"
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  ```
  package com.huaweicloud.sdk.test;
  import com.huaweicloud.sdk.core.auth.ICredential;
  import com.huaweicloud.sdk.core.auth.BasicCredentials;
  import com.huaweicloud.sdk.core.exception.ConnectionException;
  import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
  import com.huaweicloud.sdk.core.exception.ServiceResponseException;
  import com.huaweicloud.sdk.aom.v1.region.AomRegion;
  import com.huaweicloud.sdk.aom.v1.*;
  import com.huaweicloud.sdk.aom.v1.model.*;
  public class SearchTemplateByIdSolution {
      public static void main(String[] args) {
          // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
          // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
          String ak = System.getenv("CLOUD_SDK_AK");
          String sk = System.getenv("CLOUD_SDK_SK");
          String projectId = "{project_id}";
          ICredential auth = new BasicCredentials()
                  .withProjectId(projectId)
                  .withAk(ak)
                  .withSk(sk);
          AomClient client = AomClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                  .build();
          SearchTemplateByIdRequest request = new SearchTemplateByIdRequest();
          request.withTemplateId("{template_id}");
          try {
              SearchTemplateByIdResponse response = client.searchTemplateById(request);
              System.out.println(response.toString());
          } catch (ConnectionException e) {
              e.printStackTrace();
          } catch (RequestTimeoutException e) {
              e.printStackTrace();
          } catch (ServiceResponseException e) {
              e.printStackTrace();
              System.out.println(e.getHttpStatusCode());
              System.out.println(e.getRequestId());
              System.out.println(e.getErrorCode());
              System.out.println(e.getErrorMsg());
          }
      }
  }
  ```
- [Python]
  ```
  # coding: utf-8
  import os
  from huaweicloudsdkcore.auth.credentials import BasicCredentials
  from huaweicloudsdkaom.v1.region.aom_region import AomRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkaom.v1 import *
  if __name__ == "__main__":
      # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
      # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
      ak = os.environ["CLOUD_SDK_AK"]
      sk = os.environ["CLOUD_SDK_SK"]
      projectId = "{project_id}"
      credentials = BasicCredentials(ak, sk, projectId)
      client = AomClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(AomRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = SearchTemplateByIdRequest()
          request.template_id = "{template_id}"
          response = client.search_template_by_id(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  ```
  package main
  import (
  "fmt"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
      aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
  )
  func main() {
      // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
      // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
      ak := os.Getenv("CLOUD_SDK_AK")
      sk := os.Getenv("CLOUD_SDK_SK")
      projectId := "{project_id}"
      auth := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          WithProjectId(projectId).
          Build()
      client := aom.NewAomClient(
          aom.AomClientBuilder().
              WithRegion(region.ValueOf("<YOUR REGION>")).
              WithCredential(auth).
              Build())
      request := &model.SearchTemplateByIdRequest{}
  request.TemplateId = "{template_id}"
  response, err := client.SearchTemplateById(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/AOM/sdk?api=SearchTemplateById)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                                                        |
|:---|:---|
| 200 | 请求响应成功，返回执行方案详情。                                          |
| 400 | BadRequest。非法请求。建议直接修改该请求，不要重试该请求。                        |
| 401 | Unauthorized。在客户端提供认证信息后，返回该状态码，表明服务端指出客户端所提供的认证信息不正确或非法。 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-aom/ErrorCode.html)。
