{"action":"created","issue":{"url":"https://api.github.com/repos/Valandur/Web-API/issues/64","repository_url":"https://api.github.com/repos/Valandur/Web-API","labels_url":"https://api.github.com/repos/Valandur/Web-API/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/Valandur/Web-API/issues/64/comments","events_url":"https://api.github.com/repos/Valandur/Web-API/issues/64/events","html_url":"https://github.com/Valandur/Web-API/issues/64","id":305250396,"number":64,"title":"Can't POST Request to API Server Plugin","user":{"login":"pdglobal","id":36902779,"avatar_url":"https://avatars3.githubusercontent.com/u/36902779?v=4","gravatar_id":"","url":"https://api.github.com/users/pdglobal","html_url":"https://github.com/pdglobal","followers_url":"https://api.github.com/users/pdglobal/followers","following_url":"https://api.github.com/users/pdglobal/following{/other_user}","gists_url":"https://api.github.com/users/pdglobal/gists{/gist_id}","starred_url":"https://api.github.com/users/pdglobal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdglobal/subscriptions","organizations_url":"https://api.github.com/users/pdglobal/orgs","repos_url":"https://api.github.com/users/pdglobal/repos","events_url":"https://api.github.com/users/pdglobal/events{/privacy}","received_events_url":"https://api.github.com/users/pdglobal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-14T17:10:30Z","updated_at":"2018-03-15T01:47:01Z","closed_at":null,"author_association":"NONE","body":"Please help, I am trying to send a POST request to the API to execute the command:\r\n\r\n\"broadcast test message\"\r\n\r\nSee my simple php code below, It's authenticating but returning the following error:\r\n\r\n> {\"code\":400,\"message\":\"Invalid command data: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token\\n at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: valandur.webapi.serialize.request.command.ExecuteCommandRequest[\\\"command\\\"])\"}\r\n\r\nCode:\r\n```\r\n<?PHP\r\n_postdata('http://127.0.0.1:8080/api/cmd', array(\"command\" => \"broadcast test message\"), array('x-webapi-key: HIDDEN))\r\nfunction _postdata($url, $data, $header) {\r\n    $curl = curl_init($url);\r\n\tcurl_setopt($curl,CURLOPT_HTTPHEADER, $header);\r\n    curl_setopt($curl, CURLOPT_POST, true);\r\n    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));\r\n    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);\r\n    $response = curl_exec($curl);\r\n    curl_close($curl);\r\n    return $data.'=>'.$response;\r\n}\r\n?>\r\n```\r\n\r\nPlease help, it would only take a moment of your time and would help me greatly."},"comment":{"url":"https://api.github.com/repos/Valandur/Web-API/issues/comments/373232761","html_url":"https://github.com/Valandur/Web-API/issues/64#issuecomment-373232761","issue_url":"https://api.github.com/repos/Valandur/Web-API/issues/64","id":373232761,"user":{"login":"Valandur","id":1572366,"avatar_url":"https://avatars3.githubusercontent.com/u/1572366?v=4","gravatar_id":"","url":"https://api.github.com/users/Valandur","html_url":"https://github.com/Valandur","followers_url":"https://api.github.com/users/Valandur/followers","following_url":"https://api.github.com/users/Valandur/following{/other_user}","gists_url":"https://api.github.com/users/Valandur/gists{/gist_id}","starred_url":"https://api.github.com/users/Valandur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Valandur/subscriptions","organizations_url":"https://api.github.com/users/Valandur/orgs","repos_url":"https://api.github.com/users/Valandur/repos","events_url":"https://api.github.com/users/Valandur/events{/privacy}","received_events_url":"https://api.github.com/users/Valandur/received_events","type":"User","site_admin":false},"created_at":"2018-03-15T01:47:01Z","updated_at":"2018-03-15T01:47:01Z","author_association":"OWNER","body":"Hi :) If you're looking for support and quick replies you're usually better off on [discord](https://discord.gg/ReTHwNE) or the Sponge forums, Github is meant for issues.\r\n\r\nConcerning this issue - This actually seems to be a bug, or rather an inconsistency.\r\nAs a quick fix I would recommend you change your code to the following:\r\n```php\r\n<?PHP\r\n_postdata('http://127.0.0.1:8080/api/cmd', array(\"command\" => \"broadcast test message\"), array('x-webapi-key: HIDDEN'));\r\nfunction _postdata($url, $data, $header) {\r\n\t$header[] = 'Content-Type: application/json';\r\n\t$curl = curl_init($url);\r\n\tcurl_setopt($curl,CURLOPT_HTTPHEADER, $header);\r\n\tcurl_setopt($curl, CURLOPT_POST, true);\r\n\tcurl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));\r\n\tcurl_setopt($curl, CURLOPT_RETURNTRANSFER, true);\r\n\t$response = curl_exec($curl);\r\n\tcurl_close($curl);\r\n\treturn $data.'=>'.$response;\r\n}\r\n```\r\n> **$header[] = 'Content-Type: application/json';**  \r\n\r\nmakes sure that the request is understood as json by the server and  \r\n\r\n> curl_setopt($curl, CURLOPT_POSTFIELDS, **json_encode($data)**);\r\n\r\nsends the request as a json request"}}
{"actor":{"display_login":"Valandur"}}