# Getting an error while trying to fetch individual posts

**URL:** https://meta.discourse.org/t/getting-an-error-while-trying-to-fetch-individual-posts/224255
**Category:** General
**Created:** [April 14, 2022, 10:28am UTC](https://meta.discourse.org/t/getting-an-error-while-trying-to-fetch-individual-posts/224255 "2022-04-14T10:28:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Allen\_Chen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/allen_chen/32/256627_2.png) [@Allen\_Chen](https://meta.discourse.org/u/Allen_Chen)
#### Post date: [April 14, 2022, 10:28am UTC](https://meta.discourse.org/t/getting-an-error-while-trying-to-fetch-individual-posts/224255/1 "2022-04-14T10:28:32Z")

</div>

I’m trying to fetch the data of specific posts in Discourse. But while trying to do that, I’m getting the error that access is restricted, so I proceeded to add my API keys to the header. To do that I’ve written the following code:

```plaintext
axios.get(`{myURL}/posts/${pid}.json`, {
    'mode': 'cors',
    headers: {
      Authorization: '{myAPIKey}'
    }})
    .then(function (response) {
      consol.log(response)
      setPostData(response.data?.topic_list?.topics)
    }) 
    .catch(function (error) {
      console.log(error)
    })

```

I’ve already added CORS to de Discourse server to allow requests from my server. Issue with this is that now I’m getting a CORS error which says the following: `Response to preflight request doesn't pass access control check: It does not have HTTP ok status.`

I don’t understand what may I have done wrong as everything seems okay

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [April 14, 2022, 4:19pm UTC](https://meta.discourse.org/t/getting-an-error-while-trying-to-fetch-individual-posts/224255/2 "2022-04-14T16:19:43Z")

</div>

~~Here is an authorization header that I use in Ruby:~~

~~headers = { ‘Authorization’ =\> “Bearer #{do\_api\_key}” }~~

~~So I think that you need to add `Bearer ` beforeyour api key.~~

Here are headers:

```
         headers = { 'api-key' => discourse_api_key, 'api-username' => 'system' }

```

So I think you need headers like those. [Discourse REST API Documentation](https://meta.discourse.org/t/discourse-api-documentation/22706) is supposed to help with that.
