get specific data from REST API

Asked at 2017-01-11 22:09:27Z
  • 5 Subscribers
  • 114 Views
0

I want to get specific data from rest api after user login using cookie auth but I end up with Field 'fieldname' does not exist or this field cannot be viewed by anonymous users.

Below you can see the code I wrote in ajax and php to get data. I know my script is probably awful as I used curl request for the first time so bear with me, I want someone to tell me where I am doing wrong or better explain to me how to get and post data to server with curl and get and specific data display would be appreciated.

$('#user-profile').click(function(){
        $.ajax({
            type: "POST",
            url: "jiraticket.php",
            data: $('#login-form').serialize(),
            success: function(data){
                alert(data);
            }
        });
    });

and here is the script

    <?php
session_start();


  $url = 'http://base-url/rest/api/2/search?jql=issuetype%20=%20Epic%20AND%20status%20in%20(%22In%20Progress%22,%20Backlog,%20%22On%20hold%22,%20%22To%20Do%22)';
  $curl_session = curl_init($url);
  curl_setopt($curl_session, CURLOPT_HEADER, 0);
  curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);

    if(isset($_COOKIE['JSESSIONID']))
    $cookie_string='JSESSIONID='.$_COOKIE['JSESSIONID'];
    else
    $cookie_string="";



    curl_setopt($curl_session, CURLOPT_HTTPHEADER, array('Content-Type: application/json' ,'Authorization: Cookie'), array('cookie:'.$cookie_string));

   $response = curl_exec($curl_session);

   curl_close($curl_session);



   if ( !$response ) {
       die('Nothing was returned.');
   }


   $result = json_decode($response, true);

   print_r($result);

1 answers in total

0
Boris K Posted at 2017-01-11 22:34:24Z

$response printing "errorMessages":["Field 'issuetype' does not exist or this field cannot be viewed by anonymous users."]

Well, it means the API does not want to give you the value of issuetype.

Might be a typo or something, but that's not an error with your curl call, it's a problem with the API provider

Answer this questsion