Skip to content

Micropub post request incorrectly sends array items in JSON body #92

@paulrobertlloyd

Description

@paulrobertlloyd

In creating a post with 2 categories and 1 syndication target, using category and mp-syndicate-to which accept arrays, I see the following in the POST request:

{
  "h": "entry",
  "content": "Test.",
  "post-status": "published",
  "category[]": ["test", "testing"],
  "mp-destination": "https://indiekit-sandbox.netlify.app",
  "mp-syndicate-to[]": "https://mastodon.social/@indiekit_sandbox"
}

Note the array property keys include [], when they should not.

If I’m understanding this right, this might be confusing how application/json body is sent versus how the same information is sent using application/x-www-form-urlencoded.

An array should be provided in JSON as follows:

{
  "h": "entry",
  "content": "hello world",
  "category": ["foo", "bar"],
}

Only when form encoding arrays do multiple values get appended with [], meaning the above would be represented as:

h=entry&content=hello+world&category[]=foo&category[]=bar

This is as documented in the Micropub spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions