forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Lai, Weijian <laiweijian4@huawei.com> Co-committed-by: Lai, Weijian <laiweijian4@huawei.com>
217 lines
26 KiB
HTML
217 lines
26 KiB
HTML
<a name="EN-US_TOPIC_0000001910008156"></a><a name="EN-US_TOPIC_0000001910008156"></a>
|
|
|
|
<h1 class="topictitle1">Making an API Request</h1>
|
|
<div id="body1536114969128"><p id="EN-US_TOPIC_0000001910008156__p122532201579">This section describes the structure of a REST API request, and uses the IAM API for obtaining a user token as an example to demonstrate how to call an API. The obtained token can then be used to authenticate the calling of other APIs.</p>
|
|
<div class="section" id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_section1849899574"><a name="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_section1849899574"></a><a name="en-us_topic_0170917207_en-us_topic_0168405763_section1849899574"></a><h4 class="sectiontitle">Request URI</h4><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p729531715312">The format of a request URI is as follows:</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p11610193811547"><strong id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_b3129104565416">{URI-scheme} :// {<strong id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_b10231116812">Endpoint</strong>} / {resource-path} ? {query-string}</strong></p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_table442645372610" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Request URI</caption><thead align="left"><tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_row15427253182617"><th align="left" class="cellrowborder" valign="top" width="16.37%" id="mcps1.3.2.4.2.3.1.1"><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p24271253182614">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="83.63000000000001%" id="mcps1.3.2.4.2.3.1.2"><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p19427155318264">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_row104278530268"><td class="cellrowborder" valign="top" width="16.37%" headers="mcps1.3.2.4.2.3.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p44271053122619">URI-scheme</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="83.63000000000001%" headers="mcps1.3.2.4.2.3.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p11427453192617">Protocol used to transmit requests. All APIs use HTTPS.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_row1142745318267"><td class="cellrowborder" valign="top" width="16.37%" headers="mcps1.3.2.4.2.3.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p1342765311266">Endpoint</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="83.63000000000001%" headers="mcps1.3.2.4.2.3.1.2 "><p id="EN-US_TOPIC_0000001910008156__p992044614557">Domain name or IP address of the server for the REST service endpoint. The endpoint varies depending on services in different regions. It can be obtained in <a href="modelarts_03_0141.html">Endpoint</a>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_row94271453112615"><td class="cellrowborder" valign="top" width="16.37%" headers="mcps1.3.2.4.2.3.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p144271753182618">resource-path</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="83.63000000000001%" headers="mcps1.3.2.4.2.3.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p4427953122617">Access path of an API for performing a specified operation. Obtain the path from the URI of an API. For example, the <strong id="EN-US_TOPIC_0000001910008156__b104632038479">resource-path</strong> of the API used to obtain a user token is <span class="parmvalue" id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_parmvalue176306433280"><b>/v3/auth/tokens</b></span>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_row1991179192817"><td class="cellrowborder" valign="top" width="16.37%" headers="mcps1.3.2.4.2.3.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p1091217918289">query-string</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="83.63000000000001%" headers="mcps1.3.2.4.2.3.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p79121799283">Query parameter, which is optional. Ensure that a question mark (?) is included before each query parameter that is in the format of "<em id="EN-US_TOPIC_0000001910008156__i623715510455">Parameter name=Parameter value</em>". For example, <strong id="EN-US_TOPIC_0000001910008156__b69817954515">? limit=10</strong> indicates that a maximum of 10 data records will be displayed.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001910008156__p1512913502578">For example, to obtain an IAM token in a region, obtain the endpoint of IAM for this region and the <strong id="EN-US_TOPIC_0000001910008156__b135501211753">resource-path</strong> (<strong id="EN-US_TOPIC_0000001910008156__b1955518115512">/v3/auth/tokens</strong>) in the URI of the API used to obtain a user token. Then, construct the URI as follows:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_screen1553450193818">https://<em id="EN-US_TOPIC_0000001910008156__i19573103114352">{iam-endpoint}</em>/v3/auth/tokens</pre>
|
|
<div class="note" id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_note16311253154112"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p163316534416">To simplify the URI display in this document, each API is provided only with a <strong id="EN-US_TOPIC_0000001910008156__b53571353114718">resource-path</strong> and a request method. The <strong id="EN-US_TOPIC_0000001910008156__b1665051074813">URI-scheme</strong> of all APIs is <strong id="EN-US_TOPIC_0000001910008156__b12318131618481">HTTPS</strong>, and the endpoints of all APIs in the same region are identical.</p>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_section580035055419"><h4 class="sectiontitle">Request Methods</h4><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p65661618145510">The HTTP protocol defines the following request methods that can be used to send a request to the server:</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_table1961229113819" frame="border" border="1" rules="all"><caption><b>Table 2 </b>HTTP methods</caption><thead align="left"><tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_row86141913816"><th align="left" class="cellrowborder" valign="top" width="20.810000000000002%" id="mcps1.3.3.3.2.3.1.1"><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p186147910387"><strong id="EN-US_TOPIC_0000001910008156__b14244113244714">Method</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="79.19%" id="mcps1.3.3.3.2.3.1.2"><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p166141293387"><strong id="EN-US_TOPIC_0000001910008156__b119892335479">Description</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_row146141194381"><td class="cellrowborder" valign="top" width="20.810000000000002%" headers="mcps1.3.3.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p12831539123914">GET</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.19%" headers="mcps1.3.3.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p2831123916397">Requests the server to return specified resources.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_row161429103817"><td class="cellrowborder" valign="top" width="20.810000000000002%" headers="mcps1.3.3.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p3831239183912">PUT</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.19%" headers="mcps1.3.3.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p178311939193911">Requests the server to update specified resources.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_row56141190384"><td class="cellrowborder" valign="top" width="20.810000000000002%" headers="mcps1.3.3.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p68311239113912">POST</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.19%" headers="mcps1.3.3.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p1583133918391">Requests the server to add resources or perform special operations.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_row861411903812"><td class="cellrowborder" valign="top" width="20.810000000000002%" headers="mcps1.3.3.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p1183153943916">DELETE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.19%" headers="mcps1.3.3.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p6831163914392">Requests the server to delete specified resources, for example, an object.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_row5614119183810"><td class="cellrowborder" valign="top" width="20.810000000000002%" headers="mcps1.3.3.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p78314395393">HEAD</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.19%" headers="mcps1.3.3.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p38311239153920">Same as GET except that the server must return only the response header.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_row2614199163812"><td class="cellrowborder" valign="top" width="20.810000000000002%" headers="mcps1.3.3.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p1483143915390">PATCH</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.19%" headers="mcps1.3.3.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p17831173918394">Requests the server to update partial content of a specified resource.</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0113746487_p9831123911390">If the resource does not exist, a new resource will be created.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="p" id="EN-US_TOPIC_0000001910008156__p16980161354713">For example, in the case of the API used to obtain a user token, the request method is POST. The request is as follows:<pre class="screen" id="EN-US_TOPIC_0000001910008156__screen7888377244">POST https://<em id="EN-US_TOPIC_0000001910008156__i9425206203714">{iam-endpoint}</em>/v3/auth/tokens</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_section1454211155819"><h4 class="sectiontitle">Request Header</h4><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p11811752397">You can also add additional header fields to a request, such as the fields required by a specified URI or HTTP method. For example, to request for the authentication information, add <span class="parmname" id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_parmname28091429124915"><b>Content-Type</b></span>, which specifies the request body type.</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p1467193205816"><a href="#EN-US_TOPIC_0000001910008156__table139019272562">Table 3</a> describes the common request header fields to be added to the request.</p>
|
|
|
|
<div class="tablenoborder"><a name="EN-US_TOPIC_0000001910008156__table139019272562"></a><a name="table139019272562"></a><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001910008156__table139019272562" frame="border" border="1" rules="all"><caption><b>Table 3 </b>Common request header fields</caption><thead align="left"><tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_row46150831"><th align="left" class="cellrowborder" valign="top" width="16.88%" id="mcps1.3.4.4.2.5.1.1"><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p47229853">Header</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="33.12%" id="mcps1.3.4.4.2.5.1.2"><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p412859">Description</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="20%" id="mcps1.3.4.4.2.5.1.3"><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p33441585">Mandatory</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="30%" id="mcps1.3.4.4.2.5.1.4"><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p24413864">Example</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_row31365959"><td class="cellrowborder" valign="top" width="16.88%" headers="mcps1.3.4.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p57614775">Content-type</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.12%" headers="mcps1.3.4.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p36285216">Request body type or format. The default value is <span class="parmvalue" id="EN-US_TOPIC_0000001910008156__parmvalue58263396120"><b>application/json</b></span>.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.4.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p53421353">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p32162298">application/json</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_row21025229"><td class="cellrowborder" valign="top" width="16.88%" headers="mcps1.3.4.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p25322014">Content-Length</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.12%" headers="mcps1.3.4.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p37817292">Length of the request body. The unit is byte.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.4.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p43301822">Mandatory for POST and PUT requests but must be left blank for GET requests</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p17786717">3495</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_row25862728"><td class="cellrowborder" valign="top" width="16.88%" headers="mcps1.3.4.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p14506261">X-Project-Id</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.12%" headers="mcps1.3.4.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p34156482">Project ID. This parameter is used to obtain the token for each project.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.4.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p15211639">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p24183261">e9993fc787d94b6c886cbaa340f9c0f4</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_row16322762"><td class="cellrowborder" valign="top" width="16.88%" headers="mcps1.3.4.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p47075323">X-Auth-Token</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.12%" headers="mcps1.3.4.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001910008156__p187944531484">User token. It is a response to the API used to obtain a user token. This API is the only one that does not require authentication.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.4.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p26207828">Mandatory for token-based authentication</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p46589738">None</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_row16654463"><td class="cellrowborder" valign="top" width="16.88%" headers="mcps1.3.4.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p6834263">X-Sdk-Date</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.12%" headers="mcps1.3.4.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p16704444">Time when the request is sent. The time is in <em id="EN-US_TOPIC_0000001910008156__i8423526978249">YYYYMMDD</em><strong id="EN-US_TOPIC_0000001910008156__b84235270682418">'T'</strong><em id="EN-US_TOPIC_0000001910008156__i84235269782424">HHMMSS</em><strong id="EN-US_TOPIC_0000001910008156__b84235270682428">'Z'</strong> format.</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p16122270">The value is the current Greenwich Mean Time (GMT) time of the system.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.4.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p30835521">Mandatory for AK/SK-based authentication, optional for PKI token-based authentication</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p64734405">20190307T101459Z</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_row45738735"><td class="cellrowborder" valign="top" width="16.88%" headers="mcps1.3.4.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p13850059">Authorization</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.12%" headers="mcps1.3.4.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p48112991">Authentication information.</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p30363742">The value is obtained from the request signature result and is required when the AK/SK are used to encrypt the signature.</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p4838228">Type: string</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p43544058">Default value: none</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.4.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p10136448">Mandatory for AK/SK-based authentication</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p7496077">SDK-HMAC-SHA256 Credential=ZIRRKMTWPTQFQI1WKNKB/20150907//ec2/sdk_request, SignedHeaders=content-type;host;x-sdk-date, Signature=55741b610f3c9fa3ae40b5a8021ebf7ebc2a28a603fc62d25cb3bfe6608e1994</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_row355832"><td class="cellrowborder" valign="top" width="16.88%" headers="mcps1.3.4.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p28822435">Host</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.12%" headers="mcps1.3.4.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p81053717359">Information about the requested server. The value can be obtained from the URL of the service API.</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p140124114357">This value is <em id="EN-US_TOPIC_0000001910008156__i17408173354">host name</em>[:<em id="EN-US_TOPIC_0000001910008156__i7409031653">port number</em>].</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p52915874">If the port number is not specified, the default port is used. The default port number for <strong id="EN-US_TOPIC_0000001910008156__b1277082818619">https</strong> is <strong id="EN-US_TOPIC_0000001910008156__b1761714161260">443</strong>.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.4.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p58327390">Mandatory for AK/SK-based authentication</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p40756399">code.test.com</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p31263274">or</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0106912064_p12934017">code.test.com:443</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="note" id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_note13771123325011"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p1513412221808">In addition to supporting authentication using tokens, APIs support authentication using AK/SK, which uses SDK to sign a request. During the signature, the <strong id="EN-US_TOPIC_0000001910008156__b469313518611">Authorization</strong> (signature authentication) and <strong id="EN-US_TOPIC_0000001910008156__b469413358611">X-Sdk-Date</strong> (time when a request is sent) headers are automatically added to the request. </p>
|
|
</div></div>
|
|
<div class="p" id="EN-US_TOPIC_0000001910008156__p766741220577">The API for obtaining a user token does not require authentication. Therefore, this API only requires adding the <span class="parmname" id="EN-US_TOPIC_0000001910008156__parmname185084109117"><b>Content-Type</b></span> field. The request with the added <span class="parmname" id="EN-US_TOPIC_0000001910008156__parmname10508110161119"><b>Content-Type</b></span> header is as follows:<pre class="screen" id="EN-US_TOPIC_0000001910008156__screen186678128579">POST https://<em id="EN-US_TOPIC_0000001910008156__i214313484399">{iam-endpoint}</em>/v3/auth/tokens
|
|
Content-Type: application/json</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_section14612192315587"><h4 class="sectiontitle">Request Body</h4><p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p23132011213">The body of a request is often sent in a structured format as specified in the Content-Type header field. The request body transfers content except the request header. </p>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p1847214711331">The request body varies between APIs. Some APIs do not require the request body, such as the APIs requested using the GET and DELETE methods.</p>
|
|
<p id="EN-US_TOPIC_0000001910008156__p959661302018">If an API is used to obtain a user token, the request parameters and parameter description can be obtained from the API request. The following provides an example request with a body included. Replace <em id="EN-US_TOPIC_0000001910008156__i6596113112011">user_name</em>, <em id="EN-US_TOPIC_0000001910008156__i1597171319201">domain_name</em>, and <em id="EN-US_TOPIC_0000001910008156__i794603122614">user_password</em> with the actual username, tenant name, and login password, respectively. <strong id="EN-US_TOPIC_0000001910008156__b18458958132612"><em id="EN-US_TOPIC_0000001910008156__i2061215426411">project_name</em></strong> is the project name. For details, see <a href="modelarts_03_0006.html">Obtaining a Username</a>, <a href="modelarts_03_0148.html">Obtaining a Tenant Name and ID</a>, and <a href="modelarts_03_0147.html">Obtaining a Project Name</a>.</p>
|
|
<div class="note" id="EN-US_TOPIC_0000001910008156__note1350402418201"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001910008156__p77561625162017">The <strong id="EN-US_TOPIC_0000001910008156__b574016447218">scope</strong> parameter specifies where a token takes effect. In the example, the token takes effect only for the resources in a specified project. ModelArts uses a region-specific endpoint to call this API. Set <strong id="EN-US_TOPIC_0000001910008156__b778018496420">scope</strong> to <strong id="EN-US_TOPIC_0000001910008156__b66121354134216">project</strong>. You can set <strong id="EN-US_TOPIC_0000001910008156__b18747185911421">scope</strong> to an account or a project under an account. </p>
|
|
</div></div>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001910008156__screen1930315611554">POST https://<em id="EN-US_TOPIC_0000001910008156__i17401010472">{iam-endpoint}</em>/v3/auth/tokens
|
|
Content-Type:application/json
|
|
{
|
|
"auth": {
|
|
"identity": {
|
|
"methods": ["password"],
|
|
"password": {
|
|
"user": {
|
|
"name": "<em id="EN-US_TOPIC_0000001910008156__i27857330174">Username</em>",
|
|
"password": "<em id="EN-US_TOPIC_0000001910008156__i75722134715">User password</em>",
|
|
"domain": {
|
|
"name": "<em id="EN-US_TOPIC_0000001910008156__i923745721719">Domain name</em>"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"scope": {
|
|
"project": {
|
|
"name": "<em id="EN-US_TOPIC_0000001910008156__i1900326111512">project_name</em>"
|
|
}
|
|
}
|
|
}
|
|
}</pre>
|
|
<p id="EN-US_TOPIC_0000001910008156__en-us_topic_0170917207_en-us_topic_0168405763_p1859663401915">If all data required for the API request is available, you can send the request to call the API through <a href="https://curl.haxx.se/" target="_blank" rel="noopener noreferrer">curl</a>, <a href="https://www.getpostman.com/" target="_blank" rel="noopener noreferrer">Postman</a>, or coding. In the response to the API used to obtain a user token, <span class="parmname" id="EN-US_TOPIC_0000001910008156__parmname12918141645414"><b>x-subject-token</b></span> is the desired user token. This token can then be used to authenticate the calling of other APIs.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="modelarts_03_0144.html">Calling APIs</a></div>
|
|
</div>
|
|
</div>
|
|
|