APIU Guidelines 20240812 version

Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Chen, Junjie <chenjunjie@huawei.com>
Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
This commit is contained in:
Chen, Junjie 2024-08-13 10:31:24 +00:00 committed by zuul
parent 8feb9db543
commit 97b6825626
43 changed files with 952 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,92 @@
[
{
"desc":"API requests sent by third-party applications to public cloud services must be authenticated using signatures.This document describes the signature procedure, provides sa",
"product_code":"apiug",
"title":"Overview",
"uri":"apig-en-api-180328001.html",
"doc_type":"guidelines",
"p_code":"",
"code":"1"
},
{
"desc":"API Gateway provides RESTful APIs.REST provides APIs to create, query, update, delete, and access service resources.A REST API request/response pair is divided into the f",
"product_code":"apiug",
"title":"Overview of REST APIs",
"uri":"apig-en-api-180328002.html",
"doc_type":"guidelines",
"p_code":"",
"code":"2"
},
{
"desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.",
"product_code":"apiug",
"title":"Calling APIs",
"uri":"apig-en-api-180925010.html",
"doc_type":"guidelines",
"p_code":"",
"code":"3"
},
{
"desc":"Obtain the required information before calling APIs.A project ID needs to be specified in the URIs of some APIs. Therefore, you need to obtain the project ID before calli",
"product_code":"apiug",
"title":"Obtaining Required Information",
"uri":"apig-en-api-180328009.html",
"doc_type":"guidelines",
"p_code":"3",
"code":"4"
},
{
"desc":"If API requests are authenticated using tokens, the request header must contain X-Auth-Token (token information).This section describes how to call an API for token authe",
"product_code":"apiug",
"title":"Token Authentication",
"uri":"apig-en-api-180328003.html",
"doc_type":"guidelines",
"p_code":"3",
"code":"5"
},
{
"desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.",
"product_code":"apiug",
"title":"AK/SK Authentication",
"uri":"apig-en-api-180328004.html",
"doc_type":"guidelines",
"p_code":"3",
"code":"6"
},
{
"desc":"Log in to the management console.Click the username and choose My Credential from the drop-down list.Click Access Keys.Click Add Access Keys to switch to the Add Access K",
"product_code":"apiug",
"title":"Generating an AK and SK",
"uri":"apig-en-api-180328005.html",
"doc_type":"guidelines",
"p_code":"6",
"code":"7"
},
{
"desc":"Introduce the API Gateway signing SDK in the project.Download the API Gateway signing tool from the following link:https://apig-demo.obs.eu-de.otc.t-systems.com/java/java",
"product_code":"apiug",
"title":"Signing a Request",
"uri":"apig-en-api-180328006.html",
"doc_type":"guidelines",
"p_code":"6",
"code":"8"
},
{
"desc":"This section describes how to call the API of a public cloud service by using Eclipse.The following code shows how to sign a request and how to use an HTTP client to send",
"product_code":"apiug",
"title":"Sample Code",
"uri":"apig-en-api-180328008.html",
"doc_type":"guidelines",
"p_code":"6",
"code":"9"
},
{
"desc":"Table 1 describes common status codes.",
"product_code":"apiug",
"title":"HTTP Status Codes",
"uri":"apig-en-api-180328012.html",
"doc_type":"guidelines",
"p_code":"",
"code":"10"
}
]

View File

@ -0,0 +1,3 @@
version=""
language="en-us"
type=""

View File

