0

The following URL is from the FobBugz API documentation: https://kakapo.fogbugz.com/api.asp?cmd=search&q=project:inbox%20assignedTo:Elinor&cols=ixProject,ixPersonAssignedTo,sTitle&max=2&token=04t9123822q4kbba09nt740inhibk2 (you can find it here)

If I copy and paste the above URL into a web browser I get an XML response. What I would like to do is create a function that returns the XML response as a its result.

I am so stuck, it is simply not working. All I seem to get in response is an empty string. When I use this 'example' on the FogBugz site I get XML telling me that I am NOT logged in.

The function below comes mostly from here: Make a HTTPS request through PHP and get response I have been messing with it for hours without success.

function searchBug(){

$data =  "https://kakapo.fogbugz.com/api.asp?cmd=search&q=project:inbox%20assignedTo:Elinor&cols=ixProject,ixPersonAssignedTo,sTitle&max=2&token=04t9123822q4kbba09nt740inhibk2"; 
    //echo $data;
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, False);
    $result = curl_exec($ch);
    curl_close($ch);
    echo $result;
}

[EDIT: in response to comment] The response that I want to receive is:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<response>
<error code="3">
<![CDATA[ Not logged in ]]>
</error>
</response>

As that is what is shown in my browser when I paste the URL and press enter.

13
  • And what do you want to receive? Commented May 8, 2017 at 11:06
  • Well, the error is allready show, you are simply just not logged in, you probaly need to make a login call first. Commented May 8, 2017 at 11:15
  • i tried it, it works for me Commented May 8, 2017 at 11:15
  • @mrweinh - in response to your deleted answer, I have an account and API token but since I get a result from the example I figured that a PHP script should return the same. Commented May 8, 2017 at 11:15
  • 1
    @SlowLearner yes, if you want to see you xml response in browser, don't forget to send xml headers Commented May 8, 2017 at 11:27

1 Answer 1

2

You can do it like below:-

<?php
function searchBug($path){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$path);
    curl_setopt($ch, CURLOPT_FAILONERROR,1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    $retValue = curl_exec($ch);          
    curl_close($ch);
    return $retValue;
}

$sXML = searchBug('https://kakapo.fogbugz.com/api.asp?cmd=search&q=project:inbox%20assignedTo:Elinor&cols=ixProject,ixPersonAssignedTo,sTitle&max=2&token=04t9123822q4kbba09nt740inhibk2');
header('Content-Type: text/xml');
echo $sXML;

Output:- http://prntscr.com/f5fj44

Sign up to request clarification or add additional context in comments.

2 Comments

Ok - based on this I got a little further, enough to delete HTML header from the document.... thanks
@SlowLearner glad to help you :):):)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.