Creating Comments returns a `required key not provided` error
When trying to create a comment to an issue, I get a required key not provided
error, I found somewhere that sending the content-type/application-json
would fix it, but then a bad request
error is thrown
Comments (4)
-
reporter -
At some point in the past, HTTP Client methods with a
request<Action>
format were calling the old and now defunct API v1. In the meantime that changed, but the methods were kept solely as a BC and they are still there because I didn’t had the time to update this library. They will be removed in the next major version.Until a new version of this library will be released, you can create a comment to an issue something like this:
<?php $comment = new \Bitbucket\API\Repositories\Issues\Comments(); $comment->getClient()->addListener( new \Bitbucket\API\Http\Listener\OAuth2Listener($oauth_params) )->setApiVersion('2.0'); $response = $comment->getClient()->post( sprintf('repositories/%s/%s/issues/%d/comments/', $account_name, $repo_slug, $issue_id), json_encode(array('content' => array('raw' => 'My comment'))), array('Content-Type' => 'application/json')) ;
-
- changed status to wontfix
-
reporter Makes sense, however just note that it happens in all post/put methods that need a json tought,
that’s why I updated there requestPost and requestPut :D, I created a fork now with that so I can easily use until the next version is released,
if you need any help just let me know
- Log in to comment
Ok, found how to fix it, wanted to create a PR but looks like I can’t
The fix is basically adding the content type
application/json
in both post and get,
in
Api.php
public function requestPost($endpoint, $params = array(), $headers = ['Content-Type' => 'application/json'])
And
public function requestPut($endpoint, $params = array(), , $headers = ["Content-Type" => "application/json"])
And then, just handle it in
Http\Client.php
the
public function request($endpoint, $params = array(), $method = 'GET', array $headers = array())
function update the if(is_array($params)
section