# Use the Discourse API ruby gem

**URL:** https://meta.discourse.org/t/use-the-discourse-api-ruby-gem/17587
**Category:** Integrations
**Tags:** rest-api, how-to
**Created:** [July 15, 2014, 3:29am UTC](https://meta.discourse.org/t/use-the-discourse-api-ruby-gem/17587 "2014-07-15T03:29:14Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [July 15, 2014, 3:29am UTC](https://meta.discourse.org/t/use-the-discourse-api-ruby-gem/17587/1 "2014-07-15T03:29:15Z")

</div>

So you want to use [Discourse API](https://meta.discourse.org/t/discourse-api-documentation/22706)? Great! Let’s get started.

## Set up Discourse development environment

Set up Discourse development environment using our [Windows](https://meta.discourse.org/t/install-discourse-on-windows-for-development/75149), [macOS](https://meta.discourse.org/t/install-discourse-on-macos-for-development/15772/) or [Ubuntu](https://meta.discourse.org/t/install-discourse-on-ubuntu-or-debian-for-development/14727/) guide.

## Clone Discourse API Gem

Now that you have set up Discourse development environment, you should already have Git and Ruby installed on your system. You can install Discourse API gem by running following command from console:

```
git clone https://github.com/discourse/discourse_api.git ~/discourse_api

```

Alternatively, you can install the gem directly:

```
gem install discourse_api

```

## Install dependencies

Open the `discourse_api` directory and type:

```
bundle install

```

This will install any required gem dependencies.

## Generate API Key

Generate an API Key for your Discourse instance by visiting `/admin/api/keys`, to interact with Discourse API.

## Provide API Credentials

Now that you have cloned Discourse API gem and generated an API key, let’s start using it!

Open the `discourse_api/examples/example.rb` file, and modify following information:

```plaintext
client = DiscourseApi::Client.new("http://localhost:3000")
client.api_key = "YOUR_API_KEY"
client.api_username = "YOUR_USERNAME"

```

Replace `http://localhost:3000` with the url of your discourse instance, eg: `http://discourse.example.com`

Replace `YOUR_API_KEY` with the API key of your discourse instance, eg: `b1f3175cb682b3e9b6ca419db77772120b19af993cbc14ebed80fea08e3bbd66`

Replace `YOUR_USERNAME` with the Admin username of your discourse instance, eg: `codinghorror`

## Access Discourse API

Now in console, from `discourse_api` directory run:

```
ruby examples/example.rb

```

This command will print out latest topics from your Discourse instance.

That’s it. Start using [Discourse API](https://meta.discourse.org/t/discourse-api-documentation/22706) today.

* * *

_Additional Resources:_  
[Discourse API Documentation](https://docs.discourse.org/)

* * *

_Last Reviewed by @SaraDev on 2022-07-13T01:00:00Z_
