# Discourse Drafts api Not working

**URL:** https://meta.discourse.org/t/discourse-drafts-api-not-working/265036
**Category:** Development
**Tags:** rest-api
**Created:** [May 15, 2023, 10:23am UTC](https://meta.discourse.org/t/discourse-drafts-api-not-working/265036 "2023-05-15T10:23:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fahadaslam98](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fahadaslam98/32/299547_2.png) [@fahadaslam98](https://meta.discourse.org/u/fahadaslam98)
#### Post date: [May 15, 2023, 10:23am UTC](https://meta.discourse.org/t/discourse-drafts-api-not-working/265036/1 "2023-05-15T10:23:12Z")

</div>

I am facing an issue while implementing the drafts API using spring boot. All the APIs are working but this one API is giving me a tough time and I am unable to understand the issue.

Has anyone implemented this and could guide me through the issue? I am putting the error that I am able to catch into the exception:

```plaintext
2023-05-15 15:09:44.310 ERROR 880 --- [nio-5000-exec-1] c.b.c.e.advice.ExceptionHandlerAdvice : ** Exception Leaked & captured : JsonParseException; Unrecognized token 'Optional': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"Optional[java.nio.HeapByteBuffer[pos=0 lim=16187 cap=16187]]"; line: 1, column: 9]
2023-05-15 15:09:44.315 DEBUG 880 --- [nio-5000-exec-1] s.s.w.c.SecurityContextPersistenceFilter : Cleared SecurityContextHolder to complete request
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Optional': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

```

Here is the payload as well and URL “/drafts.json”:

```plaintext
{
    "draft_key": "new_topic",
    "sequence": 94,
    "data": {
        "reply": "estaetwetweas sfasdf asdfa sdf as ",
        "action": "createTopic",
        "title": "test test test",
        "categoryId": 5,
        "archetypeId": "regular",
        "metaData": null,
        "composerTime": 19025,
        "typingTime": 4800
    }
}

```

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [May 15, 2023, 11:11am UTC](https://meta.discourse.org/t/discourse-drafts-api-not-working/265036/2 "2023-05-15T11:11:13Z")

</div>

I like to fiddle a bit with the API and had a quick look, but Insomnia returns an error 500. 😖

I use an admin API key and the following payload on Insomnia with a POST request on /drafts.json:

```json
{
  "draft_key": "new_topic",
  "sequence": 181,
  "data": {
    "reply": "test draft",
    "action": "createTopic",
    "title": "Here's a draft topic again",
    "categoryId": 4,
    "archetypeId": "regular",
    "metaData": null,
    "composerTime": 11311,
    "typingTime": 3200
  },
  "owner": "fa8073ea509544319371333121ca878e",
  "force_save": false
}

```

I got the same error 500 if I make a “reply” draft request.

Sorry I can’t be of some help, but I now wonder why it doesn’t work as well. 🧑‍💻 ❔

---

<div class="post-metadata">

### Author: ![fahadaslam98](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fahadaslam98/32/299547_2.png) [@fahadaslam98](https://meta.discourse.org/u/fahadaslam98)
#### Post date: [May 15, 2023, 11:15am UTC](https://meta.discourse.org/t/discourse-drafts-api-not-working/265036/3 "2023-05-15T11:15:24Z")

</div>

I would surely update the solution here. thanks for trying out and if you are able to fix it sooner then me please update here so that I can benefit from your effort as well

---

<div class="post-metadata">

### Author: ![ludomori99](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ludomori99/32/364432_2.png) [@ludomori99](https://meta.discourse.org/u/ludomori99)
#### Post date: [February 20, 2024, 11:03am UTC](https://meta.discourse.org/t/discourse-drafts-api-not-working/265036/5 "2024-02-20T11:03:11Z")

</div>

Hello folks, just adding to the thread that I encountered the precise same issue (tried to post to draft.json with same reverse-engineered payload) and wondered if you had found a solution or a workaround to write drafts to posts via api. Thanks!
