breart / atlassian-connect-core

[Laravel 5.5+] The easiest way to create an add-on for the JIRA and Confluence
https://packalyst.com/packages/package/brezzhnev/atlassian-connect-core
MIT License
41 stars 32 forks source link

Unauthorized (401) #6

Closed deadmerc closed 6 years ago

deadmerc commented 6 years ago

Hi, have trouble, with secure request. I am using $client = new JWTClient(Auth::user()); dump($client->post('/rest/api/2/search'.urlencode('?jql=updated > 2014-01-20 and project in (PC) and timespent > 0&fields=summary,worklog&maxResults=1000'))); I got 401, can you please help me with it? Interesting, what dump($client->get('/rest/api/2/issue/TEST-13')); works perfectly, problem in jira permissions?

breart commented 6 years ago

Hi @DeadMerc,

That's because you're trying to pass query parameters to URL, you should use the parameter $config instead:

$client = new JWTClient(Auth::user());
$client->post('rest/api/2/search', [], [
    'query' => [
        'jql' => 'updated > 2014-01-20 and project in (PC) and timespent > 0',
        'fields' => 'summary,worklog',
        'maxResults' => '1000'
    ]
]);

You can see all the available options at Guzzle HTTP documentation.

Btw, the same issue: https://github.com/brezzhnev/atlassian-connect-core/issues/4

deadmerc commented 6 years ago

Thanks for fast response @brezzhnev , but it not working Your example return Unrecognized field "query" (Class com.atlassian.jira.rest.v2.search.SearchRequestBean), not marked as ignorable Tried without query Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token This request have GET method, it not working too.

breart commented 6 years ago

@DeadMerc when I using GET method it also doesn't work for me, strange.

You could try this, it works for me:

$client = new JWTClient(Auth::user());
$response = $client->post('rest/api/2/search', [
    'jql' => 'updated > 2014-01-20 and project in (PC) and timespent > 0',
    'fields' => ['summary', 'worklog'],
    'maxResults' => '1000'
]);

Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token

This error was due to fields parameter. When you're performing POST request, you should use an array instead of the string with commas.