tumblr / docs

Tumblr's public platform documentation.
Apache License 2.0
108 stars 26 forks source link

`formatting` and `indent_level` don't seem to work like documented #103

Closed annando closed 1 year ago

annando commented 1 year ago

I'm trying to post to blog/(page)/posts. It seem to work - but only if I do not include formatting or indent_level. So then I tried the examples in the documentation.

I transmitted this to the endpoint:

{
    "content": [
        {
            "type": "text",
            "text": "supercalifragilisticexpialidocious",
            "formatting": [
                {
                    "start": 0,
                    "end": 20,
                    "type": "bold"
                },
                {
                    "start": 9,
                    "end": 34,
                    "type": "italic"
                }
            ]
        }
    ]
}

There I got this as return value:

stdClass Object
(
    [meta] => stdClass Object
        (
            [status] => 400
            [msg] => Bad Request
        )

    [response] => Array
        (
        )

    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [title] => Bad Request
                    [code] => 0
                    [detail] => Minor hiccup. Try again.
                )

            [1] => stdClass Object
                (
                    [title] => Bad Request
                    [code] => 0
                    [detail] => Minor hiccup. Try again.
                )

            [2] => stdClass Object
                (
                    [title] => Bad Request
                    [code] => 0
                    [detail] => Minor hiccup. Try again.
                )

            [3] => stdClass Object
                (
                    [title] => Bad Request
                    [code] => 0
                    [detail] => Minor hiccup. Try again.
                )
        )
)

It works when I transmit this:

{
    "content": [
        {
            "type": "text",
            "text": "supercalifragilisticexpialidocious"
        }
    ]
}

Then get this in return:

stdClass Object
(
    [meta] => stdClass Object
        (
            [status] => 201
            [msg] => Created
        )

    [response] => stdClass Object
        (
            [id] => ...
            [state] => published
            [display_text] => Posted to ...
        )
) 

Same goes with the indent_level.

I send this:

{
    "content": [
        {
            "type": "text",
            "subtype": "indented",
            "text": "1: blockquote, not nested"
        },
        {
            "type": "text",
            "subtype": "indented",
            "text": "2: blockquote, nested",
            "indent_level": 1
        },
        {
            "type": "text",
            "subtype": "unordered-list-item",
            "text": "3: nested in two blockquotes",
            "indent_level": 2
        },
        {
            "type": "text",
            "subtype": "ordered-list-item",
            "text": "4: nested in two blockquotes and a list",
            "indent_level": 3
        },
        {
            "type": "text",
            "subtype": "unordered-list-item",
            "text": "3: back to level 3, double nesting",
            "indent_level": 2
        },
        {
            "type": "text",
            "subtype": "indented",
            "text": "1: back to level 1, no nesting"
        }
    ]
}

I receive this:

stdClass Object
(
    [meta] => stdClass Object
        (
            [status] => 400
            [msg] => Bad Request
        )

    [response] => Array
        (
        )

    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [title] => Bad Request
                    [code] => 0
                    [detail] => Something flubbed. Try again.
                )

            [1] => stdClass Object
                (
                    [title] => Bad Request
                    [code] => 0
                    [detail] => Something flubbed. Try again.
                )

            [2] => stdClass Object
                (
                    [title] => Bad Request
                    [code] => 0
                    [detail] => Something flubbed. Try again.
                )

            [3] => stdClass Object
                (
                    [title] => Bad Request
                    [code] => 0
                    [detail] => Something flubbed. Try again.
                )
        )
)

I'm using an ancient PHP library to post this that derived from this it seems: https://github.com/fooyeahcode/tumblroauth

Since the posting in NPF does work when I omit formatting or indent_level this shouldn't matter, shouldn't it?

I guess I'm missing something here, but I should have studied the API documentation deep enough, I think.

cyle commented 1 year ago

Hello @annando ! I'm sorry you're having this issue. The NPF JSON here is valid, and I can confirm it works when creating posts for my test account using my own API consumer. The issue must be with that library you're using -- my hunch would be that it's encoding something incorrectly? I'm not sure, but I'd recommend trying an API client like Postman or cURL to test these requests, and see if you get the same issue.

annando commented 1 year ago

Yeah, I can confirm that it is caused by my used library. I now experimented with Guzzle and I was able to post. Thanks for the hint!