@ -0,0 +1,7 @@
<a name="apig-en-api-180328001"></a><a name="apig-en-api-180328001"></a>
<h1 class="topictitle1">Overview</h1>
<div id="body1521449602954"><p id="apig-en-api-180328001__p7945016142655">API requests sent by third-party applications to public cloud services must be authenticated using signatures.</p>
<p id="apig-en-api-180328001__p36893300141518">This document describes the signature procedure, provides sample code to illustrate how to use the default signer to sign requests and how to use the HTTP client to send requests.</p>
</div>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,80 @@
<a name="apig-en-api-180328003"></a><a name="apig-en-api-180328003"></a>
<h1 class="topictitle1">Token Authentication</h1>
<div id="body1537441075328"><div class="section" id="apig-en-api-180328003__section5608799912249"><h4 class="sectiontitle">Application Scenarios</h4><p id="apig-en-api-180328003__p4683410312249">If API requests are authenticated using tokens, the request header must contain <strong id="apig-en-api-180328003__b842352706161232">X-Auth-Token</strong> (token information).</p>
<p id="apig-en-api-180328003__p1885374512249">This section describes how to call an API for token authentication.</p>
</div>
<div class="section" id="apig-en-api-180328003__section3546598312249"><h4 class="sectiontitle">Procedure</h4><ol id="apig-en-api-180328003__ol5417235112249"><li id="apig-en-api-180328003__li7201450105021">Send <strong id="apig-en-api-180328003__b034312224917">POST https://</strong><em id="apig-en-api-180328003__i20265928093">IAM endpoint</em><strong id="apig-en-api-180328003__b1356462520912">/v3/auth/tokens</strong> to obtain the IAM endpoint and the region name in the message body.<p id="apig-en-api-180328003__p29157503105024">See <a href="https://docs.otc.t-systems.com/regions-and-endpoints/index.html" target="_blank" rel="noopener noreferrer">Regions and Endpoints</a>.</p>
<p id="apig-en-api-180328003__p126473211266"></p>
<p id="apig-en-api-180328003__p066712334263">A cloud service can be deployed globally or at the project level.</p>
<ul id="apig-en-api-180328003__ul11667123332614"><li id="apig-en-api-180328003__li17667173382616">A project-level service requires a project-level token. When you call the API, set <strong id="apig-en-api-180328003__b18431516468">auth.scope</strong> in the request body to <strong id="apig-en-api-180328003__b5845158464">project</strong>. The following services are at the project level: AOM, APIG, AS, BMS, CBR, CCE, Cloud Eye, CSBS, CSS, CTS, DataArts Studio, DC, DCS, DDS, Dedicated WAF, DeH, DIS, DLI, DMS, DNS, DRS, DWS, ECS, EIP, ELB, EVS, GaussDB (for MySQL), GaussDB NoSQL, IMS, KMS, LTS, ModelArts, MRS, NAT, PLAS, RDS, RTS, SDRS, SFS, SMN, SWR, VBS, VPC, VPCEP, VPN, and WAF.</li><li id="apig-en-api-180328003__li7667233182615">A global service requires a global token. When you call the API, set <strong id="apig-en-api-180328003__b16642105915485">auth.scope</strong> in the request body to <strong id="apig-en-api-180328003__b364265915485">domain</strong>. The following services are global ones: Anti-DDoS, IAM, OBS, TMS, and TMS.</li></ul>
<div class="p" id="apig-en-api-180328003__p4434491412249">The following shows an example of a project-level service request:<div class="note" id="apig-en-api-180328003__note6355990812249"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="apig-en-api-180328003__p3516826412249">Replace the texts in italic with actual ones. For details, see <em id="apig-en-api-180328003__i842352697155127">Identity and Access Management API Reference</em>.</p>
<p id="apig-en-api-180328003__p1770474713271">Log in to the management console, click your username in the upper right corner, and choose <strong id="apig-en-api-180328003__b1424175514817">My Credential</strong> from the drop-down list. On the <strong id="apig-en-api-180328003__b362886114912">My Credentials</strong> page, obtain your username, domain name, and project ID.</p>
</div></div>
<pre class="screen" id="apig-en-api-180328003__screen18966866105917">{
"auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"name": "<em id="apig-en-api-180328003__i3005717212249"><strong id="apig-en-api-180328003__b34061845415">username</strong></em>", // IAM username
"password": "<em id="apig-en-api-180328003__i207909212249"><strong id="apig-en-api-180328003__b626512207546">password</strong></em>", // IAM user password
"domain": {
"name": "<em id="apig-en-api-180328003__i1871183512249"><strong id="apig-en-api-180328003__b7805102111542">domainname</strong></em>" // Name of the domain to which the IAM user belongs
}
}
}
},
"scope": {
"<strong id="apig-en-api-180328003__b563015402144">project</strong>": {
"id": "<strong id="apig-en-api-180328003__b4301132835416"><em id="apig-en-api-180328003__i1191627165415">0215ef11e49d4743be23dd97a1561e91</em></strong>" // Project ID
}
}
}
}</pre>
</div>
<p id="apig-en-api-180328003__p1847182114579">The following shows an example of a global service request:</p>
<pre class="screen" id="apig-en-api-180328003__screen184324210584">{
"auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"name": "<em id="apig-en-api-180328003__i1589423111011"><strong id="apig-en-api-180328003__b1589423112012">username</strong></em>", // IAM username
"password": "<em id="apig-en-api-180328003__i7932938307"><strong id="apig-en-api-180328003__b149328381909">password</strong></em>", // IAM user password
"domain": {
"name": "<em id="apig-en-api-180328003__i34335451306"><strong id="apig-en-api-180328003__b343319451304">domainname</strong></em>" // Name of the domain to which the IAM user belongs
}
}
}
},
"scope": {
"<strong id="apig-en-api-180328003__b191917362143">domain</strong>": {
"name": "<em id="apig-en-api-180328003__i13403382119"><strong id="apig-en-api-180328003__b74031884120">domainname</strong></em>" // Name of the domain to which the IAM user belongs
}
}
}
}</pre>
</li><li id="apig-en-api-180328003__li2615608112249"><a name="apig-en-api-180328003__li2615608112249"></a><a name="li2615608112249"></a>Obtain the token. For details, see section "Obtaining the User Token" in the <em id="apig-en-api-180328003__i9409102014312">Identity and Access Management API Reference</em>. If the request is successful, the value of the X-Subject-Token header in the response is the token.<p id="apig-en-api-180328003__p183451053025">The following figures illustrate how to use Postman to manually obtain a token.</p>
<div class="fignone" id="apig-en-api-180328003__fig423411369101"><span class="figcap"><b>Figure 1 </b>Example request</span><br><span><img id="apig-en-api-180328003__image1460602112316" src="en-us_image_0139098594.png" title="Click to enlarge" class="imgResize"></span></div>
<div class="fignone" id="apig-en-api-180328003__fig1097673441212"><span class="figcap"><b>Figure 2 </b>Obtain <strong id="apig-en-api-180328003__b89061138185418">X-Subject-Token</strong> from the header of the response message.</span><br><span><img id="apig-en-api-180328003__image10464847153010" src="en-us_image_0139099203.png" title="Click to enlarge" class="imgResize"></span></div>
</li><li id="apig-en-api-180328003__li3407814412249">Call a service API, add the <strong id="apig-en-api-180328003__b208194011610">X-Auth-Token</strong> header with the token obtained in <a href="#apig-en-api-180328003__li2615608112249">2</a>.</li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="apig-en-api-180925010.html">Calling APIs</a></div>
</div>
</div>
<script language="JavaScript">
<!--
image_size('.imgResize');
var msg_imageMax = "view original image";
var msg_imageClose = "close";
//--></script>

