# Retrieving post.raw only works right after creating post

**URL:** https://meta.discourse.org/t/retrieving-post-raw-only-works-right-after-creating-post/115267
**Category:** Development
**Created:** [April 16, 2019, 11:17pm UTC](https://meta.discourse.org/t/retrieving-post-raw-only-works-right-after-creating-post/115267 "2019-04-16T23:17:27Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Mathijs\_V](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mathijs_v/32/135133_2.png) [@Mathijs\_V](https://meta.discourse.org/u/Mathijs_V)
#### Post date: [April 16, 2019, 11:17pm UTC](https://meta.discourse.org/t/retrieving-post-raw-only-works-right-after-creating-post/115267/1 "2019-04-16T23:17:27Z")

</div>

Hi there,

At the moment I am working on an extra PostMenuButton. Funny thing is that the **Cooked post** is always available but the **Raw post** is not!

Running discourse version [v2.3.0.beta8 +103]

```plaintext
<script type = "text/discourse-plugin" version = "0.1" >

  api.addPostMenuButton('trimetrack', attrs => {
    return {
      action: 'createTimeTracking',
      icon: 'calendar-alt',
      className: 'time-tracking',
      title: 'time_tracking',
      position: 'first'
    };
  }
                       );
  api.attachWidgetAction('post-menu', 'createTimeTracking', function() {
    const post = this.findAncestorModel();
    alert("Raw post: " + post.raw);
    alert("Cooked post: " + post.cooked);
  });
  
  </script>

```

Steps to reproduce:

1. Create theme component with code as shown above.

2. Create a new post, do not refresh, click the calendar icon.

3. See the alert pop-ups.  

4. Refresh the page. Click on the calendar button again for the same post.  

5. Now the post only has the cooked content available, raw content is not getting through.

I hope anyone can either spot my failure or confirm the bug 🙂

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 17, 2019, 2:05am UTC](https://meta.discourse.org/t/retrieving-post-raw-only-works-right-after-creating-post/115267/2 "2019-04-17T02:05:28Z")

</div>

This is by design, we prefer to keep our topic payload smaller so if you need raw you have to ask for it on-demand.

Otherwise we would be shipping data to all clients that they do not need the vast majority of the time.

---

<div class="post-metadata">

### Author: ![Mathijs\_V](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mathijs_v/32/135133_2.png) [@Mathijs\_V](https://meta.discourse.org/u/Mathijs_V)
#### Post date: [April 17, 2019, 7:18am UTC](https://meta.discourse.org/t/retrieving-post-raw-only-works-right-after-creating-post/115267/3 "2019-04-17T07:18:51Z")

</div>

Thanks for your reply! Now I can stop wasting time 🙂

> [@sam](#):
>
> we prefer to keep our topic payload smaller

Ahh that makes so much sense!

> [@sam](#):
>
> ask for it on-demand

Could you point me in the right direction to retrieve post data from javascript?  
I had a sort of workaround to get the .json by retrieving the /t/raw/{topicid}/{postid}.json but that was really ugly and there must be a better way.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 17, 2019, 7:38am UTC](https://meta.discourse.org/t/retrieving-post-raw-only-works-right-after-creating-post/115267/4 "2019-04-17T07:38:52Z")

</div>

> [@Mathijs\_V](#):
>
> I had a sort of workaround to get the .json by retrieving the /t/raw/{topicid}/{postid}.json but that was really ugly and there must be a better way.

Yeah that is pretty much your only option.

---

<div class="post-metadata">

### Author: ![Mathijs\_V](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mathijs_v/32/135133_2.png) [@Mathijs\_V](https://meta.discourse.org/u/Mathijs_V)
#### Post date: [April 17, 2019, 7:59am UTC](https://meta.discourse.org/t/retrieving-post-raw-only-works-right-after-creating-post/115267/5 "2019-04-17T07:59:31Z")

</div>

Thank you. I will make my workaround less ugly and post it here when finished!

---

<div class="post-metadata">

### Author: ![paresy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paresy/32/96471_2.png) [@paresy](https://meta.discourse.org/u/paresy)
#### Post date: [February 9, 2021, 1:19pm UTC](https://meta.discourse.org/t/retrieving-post-raw-only-works-right-after-creating-post/115267/6 "2021-02-09T13:19:37Z")

</div>

Is this still true? When editing a post the request is to e.g. /posts/13.json

Is there any JS API for that? Or any JS API for making an authenticated request?

@Mathijs_V Would you share your code?

Thanks!

---

<div class="post-metadata">

### Author: ![paresy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paresy/32/96471_2.png) [@paresy](https://meta.discourse.org/u/paresy)
#### Post date: [February 9, 2021, 10:05pm UTC](https://meta.discourse.org/t/retrieving-post-raw-only-works-right-after-creating-post/115267/7 "2021-02-09T22:05:41Z")

</div>

That’s how i did it at the moment:

```plaintext
import {ajax} from "discourse/lib/ajax";

...

let post = this.findAncestorModel();
ajax(`/posts/${post.id}`, { type: "GET", cache: false }).then(
  (result) => {
    console.log(result.raw);
  }
);

```

Taken from here: [discourse-checklist/assets/javascripts/discourse/initializers/checklist.js.es6 at a94022393c1fd290e492688041896d4392129052 · discourse/discourse-checklist · GitHub](https://github.com/discourse/discourse-checklist/blob/a94022393c1fd290e492688041896d4392129052/assets/javascripts/discourse/initializers/checklist.js.es6#L39)
