Misskey: Note Create Api Usage Causes Error: invalid JSON, only supports object and array

Created on 24 Dec 2018  ·  7Comments  ·  Source: syuilo/misskey

Summary


Using the note create api endpoint results in Error: invalid JSON, only supports object and array on the server side.

the request as received by netcat is as follows:

POST /api/notes/create HTTP/1.1
user-agent: reqwest/0.9.5
accept: */*
content-type: application/x-www-form-urlencoded
content-length: 295
accept-encoding: gzip
host: localhost:2389

i=%<removed>&visibility=private&text=Petit+Trees+%28sketch%29.+2+%0Ahttps%3A%2F%2Fimgs.xkcd.com%2Fcomics%2Ftree_cropped_%281%29.jpg+%0A%27Petit%27+being+a+reference+to+Le+Petit+Prince%2C+which+I+only+thought+about+halfway+through+the+sketch+%0Ahttps%3A%2F%2Fxkcd.com%2F2%

if using json rather that form encoding, nothing happens at all.
same thing occurs both without any visibility parameter and when the text is just simply the word "text"

here is the request and response as seen by the client:

Request { method: POST, url: "https://boopsnoot.gq/api/notes/create", headers: {"content-type": "application/x-www-form-urlencoded"} }
Response { url: "https://boopsnoot.gq/api/notes/create", status: 400, headers: {"server": "nginx/1.12.2", "date": "Mon, 24 Dec 2018 09:11:57 GMT", "content-type": "text/plain; charset=utf-8", "content-length": "11", "connection": "keep-alive"} }

Expected Behavior


Note created and no error

Actual Behavior

Error: invalid JSON, only supports object and array
at parse (/home/misskey/misskey/node_modules/co-body/lib/json.js:55:13)
at AsyncFunction.module.exports [as json] (/home/misskey/misskey/node_modules/co-body/lib/json.js:41:20)
at process._tickCallback (internal/process/next_tick.js:68:7)

Steps to Reproduce

  1. Post to https://boopsnoot.gq/api/notes/create


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Most helpful comment

I don't know why misskey doesn't support url encoded forms, so I created a patch for supporting it.

All 7 comments

Please use application/json instead of application/x-www-form-urlencoded.

When doing so I get nothing in the server log and the following on the client side:

Request { method: POST, url: "https://boopsnoot.gq/api/notes/create", headers: {"content-type": "application/json"} }
Response { url: "https://boopsnoot.gq/api/notes/create", status: 400, headers: {"server": "nginx/1.12.2", "date": "Mon, 24 Dec 2018 09:22:58 GMT", "content-type": "application/json; charset=utf-8", "content-length": "31", "connection": "keep-alive", "vary": "Accept-Encoding, Origin", "strict-transport-security": "max-age=15552000; preload", "cache-control": "private, max-age=0, must-revalidate"} }

Hmm, I can't see the overall of this problem yet.
BTW, you are using reqwest in Rust, right?
Please show me the client codes if you don't mind me seeing.

Thats right, heres the misskey client section:

        let misskey_parems = [
            ("i", &api.misskey_key),
            ("visibility", &String::from("private")),
            ("text", &String::from("status")),
        ];

        let client = reqwest::Client::new()
            .post(&api.misskey_url.to_string())
            .json(&misskey_parems);

        let request = reqwest::Client::new()
            .post(&api.misskey_url.to_string())
            .json(&misskey_parems)
            .build()
            .unwrap();

        println!("{:?}", request);

        match client.send() {
            Ok(o) => println!("{:?}", o),
            Err(e) => println!("{:?}", e),
        };

Thank you!
Can you retry with these codes?

use std::collections::HashMap;

\~\~\~

        let mut misskey_params = HashMap::new();
        misskey_params.insert("i", &api.misskey_key);
        misskey_params.insert("visibility", &String::from("private"));
        misskey_params.insert("text", &String::from("status"));

        let client = reqwest::Client::new()
            .post(&api.misskey_url.to_string())
            .json(&misskey_params);

        let request = reqwest::Client::new()
            .post(&api.misskey_url.to_string())
            .json(&misskey_params)
            .build()
            .unwrap();

        println!("{:?}", request);

        match client.send() {
            Ok(o) => println!("{:?}", o),
            Err(e) => println!("{:?}", e),
        };

that seems to work
odd

any reason why misskey doesnt support url encoded forms?

I don't know why misskey doesn't support url encoded forms, so I created a patch for supporting it.

Was this page helpful?
0 / 5 - 0 ratings