View File

@ -0,0 +1,36 @@
<a name="apig-en-api-180328004"></a><a name="apig-en-api-180328004"></a>
<h1 class="topictitle1">AK/SK Authentication</h1>
<div id="body1521445726195"><p id="apig-en-api-180328004__p4081232010247">When you use API Gateway to send requests to underlying services, the requests must be signed using the AK and SK.</p>
<div class="note" id="apig-en-api-180328004__note39290400185533"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="apig-en-api-180328004__p43222010185539">AK is a unique identifier that is associated with a secret access key; the access key ID and secret access key are used together to sign requests cryptographically.</p>
<p id="apig-en-api-180328004__p27812810185625">SK is a key that is used in conjunction with an access key ID to cryptographically sign requests. Signing a request identifies the sender and prevents the request from being altered.</p>
</div></div>
<p id="apig-en-api-180328004__p177381608119">The AK/SK authentication process is as follows:</p>
<ol id="apig-en-api-180328004__ol3895253574"><li id="apig-en-api-180328004__li889518531076"><a name="apig-en-api-180328004__li889518531076"></a><a name="li889518531076"></a>A standard request is created.</li><li id="apig-en-api-180328004__li1541420241986">A to-be-signed string is created using the request and other related information.</li><li id="apig-en-api-180328004__li198402221915"><a name="apig-en-api-180328004__li198402221915"></a><a name="li198402221915"></a>A signature is calculated using the AK/SK and to-be-signed string.</li><li id="apig-en-api-180328004__li68021236101010">The generated signature is added as a header or a query parameter in the HTTP request.</li><li id="apig-en-api-180328004__li12754191891410">After receiving the request, API Gateway performs <a href="#apig-en-api-180328004__li889518531076">1</a> to <a href="#apig-en-api-180328004__li198402221915">3</a> to calculate a signature.</li><li id="apig-en-api-180328004__li1440182718209">The new signature is compared with the signature generated in <a href="#apig-en-api-180328004__li198402221915">3</a>. If they are consistent, the request is processed; otherwise, the request is rejected.</li></ol>
<p id="apig-en-api-180328004__p193791486216"><a href="#apig-en-api-180328004__fig104904517537">Figure 1</a> shows the process of calling APIs through AK/SK authentication.</p>
<div class="fignone" id="apig-en-api-180328004__fig104904517537"><a name="apig-en-api-180328004__fig104904517537"></a><a name="fig104904517537"></a><span class="figcap"><b>Figure 1 </b>API calling process flow</span><br><span><img class="imgResize" id="apig-en-api-180328004__image1749635618277" src="en-us_image_0161965716.png" title="Click to enlarge"></span></div>
<div class="note" id="apig-en-api-180328004__note14106145674716"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="apig-en-api-180328004__ul4407983487"><li id="apig-en-api-180328004__li11407988488">If a failure occurs in any step, the failure will be returned to the client application.</li><li id="apig-en-api-180328004__li1091411114818">The cached token is valid for 15 minutes by default.</li></ul>
</div></div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="apig-en-api-180328005.html">Generating an AK and SK</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="apig-en-api-180328006.html">Signing a Request</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="apig-en-api-180328008.html">Sample Code</a></strong><br>
</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="apig-en-api-180925010.html">Calling APIs</a></div>
</div>
</div>
<script language="JavaScript">
<!--
image_size('.imgResize');
var msg_imageMax = "view original image";
var msg_imageClose = "close";
//--></script>

