> For the complete documentation index, see [llms.txt](https://docs-epc.gitbook.io/ncs-documents/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-epc.gitbook.io/ncs-documents/public-api/getting-start-with-ncs-public-api/using-rest-api.md).

# Using REST API

## Prerequisite

* มี account ใช้งานบน NIPA Cloud Space
* มี access เข้า project ที่มี wallet status เป็น Normal

## Instructions

### 1. ดูข้อมูล project ID บน NIPA Cloud Space

เข้าสู่หน้า project detail จากการเลือก project ที่ต้องการที่หน้า projects management และเลือก copy project ID

<figure><img src="/files/u6GQ6cEtDPcf3zjhFa29" alt=""><figcaption></figcaption></figure>

### 2. Authen เข้าใช้งาน OpenStack API

ใช้ cURL ในการ authenticate OpenStack API

<pre><code>curl -i -X POST \
<strong>https://identity-api.nipa.cloud/v3/auth/tokens \
</strong>  -H "Content-Type: application/json" \
  -d '
{
  "auth": {
    "identity": {
      "methods": [
        "password"
      ],
      "password": {
        "user": {
          "name": "&#x3C;email สำหรับใช้ login เข้า NCS>",
          "password": "&#x3C;password สำหรับใช้ login เข้า NCS>",
          "domain": { "name": "nipacloud" }
        }
      }
    },
    "scope": {
      "project": {
        "id": "&#x3C;project ID ที่ copy มาจากหน้า project detail>"
      }
    }
  }
}'
</code></pre>

เมื่อได้ผลเป็น Created (201) ให้ทำการ copy X-Subject-Token ใน response header ไปใช้งานต่อ

และสามารถดู API endpoint ได้จาก catalog ใน response body

อ่านเพิ่มเติม <https://docs.openstack.org/api-quick-start/api-quick-start.html#authenticate>

***

## ตัวอย่างการใช้งาน API

ดูรายการ API สำหรับจัดการ Compute Instance ได้จาก <https://docs.openstack.org/api-ref/compute/>

### 1. ทำการ set variable

ทำการ export token variable โดยใช้ command

```
export OS_TOKEN=<X-Subject-Token ที่ได้จาก header ของการ authen>
```

export Compute API endpoint โดยใช้ command

```
export OS_COMPUTE_API=<Compute API endpoint จาก catalog ของการ authen>
```

### 2. ทำ action กับ Compute Instance

สั่ง REST API เพื่อทำ action กับ Compute Instance (Server)

```
curl -L -X POST -H "X-Auth-Token: $OS_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"os-stop": null}' \
     $OS_COMPUTE_API/servers/{server_id}/action
```

***

## Reference

* keystone api ref : <https://docs.openstack.org/api-ref/identity/v3/>
* glace api ref : <https://docs.openstack.org/api-ref/image/v2/>
* nova api ref : <https://docs.openstack.org/api-ref/compute/>
* cinder api ref : <https://docs.openstack.org/api-ref/block-storage/v3/>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-epc.gitbook.io/ncs-documents/public-api/getting-start-with-ncs-public-api/using-rest-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
