0

I created a plug-in that retrieves data from an api(at least tries to!). This is the code of the function.

function call_back(){

     
$apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$response = wp_remote_get ('http://mysite.atlassian.net/rest/api/3/issue/LD-1',$args);
$args = array(

    'headers' => array(
      'Content-Type' => 'application/json',
      'Authorization' => 'Basic ', $apiKey,
    )
);


echo '<pre>';
var_dump(wp_remote_retrieve_body($response));
echo '</pre>';
};

The api key that i use works, used it in postman. But the problem i get is that in WP i get:

"string(95) "{"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}""

I do have permission and the issue does exist, the problem is with authentication. For some reason i don't get access. Any idea on why?

2
  • 3
    You have to declare $args first
    – fuxia
    Commented Jul 29, 2020 at 15:46
  • What do you mean? Putting $args above the response?
    – Thinsanta
    Commented Jul 30, 2020 at 10:13

1 Answer 1

1

Thank you that helped me alot! But there was one more problem and that was the "'Authorization' => 'Basic ', $apiKey," part. I just needed a dot before $apiKey. Thanks again for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.