Your Power-Up will need to interact with the Trello API to perform some operations. For example:

  • Get information on Trello data, such as Cards and Boards and their metadata

  • Set metadata on Trello Cards and Boards

  • Creating, updating and deleting Cards

Use this article to find out how to use the Trello API Provider and associated React Hook to access the Trello API, also known as t.


1. Install the @optro/api-client package

Before you can use the Optro UI, you need to install it:

# Using Yarn
yarn add @optro/api-client

# Using NPM
npm install @optro/api-client

2. Add the TrelloProvider to the root of your React project

Find out how to access the Trello API throughout your Power-Up using the TrelloProvider at the root level and then calling the useTrelloApi hook to access the client.

First, place the following code at the root of your project:

import {TrelloProvider} from '@optro/ui-react';
const t = window.TrelloPowerUp.iframe();

function ReactRoot() {
  return (
    <TrelloProvider t={t}>

3. Use the useProvidedTrello() React Hook to use the Trello API

Next, use the following React Hook which provides access to the Trello API in a component that is lower down the hierarchy:

import {useProvidedTrello} from '@optro/ui-react';

function ReactComponent() {
  const t = useProvidedTrello();
  // Use the Trello API

4. Use TypeScript Code Completion

As the Trello types are in the types/trello.d.ts file in the template and any generated projects, you can use these TypeScript types to enable auto-completion on the Trello JavaScript API.

If you’re not using the generator or template, you can use the types in your own project using the Trello Types File.

Check out an example of this auto-completion in IntelliJ IDEA:

This form of autocompletion is supported in most IDE’s e.g. VS Code, Atom, WebStorm.

API Reference

If you want full documentation on what functions are available in the Trello API, check out the following resource:

Next Steps

You should now have access to the Trello API inside your React components, provided they have a parent component that contains the provider.

Next, you may be interested to see how capabilities are handled in the project and how they can be extended:

Add Capabilities to your Power-Up