Hi,
I'm trying to create new discussions in our flarum (v1.2.0) via REST-api. It looks as if I'm able to read existing discussions via GET request to /api/discussions
However, I can't find any documentation on what to send to the api/discussions
resource, besides the accepted method (POST).
Now if I try to send a json with 'data' array: I get back a 500 error.
curl -X POST -v -H "${authHeader}" ${flBase}/discussions -H "Content-Type: application/json" -d "${writeJson}"
my payload looks like this
{
"data": [
{
"type": "posts",
"attributes": {
"number": 1,
"title": "api writer",
"createdAt": "2020-03-09T14:35:59+00:00",
"contentType": "comment",
"contentHtml": "hi from API",
}
}
]
}
In the flarum logs I get this output:
[2022-01-28 15:26:14] flarum.ERROR: TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in vendor/flarum/subscriptions/src/Listener/SaveSubscriptionToDatabase.php:21
Stack trace:
vendor/flarum/subscriptions/src/Listener/SaveSubscriptionToDatabase.php(21): array_key_exists('subscription', NULL)
vendor/illuminate/events/Dispatcher.php(424): Flarum\Subscriptions\Listener\SaveSubscriptionToDatabase->handle(Object(Flarum\Discussion\Event\Saving))
vendor/illuminate/events/Dispatcher.php(249): Illuminate\Events\Dispatcher->Illuminate\Events\{closure}('Flarum\\Discussi...', Array)
vendor/flarum/core/src/Discussion/Command/StartDiscussionHandler.php(71): Illuminate\Events\Dispatcher->dispatch('Flarum\\Discussi...')
vendor/illuminate/bus/Dispatcher.php(122): Flarum\Discussion\Command\StartDiscussionHandler->handle(Object(Flarum\Discussion\Command\StartDiscussion))
vendor/illuminate/pipeline/Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Flarum\Discussion\Command\StartDiscussion))
vendor/illuminate/pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Flarum\Discussion\Command\StartDiscussion))
vendor/illuminate/bus/Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then(Object(Closure))
vendor/illuminate/bus/Dispatcher.php(78): Illuminate\Bus\Dispatcher->dispatchNow(Object(Flarum\Discussion\Command\StartDiscussion))
vendor/flarum/core/src/Api/Controller/CreateDiscussionController.php(62): Illuminate\Bus\Dispatcher->dispatch(Object(Flarum\Discussion\Command\StartDiscussion))
/vendor/flarum/core/src/Api/Controller/AbstractSerializeController.php(115): Flarum\Api\Controller\CreateDiscussionController->data(Object(Laminas\Diactoros\ServerRequest), Object(Tobscure\JsonApi\Document))
/vendor/flarum/core/src/Api/Controller/AbstractCreateController.php(22): Flarum\Api\Controller\AbstractSerializeController->handle(Object(Laminas\Diactoros\ServerRequest))
/vendor/flarum/core/src/Http/RouteHandlerFactory.php(41): Flarum\Api\Controller\AbstractCreateController->handle(Object(Laminas\Diactoros\ServerRequest))
/vendor/flarum/core/src/Http/Middleware/ExecuteRoute.php(27): Flarum\Http\RouteHandlerFactory->Flarum\Http\{closure}(Object(Laminas\Diactoros\ServerRequest), Array)
/vendor/laminas/laminas-stratigility/src/Next.php(51): Flarum\Http\Middleware\ExecuteRoute->process(Object(Laminas\Diactoros\ServerRequest), Object(Closure))
/vendor/flarum/core/src/Api/Middleware/ThrottleApi.php(33): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
/vendor/laminas/laminas-stratigility/src/Next.php(51): Flarum\Api\Middleware\ThrottleApi->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
/vendor/flarum/core/src/Http/Middleware/CheckCsrfToken.php(40): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
/vendor/laminas/laminas-stratigility/src/Next.php(51): Flarum\Http\Middleware\CheckCsrfToken->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
/vendor/flarum/core/src/Http/Middleware/ResolveRoute.php(67): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
/vendor/laminas/laminas-stratigility/src/Next.php(51): Flarum\Http\Middleware\ResolveRoute->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
/vendor/flarum/core/src/Http/Middleware/SetLocale.php(51): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
/vendor/laminas/laminas-stratigility/src/Next.php(51): Flarum\Http\Middleware\SetLocale->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
/vendor/flarum/core/src/Http/Middleware/AuthenticateWithHeader.php(58): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
/vendor/laminas/laminas-stratigility/src/Next.php(51): Flarum\Http\Middleware\AuthenticateWithHeader->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
Do you have any hints or docs on a valid payload to start a new discussion without errors?