Discourse Drafts api Not working

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:

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”:

{
    "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
    }
}
1 Like

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

I use an admin API key and the following payload on Insomnia with a POST request on /drafts.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. :technologist: :grey_question:

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

1 Like

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!