Three questions about Posting API

Hello. I have three questions about posting API.

1. Can you assign multiple categories to a post?

Let’s assume I have two categories implemented on my personal blog, named “First” and Second".

I write and execute this code on my personal blog:

token = "..."
headers ={
  "content-type": "application/x-www-form-urlencoded; charset=utf-8", 
  "Authorization": f"Bearer {token}"}

sent = requests.post(
    url="https://micro.blog/micropub?q=source",
    headers=headers,
    data={
        "h": "entry",
        "content": "Hello world",
        "category": ['First', 'Second']
    }
)

And it works. BUT, the published post will appear belonging only to the first category, and not to the second category.

Please, could you explain me what am I doing wrong?


2. Is it possible to query Micro.blog for a list of the existing blog categories?

I tried to send a GET request to /micropub?q=query with this code:

sent = requests.get(
    url="https://micro.blog/micropub?q=config",
    headers=headers,
)

But I didn’t find a list of categories that I can apply to my posts, on the JSON object that was returned by the server.

Is there an endpoint I can send a GET request, to query for a list of the existing categories for my personal blog?


3. Is it possible to ask the Posting API to assign my new post a specific slug ?

If I send a POST request to the posting API, Micro.blog will create a new post and assigns it a permalink of its own accord.
Sometimes it’s apparently the time of the day or a serial number, for example: https://cesco.micro.blog/2023/05/24/175730.html

I’d rather be the one to suggest to micro.blog a slug suitable for my post.
I’d like to be able to post a new message and suggest a slug as in this (imaginary) piece of code:

token = "..."
headers ={
  "content-type": "application/x-www-form-urlencoded; charset=utf-8", 
  "Authorization": f"Bearer {token}"}

sent = requests.post(
    url="https://micro.blog/micropub?q=source",
    headers=headers,
    data={
        "h": "entry",
        "content": "Hello world",
        "slug": "my-hello-world"
    }
)

Micro.blog would try to implement my requested slug, and if that would not be possible (for example, because there are two posts sharing the same slug) it would return me an error code back and tell me that my requested slug can not be used.

Otherwise, it would publish my post with my requested permalink. For example:
https://cesco.micro.blog/2023/05/24/my-hello-world

Is this behavior doable now, or may be considered as a feature for the next future?

Many thanks for your replies. Cheers

The first two are definitely possible, because MarsEdit supports both, though I think that MarsEdit uses MetaWeblog and not Micropub. I’m not sure if Micropub or the implementation of that is at issue here.

The third is not possible today, because Micro.blog broadly does not support setting custom slugs or URL formats. Posts without a title are timestamped, those with a title have the title shortened (not sure about truncation rules) and all posts go to /:year/:month/:day/{title}.html. Custom slugs and custom formats for slugs has been requested before.

1 Like

Thank you for your clarification.
You’re right, the correct word is slug and not permalink.

As @jsonbecker said, #3 isn’t possible yet. We are going to be adding this. You might also see those date slugs if the default title has been used already for today’s date.

For #1: Yes, when sending as form-encoded values, multiple categories look like this with []:

content=Hello&category[]=First&category[]=Second

Might depend on your HTTP library if there’s a convenient way to take an array and make that, or if you’ll need to create the request data in that format.

For #2: Yes, it’s a separate parameter like this:

https://micro.blog/micropub?q=category
1 Like

Thank you very much @manton
I’m still trying to get multiple categories right, but I’m glad to hear that #2 is a piece of cake and #3 will be implemented :heart_eyes:

You may want to hit the :heart: in Pete’s request here.

1 Like

Done! Thanks for suggesting the link.

@manton this might be a rare use case for Micro.blog, but automated generation of slugs doesn’t work for non-Latin languages, so custom slugs would be great.

There’s a “hack” as you can set an English title and replace it right after, but it’s not exactly convenient.

1 Like

You’re right, that is something we need to address.

1 Like