WebGeekUK Posted December 22, 2016 Share Posted December 22, 2016 Hi, I am trying to use the following code to connect to an API and then display the data to screen, however, at present when running the code nothing at all is displayed and nothing happens. I'm fairly new to PHP and just cannot figure out what I'm doing wrong. Please help! <?php ini_set('display_errors',"1"); function curl_request(){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://eu.myconnectwise.net/v2017_1/apis/3.0/services/tickets/13934"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: basic ' . base64_encode('#######'.'+'.'##########'.':'.'##########'))); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $json = curl_exec($ch); curl_close ($ch); $obj = json_decode($json); print ($obj['summary']); } print curl_request(); ?> The data structure of what I am trying to pull back is as follows: Ticket {id(Integer) * summary(String(100)) recordType(Enum) board(BoardReference) } Quote Link to comment Share on other sites More sharing options...
requinix Posted December 22, 2016 Share Posted December 22, 2016 What is the contents of $json? Quote Link to comment Share on other sites More sharing options...
WebGeekUK Posted December 22, 2016 Author Share Posted December 22, 2016 (edited) Hi Requinix, I'm unsure what the contents are as I can't view anything in the browser when I run the code. I have checked to ensure the URL and authorization details are correct. The following link details what should be returned: https://developer.connectwise.com/manage/rest?a=service?a=Service&e=Tickets&o=GET. Edited December 22, 2016 by WebGeekUK Quote Link to comment Share on other sites More sharing options...
requinix Posted December 22, 2016 Share Posted December 22, 2016 Try running just this: <?php ini_set('display_errors',"1"); header('Content-Type: text/plain'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://eu.myconnectwise.net/v2017_1/apis/3.0/services/tickets/13934"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: basic ' . base64_encode('#######'.'+'.'##########'.':'.'##########'))); curl_exec($ch); curl_close ($ch); ?> Quote Link to comment Share on other sites More sharing options...
WebGeekUK Posted December 22, 2016 Author Share Posted December 22, 2016 Hi, Having tried the code suggested, I get the following error: Warning: Cannot modify header information - headers already sent by Quote Link to comment Share on other sites More sharing options...
requinix Posted December 22, 2016 Share Posted December 22, 2016 Okay... Can you solve that problem on your own? Quote Link to comment Share on other sites More sharing options...
WebGeekUK Posted December 22, 2016 Author Share Posted December 22, 2016 It doesn't even show any of the api data that is being called in the browser header console... Quote Link to comment Share on other sites More sharing options...
WebGeekUK Posted December 22, 2016 Author Share Posted December 22, 2016 (edited) I have solved the issue with the 'Cannot modify header information' error, however, I am still no closer to understanding why this doesn't seem to be working... This is the page where the api data is being called: http://www.bournetown.co.uk/bourne-events3.php. Edited December 22, 2016 by WebGeekUK Quote Link to comment Share on other sites More sharing options...
requinix Posted December 22, 2016 Share Posted December 22, 2016 It doesn't even show any of the api data that is being called in the browser header console...Of course not: the API call is happening on your server, not in the browser. I have solved the issue with the 'Cannot modify header information' error, however, I am still no closer to understanding why this doesn't seem to be working...[/size]So how about we return to what I was asking about before. That test script I posted - what do you get if you run that? Quote Link to comment Share on other sites More sharing options...
WebGeekUK Posted December 23, 2016 Author Share Posted December 23, 2016 Hi again Requinix and thanks for your support. Unfortunately when I run your test script nothing is returned. Quote Link to comment Share on other sites More sharing options...
WebGeekUK Posted December 23, 2016 Author Share Posted December 23, 2016 Hi again, When adding var_dump($json) I get the following response: bool(false) Quote Link to comment Share on other sites More sharing options...
requinix Posted December 23, 2016 Share Posted December 23, 2016 Right now I don't care about $json. Listen to me, okay? This code: <?php ini_set('display_errors',"1"); header('Content-Type: text/plain'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://eu.myconnectwise.net/v2017_1/apis/3.0/services/tickets/13934"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: basic ' . base64_encode('#######'.'+'.'##########'.':'.'##########'))); curl_exec($ch); curl_close ($ch); ?>Put the right username and password in there, then run it. What is the output? If there's sensitive information then redact it, but otherwise post exactly what you see. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.