# How to create a plugin with backend API calls to populate composer while drafting?

**URL:** https://meta.discourse.org/t/how-to-create-a-plugin-with-backend-api-calls-to-populate-composer-while-drafting/356970
**Category:** Development
**Created:** [March 12, 2025, 2:38pm UTC](https://meta.discourse.org/t/how-to-create-a-plugin-with-backend-api-calls-to-populate-composer-while-drafting/356970 "2025-03-12T14:38:02Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![renato](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renato/32/383632_2.png) [@renato](https://meta.discourse.org/u/renato)
#### Post date: [March 12, 2025, 6:24pm UTC](https://meta.discourse.org/t/how-to-create-a-plugin-with-backend-api-calls-to-populate-composer-while-drafting/356970/3 "2025-03-12T18:24:59Z")

</div>

> [@fabkosta](#):
>
> (running under my own URL that requires an API key)

It doesn’t seem like you need any backend changes. The behavior you describe is very similar to how our [“Insert Hyperlink” modal](https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.gjs) works – you can search for topics, select one of them to add as a link, and a link will be added to the composer when you confirm.

You can add the button to a [plugin outlet](https://meta.discourse.org/t/using-plugin-outlet-connectors-from-a-theme-or-plugin/32727), or to the toolbar via a [`api.onToolbarCreate`](https://github.com/discourse/discourse/blob/897b043f01e9e06c14239c233efd3dab5be85aae/app/assets/javascripts/discourse/app/lib/plugin-api.gjs#L1008-L1027) added to an initializer, and open a modal similarly to how we’re doing it for the [“Insert Hyperlink” modal](https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.gjs). It’s able to [`addText`](https://github.com/discourse/discourse/blob/897b043f01e9e06c14239c233efd3dab5be85aae/app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.gjs#L142-L149) to the composer by levering the [`toolbarEvent` object](https://github.com/discourse/discourse/blob/897b043f01e9e06c14239c233efd3dab5be85aae/app/assets/javascripts/discourse/app/components/d-editor.js#L565-L570) from the toolbar action (if you need an outlet, you can also interact with the composer via [`appEvents` triggers](https://meta.discourse.org/t/appevents-triggers-reference/338465#p-1654554-composerinsert-text-linkhttpsgithubcomdiscoursediscourseblobmainappassetsjavascriptsdiscourseappservicessearchjsl42-46)).

---

_[View the full topic](https://meta.discourse.org/t/how-to-create-a-plugin-with-backend-api-calls-to-populate-composer-while-drafting/356970)._
