# コンポーネントからAPIにアクセスする

**URL:** <https://meta.discourse.org/t/accessing-the-api-from-a-component/271311>\
**Category:** Development\
**Created:** [2023 年 7 月 11 日午後 10:41 UTC](https://meta.discourse.org/t/accessing-the-api-from-a-component/271311 "2023-07-11T22:41:35Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pipkin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pipkin/32/134643_2.png) [@pipkin](https://meta.discourse.org/u/pipkin)\
**Post date:** [2023 年 7 月 13 日午後 7:26 UTC](https://meta.discourse.org/t/accessing-the-api-from-a-component/271311/2 "2023-07-13T19:26:18Z")

</div>

承知いたしました。このように行います。

```js
import { withPluginApi } from "discourse/lib/plugin-api";

export default {
    setupComponent() {
        withPluginApi("0.12.3", api => {
            console.log(api.getCurrentUser());
        });
    },
};

```

---

_[View the full topic](https://meta.discourse.org/t/accessing-the-api-from-a-component/271311)._