View File

@ -0,0 +1,15 @@
<a name="apig-en-api-180328005"></a><a name="apig-en-api-180328005"></a>
<h1 class="topictitle1">Generating an AK and SK</h1>
<div id="body1537444154231"><ol id="apig-en-api-180328005__ol6063434420657"><li id="apig-en-api-180328005__li53268082161429">Log in to the management console.</li><li id="apig-en-api-180328005__li58707242194127">Click the username and choose <strong id="apig-en-api-180328005__b15347312181919">My Credential</strong> from the drop-down list.</li></ol><ol start="3" id="apig-en-api-180328005__ol1866691320747"><li id="apig-en-api-180328005__li64261916202213">Click <strong id="apig-en-api-180328005__b25322139195">Access Keys</strong>.</li><li id="apig-en-api-180328005__li1327987320742">Click <strong id="apig-en-api-180328005__b77941514131917">Add Access Keys</strong> to switch to the <strong id="apig-en-api-180328005__b12795614141914">Add Access Keys</strong> page.</li><li id="apig-en-api-180328005__li12076053102753">Enter your login password.</li><li id="apig-en-api-180328005__li18362662204736">Enter the verification code sent to your mailbox or mobile phone.<div class="note" id="apig-en-api-180328005__note35171693204736"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="apig-en-api-180328005__ul26525690204736"><li id="apig-en-api-180328005__li30992410204736">Users that are created in IAM without specifying email addresses or mobile numbers only need to enter their login passwords.</li><li id="apig-en-api-180328005__li28362923204736">MyWorkplace users are not required to enter their login passwords. They can create new access keys without entering verification codes if no email addresses or mobile numbers have been specified.</li></ul>
</div></div>
</li></ol><ol start="7" id="apig-en-api-180328005__ol6544796411157"><li id="apig-en-api-180328005__li38629386204736">Click <strong id="apig-en-api-180328005__b13623101072111">OK</strong> to download the access key.<div class="note" id="apig-en-api-180328005__note3606752619504"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p class="text" id="apig-en-api-180328005__p59314629204732">Keep the AK/SK file confidential to prevent information leakage.</p>
</div></div>
</li></ol>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="apig-en-api-180328004.html">AK/SK Authentication</a></div>
</div>
</div>

