Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can't access to rest api with curl php

Mikael Boutin October 3, 2012

Hi, i try to get the rest api responses with Curl in php, but i can't authenticate...

$username = '****';
$password = '****';
 
$url = 'https://****.onjira.com/rest/api/2.0.alpha1/issue/COU-1432?expand=changelog';
$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0';

$curl = curl_init();
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
print_r(curl_exec($curl));

It always return me: {"errorMessages":["Vous n'avez pas l'autorisation de voir la demande indiquée","Connexion requise"],"errors":{}}

How can i get the json code in this url?

Thank you for your help

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 4, 2012

I've got a slightly simpler version working nicely:

<?php
  $json = `curl -u username:password https://jira.atlassian.com/rest/api/latest/issue/JRA-9.json`;
  echo $json;

See also: The Simplest Possible JIRA REST Examples

TAGS
AUG Leaders

Atlassian Community Events