View File

@ -0,0 +1,25 @@
<a name="apig-en-api-180328006"></a><a name="apig-en-api-180328006"></a>
<h1 class="topictitle1">Signing a Request</h1>
<div id="body1537444154804"><ol id="apig-en-api-180328006__ol930865701011"><li id="apig-en-api-180328006__li17137133433914"><a name="apig-en-api-180328006__li17137133433914"></a><a name="li17137133433914"></a>Introduce the API Gateway signing SDK in the project.<ol type="a" id="apig-en-api-180328006__ol54494262406"><li id="apig-en-api-180328006__li9451162612408">Download the API Gateway signing tool from the following link:<p id="apig-en-api-180328006__p122916401107"><a name="apig-en-api-180328006__li9451162612408"></a><a name="li9451162612408"></a><a href="https://apig-demo.obs.eu-de.otc.t-systems.com/java/java-sdk-core.zip" target="_blank" rel="noopener noreferrer">https://apig-demo.obs.eu-de.otc.t-systems.com/java/java-sdk-core.zip</a></p>
</li><li id="apig-en-api-180328006__li54621026114019">Decompress the downloaded package to obtain a <strong id="apig-en-api-180328006__b12397105192410">.jar</strong> file.</li><li id="apig-en-api-180328006__li1046402634017">Add the decompressed <strong id="apig-en-api-180328006__b765309142415">.jar</strong> file to a project, for example, Eclipse, as a dependency package. See the following figure.<p id="apig-en-api-180328006__p9619172034018"><span><img id="apig-en-api-180328006__image534782164016" src="en-us_image_0132557229.png" title="Click to enlarge" class="imgResize"></span></p>
</li></ol>
</li><li id="apig-en-api-180328006__li18855549161113">Sign the request.<p id="apig-en-api-180328006__p147949344572"><a name="apig-en-api-180328006__li18855549161113"></a><a name="li18855549161113"></a>The signing method is integrated into the <strong id="apig-en-api-180328006__b11687487240">.jar</strong> file added in <a href="#apig-en-api-180328006__li17137133433914">1</a>. Before sending the request, sign the requested content. The signature obtained is included in the HTTP header of the request.</p>
<p id="apig-en-api-180328006__p9205028144610">For details, see <a href="apig-en-api-180328008.html">Sample Code</a>.</p>
<div class="notice" id="apig-en-api-180328006__note47372794014"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="apig-en-api-180328006__p1773727144016">The JDK version cannot be earlier than 1.8.</p>
</div></div>
</li></ol>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="apig-en-api-180328004.html">AK/SK Authentication</a></div>
</div>
</div>
<script language="JavaScript">
<!--
image_size('.imgResize');
var msg_imageMax = "view original image";
var msg_imageClose = "close";
//--></script>

View File

@ -0,0 +1,79 @@
<a name="apig-en-api-180328008"></a><a name="apig-en-api-180328008"></a>
<h1 class="topictitle1">Sample Code</h1>
<div id="body1537444154811"><div class="section" id="apig-en-api-180328008__section1596319488437"><h4 class="sectiontitle">Scenario</h4><p id="apig-en-api-180328008__p1220414484384">This section describes how to call the API of a public cloud service by using Eclipse.</p>
<div class="p" id="apig-en-api-180328008__p363635184312">The following code shows how to sign a request and how to use an HTTP client to send an HTTPS request. The code is categorized into three classes:<ul id="apig-en-api-180328008__ul109498014112"><li id="apig-en-api-180328008__li119491103110"><strong id="apig-en-api-180328008__b38114539368">AccessService</strong>: an abstract class that merges the GET, POST, PUT, and DELETE methods into the access method.</li><li id="apig-en-api-180328008__li16949701211"><strong id="apig-en-api-180328008__b16692111103719">Demo</strong>: execution entry that simulates GET, POST, PUT, and DELETE requests.</li><li id="apig-en-api-180328008__li99492015115"><strong id="apig-en-api-180328008__b79386273717">AccessServiceImpl</strong>: implementation of the access method. The code required for API Gateway communication is included in the access method.</li></ul>
</div>
<p id="apig-en-api-180328008__p265415818244">You can download the sample code package from <a href="https://apig-demo.obs.eu-de.otc.t-systems.com/java/SdkDemo.zip" target="_blank" rel="noopener noreferrer">https://apig-demo.obs.eu-de.otc.t-systems.com/java/SdkDemo.zip</a>.</p>
<div class="notice" id="apig-en-api-180328008__note47372794014"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="apig-en-api-180328008__p1773727144016">The JDK version cannot be earlier than 1.8.</p>
</div></div>
</div>
<div class="section" id="apig-en-api-180328008__section98551696457"><h4 class="sectiontitle">Procedure</h4><ol id="apig-en-api-180328008__ol1515318170459"><li id="apig-en-api-180328008__li1115311720450">Download the sample code package and decompress it.</li><li id="apig-en-api-180328008__li1210954191115">Import the sample project to Eclipse.<div class="fignone" id="apig-en-api-180328008__fig16546145205014"><span class="figcap"><b>Figure 1 </b>Selecting an existing project</span><br><span><img id="apig-en-api-180328008__image1474131114720" src="en-us_image_0132432937.png" title="Click to enlarge" class="imgResize"></span></div>
<div class="fignone" id="apig-en-api-180328008__fig767232218519"><span class="figcap"><b>Figure 2 </b>Selecting the sample code file after decompression</span><br><span><img id="apig-en-api-180328008__image13419842205018" src="en-us_image_0132432939.png" title="Click to enlarge" class="imgResize"></span></div>
<div class="fignone" id="apig-en-api-180328008__fig159778103242"><span class="figcap"><b>Figure 3 </b>Structure of the project after importing</span><br><span><img id="apig-en-api-180328008__image128044312389" src="en-us_image_0132518357.png"></span></div>
</li><li id="apig-en-api-180328008__li1985133317503">Edit the main method in the <strong id="apig-en-api-180328008__b12111822184012">Demo.java</strong> file.<p id="apig-en-api-180328008__p2061535616161">Replace the bold texts with actual values. If you use other methods, such as POST, PUT, and DELETE, see the corresponding annotations.</p>
<p id="apig-en-api-180328008__p129401344175213">Replace the parameters in the URL, for example, <strong id="apig-en-api-180328008__b61192044135710">project_id</strong>.</p>
<p id="apig-en-api-180328008__p76929333513">For details on how to obtain your region name, service name, AK/SK, project ID, and domain ID, see <a href="apig-en-api-180328009.html">Obtaining Required Information</a>.</p>
<pre class="screen" id="apig-en-api-180328008__screen1282532262819">//<strong id="apig-en-api-180328008__b682822216285">TODO</strong>: Replace <strong id="apig-en-api-180328008__b1494717204464">eu-de</strong> with the name of the region in which the service to be accessed is located.
<strong id="apig-en-api-180328008__b3836162292818">private</strong> <strong id="apig-en-api-180328008__b14838142214284">static</strong> <strong id="apig-en-api-180328008__b9840162252820">final</strong> String <strong id="apig-en-api-180328008__b168426222280"><em id="apig-en-api-180328008__i78434223289">region</em></strong> = "<strong id="apig-en-api-180328008__b984611224288">eu-de</strong>";
//<strong id="apig-en-api-180328008__b485092242814">TODO</strong>: Replace <strong id="apig-en-api-180328008__b1289103244620">vpc</strong> with the name of the service you want to access. For example, ecs, vpc, iam, and elb.
<strong id="apig-en-api-180328008__b1085511229289">private</strong> <strong id="apig-en-api-180328008__b148569223286">static</strong> <strong id="apig-en-api-180328008__b2858922162819">final</strong> String <strong id="apig-en-api-180328008__b1886002219283"><em id="apig-en-api-180328008__i08607227287">serviceName</em></strong> = "<strong id="apig-en-api-180328008__b10864422132819">vpc</strong>";
<strong id="apig-en-api-180328008__b586872292810">public</strong> <strong id="apig-en-api-180328008__b387022202811">static</strong> <strong id="apig-en-api-180328008__b9872422122810">void</strong> main(String[] args) <strong id="apig-en-api-180328008__b1687452216287">throws</strong> UnsupportedEncodingException
{
//<strong id="apig-en-api-180328008__b14878522192811">TODO</strong>: Replace the AK and SK with those obtained on the <strong id="apig-en-api-180328008__b96051419463">My Credential</strong> page.
String ak = "<strong id="apig-en-api-180328008__b1788482282817">ZIRRKMTWPTQFQI1WKNKB</strong>";
String sk = "<strong id="apig-en-api-180328008__b15888122142815">Us0mdMNHk******YrRCnW0ecfzl</strong>";
//<strong id="apig-en-api-180328008__b138911622102819">TODO</strong>: To specify a project ID (multi-project scenarios), add the X-Project-Id header.
//<strong id="apig-en-api-180328008__b188965224282">TODO</strong>: To access a global service, such as IAM, DNS, CDN, and TMS, add the X-Domain-Id header to specify an account ID.
//<strong id="apig-en-api-180328008__b690112219287">TODO</strong>: To add a header, find "Add special headers" in the <strong id="apig-en-api-180328008__b1545410554465">AccessServiceImple.java</strong> file.
//<strong id="apig-en-api-180328008__b18907182213284">TODO</strong>: Test the API
String url = "<strong id="apig-en-api-180328008__b20913522132813">https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/vpcs/{vpc_id}</strong>";
<em id="apig-en-api-180328008__i1291714227289">get</em>(ak, sk, url);
//<strong id="apig-en-api-180328008__b7926142272813">TODO</strong>: When creating a VPC, replace <em id="apig-en-api-180328008__i6496148124718">{project_id}</em> in postUrl with the actual value.
//String postUrl = "https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/cloudservers";
//String postbody ="{\"<u id="apig-en-api-180328008__u393210221281">vpc</u>\": {\"name\": \"vpc\",\"cidr\": \"192.168.0.0/16\"}}";
//post(ak, sk, postUrl, postbody);
//<strong id="apig-en-api-180328008__b39371722132816">TODO</strong>: When querying a VPC, replace <em id="apig-en-api-180328008__i29291714154718">{project_id}</em> in url with the actual value.
//String url = "https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/vpcs/{vpc_id}";
//get(ak, sk, url);
//<strong id="apig-en-api-180328008__b795092292816">TODO</strong>: When updating a VPC, replace <em id="apig-en-api-180328008__i96031294474">{project_id}</em> and <em id="apig-en-api-180328008__i3423933194716">{vpc_id}</em> in putUrl with the actual values.
//String putUrl = "https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/vpcs/{vpc_id}";
//String putbody ="{\"vpc\":{\"name\": \"vpc1\",\"cidr\": \"192.168.0.0/16\"}}";
//put(ak, sk, putUrl, putbody);
//<strong id="apig-en-api-180328008__b1996262292817">TODO</strong>: When deleting a VPC, replace <em id="apig-en-api-180328008__i1564824510475">{project_id}</em> and <em id="apig-en-api-180328008__i3443250124716">{vpc_id}</em> in deleteUrl with the actual values.
//String deleteUrl = "https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/vpcs/{vpc_id}";
//delete(ak, sk, deleteUrl);
}</pre>
</li><li id="apig-en-api-180328008__li692519271935">(Optional) To call a service API of a sub-project or to add a self-defined header, perform the following steps:<ol type="a" id="apig-en-api-180328008__ol12427135611263"><li id="apig-en-api-180328008__li54271856142617">In the main method in the <strong id="apig-en-api-180328008__b112361621145020">Demo.java</strong> file, replace <strong id="apig-en-api-180328008__b5766162611504">project_id</strong> with the sub-project ID of the API.<pre class="screen" id="apig-en-api-180328008__screen11631945182617">//<strong id="apig-en-api-180328008__b763444562619">TODO</strong>: Test the API
String url = "https://vpc.eu-de.otc.t-systems.com/v1/{<strong id="apig-en-api-180328008__b363934516261">project_id</strong>}/vpcs/{vpc_id}";
<em id="apig-en-api-180328008__i1164219452266">get</em>(ak, sk, url);</pre>
</li><li id="apig-en-api-180328008__li11427145613263"><a name="apig-en-api-180328008__li11427145613263"></a><a name="li11427145613263"></a>Locate the following lines in the <strong id="apig-en-api-180328008__b117131855110">AccessServiceImpl.java</strong> file, delete "//" to activate the code line, and replace the sub-project ID with the actual one.<pre class="screen" id="apig-en-api-180328008__screen17729190153516">//<strong id="apig-en-api-180328008__b167326033518">TODO</strong>: Add special headers.
//request.addHeader("X-Project-Id", "<strong id="apig-en-api-180328008__b77328083512">xxxxx</strong>");</pre>
</li><li id="apig-en-api-180328008__li47751621276">Repeat <a href="#apig-en-api-180328008__li11427145613263">4.b</a> to add other self-defined headers.</li></ol>
</li><li id="apig-en-api-180328008__li18412306320">Compile and run the API calling code.<p id="apig-en-api-180328008__p188281527115415"><a name="apig-en-api-180328008__li18412306320"></a><a name="li18412306320"></a>Find <strong id="apig-en-api-180328008__b350175610616">Demo.java</strong> in the left pane of the Package Explorer, right-click, and choose <strong id="apig-en-api-180328008__b1685091315113">Run AS</strong> &gt; <strong id="apig-en-api-180328008__b340219171313">Java Application</strong>.</p>
<p id="apig-en-api-180328008__p20946560369">View the API call logs on the console.</p>
</li></ol>
</div>
<p id="apig-en-api-180328008__p56708187102740"></p>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="apig-en-api-180328004.html">AK/SK Authentication</a></div>
</div>
</div>
<script language="JavaScript">
<!--
image_size('.imgResize');
var msg_imageMax = "view original image";
var msg_imageClose = "close";
//--></script>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,16 @@
<a name="apig-en-api-180925010"></a><a name="apig-en-api-180925010"></a>
<h1 class="topictitle1">Calling APIs</h1>
<div id="body1537441012740"><p id="apig-en-api-180925010__p8060118"></p>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="apig-en-api-180328009.html">Obtaining Required Information</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="apig-en-api-180328003.html">Token Authentication</a></strong><br>
</li>
<li class="ulchildlink"><strong><a href="apig-en-api-180328004.html">AK/SK Authentication</a></strong><br>
</li>
</ul>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 836 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 834 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 962 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1014 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB