tag:help.lighthouseapp.com,2008-09-20:/discussions/api-developers/1135-api-downLighthouse: Discussion 2013-04-29T17:03:36Ztag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-25T20:15:30Z2013-04-25T20:15:30ZUsing the API with PHP<div><p>The only thing that's different is that we recently changed load
balancers (SSL and IP address changed) but the old setup is still
running and should work. Are you using a library to access the API?
Can you reproduce with, say, just cURL?</p></div>Tiger Teamtag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-25T20:32:17Z2013-04-25T20:32:17ZUsing the API with PHP<div><p>We're using curl via PHP. The code is basically the same as
found here...<br>
<a href=
"http://help.lighthouseapp.com/discussions/api-developers/39-api-php-example">
http://help.lighthouseapp.com/discussions/api-developers/39-api-php...</a></p>
<p>I haven't tried using just curl via command line yet... I've
never tried that, actually, so trying to craft a curl command that
replicates what we're doing in php might take a bit for me to wrap
my head around. Before I get into that, could you take a quick look
at the php example code and see if there's anything obvious to you
that could cause this?</p></div>gazugafantag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-25T21:29:37Z2013-04-25T21:29:37ZUsing the API with PHP<div><p>We're seeing the same problem using the same sample code
from:</p>
<p><a href=
"http://help.lighthouseapp.com/discussions/api-developers/39-api-php-example#comment_138421">
http://help.lighthouseapp.com/discussions/api-developers/39-api-php...</a></p>
<p>This has worked fine for us for months, but is now returning an
empty result and not creating the ticket.</p>
<p>Using curl from the command line, I have been able to create a
ticket, so it's not apparent to me what has changed.</p>
<p>Any advice?</p></div>Colin Graytag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-25T22:37:56Z2013-04-25T22:37:56ZUsing the API with PHP<div><p>If it suddenly broke, it's likely our fault..! I will take a
look. Are you including any yaml in your XML?</p></div>Tiger Teamtag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-25T22:56:43Z2013-04-25T22:56:43ZUsing the API with PHP<div><p>Dont burn too much time-- I should be able to figure it out way
faster. It seems to be restricted to PHP clients only.</p></div>Tiger Teamtag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-25T22:57:51Z2013-04-25T22:57:51ZUsing the API with PHP<div><p>However if you are able to capture the raw http post for me
that'd be suuuper helpful</p></div>Tiger Teamtag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-25T22:58:32Z2013-04-25T22:58:33ZUsing the API with PHP<div><p>Thanks for looking into this. We're not using any YAML. Let us
know what you find...</p></div>Colin Graytag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-25T23:30:49Z2013-04-25T23:30:49ZUsing the API with PHP<div><p>Can you give me the project id? You're posting to /tickets.xml,
right?</p></div>Courtenaytag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-25T23:34:26Z2013-04-25T23:34:27ZUsing the API with PHP<div><p>I'm posting to: /projects/90316/tickets.xml</p>
<p>If you can give me an email address, I can send you the php curl
request dump.</p></div>Colin Graytag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-25T23:58:01Z2013-04-25T23:58:01ZUsing the API with PHP<div><p>OK, I've found the cause of it. The workaround for now is for
you to hardcode the lighthouse domain and IP address so you're
hitting the old load balancer - the new one (ELB) has issues with
php's curl (!!)</p>
<p>So you'd put this in your hosts file:</p>
<pre>
<code>184.73.201.0 your.lighthouseapp.com</code>
</pre>
<p>replacing 'your' with your account name.</p>
<p>I am still trying to find the right incantation to your php
script to get it working.</p></div>Courtenaytag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-26T00:31:49Z2013-04-26T00:31:49ZUsing the API with PHP<div><p>ok, turns out the original php script was crappy. Change your
script to look like this:</p>
<pre>
<code>$header = "X-Lighthouse-Token: " . $token . "\r\n";
$header .= "Content-Type: application/xml\r\n";
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( $header ) );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $xml );</code>
</pre>
<p>removing the parts about content-length, $header .= $xml and so
on.</p>
<p>Thus the whole request (based on that sample anyway) is
something like</p>
<pre>
<code>$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
"<ticket>" .
"<title>" . $title . "</title>" .
"<body>" . $description . "</body>" .
"</ticket>";
// Setup the right headers for content-type etc.
$header = "X-LighthouseToken: " . $token . "\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( $header ) );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $xml );
// Execute the request and get the result
$result = curl_exec( $curl );</code>
</pre></div>Courtenaytag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-26T17:10:49Z2013-04-26T17:10:52ZUsing the API with PHP<div><p>Still no luck; I had tried an approach similar to this
yesterday, and I constantly get back an error stating "Title can't
be blank". I suspect I'm missing something obvious. Here's my test
code:</p>
<pre>
<code>
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
"<ticket>" .
"<title>myTitle</title>" .
"<body>myDescription</body>" .
"</ticket>";
// Setup the right headers for content-type etc.
$header = "X-LighthouseToken: " . $token . "\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n\r\n";
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( $header ) );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $xml );
// Execute the request and get the result
$result = curl_exec( $curl );
curl_close($curl);</code>
</pre>
<p>Also, does your last suggestion mean we don't need the hosts
file change (I've tried it both ways with no success)?</p></div>Colin Graytag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-26T18:02:30Z2013-04-26T18:02:30ZUsing the API with PHP<div><p>Hi Colin,</p>
<p>Here is a simpler, more readable version that works:</p>
<pre>
<code><?php
$account = "XXX";
$project = "XXX";
$username = "XXX";
$password = "XXX";
$url = "http://$account.lighthouseapp.com/projects/$project/tickets.xml";
$title = "title";
$description = "description";
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
"<ticket>" .
"<title>$title</title>" .
"<body>$description</body>" .
"</ticket>";
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_USERPWD, "$username:$password" );
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( "Content-Type: application/xml" ) );
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $xml );
curl_exec( $curl );
curl_close( $curl );
?></code>
</pre>
<p>A few notes though:</p>
<ul>
<li>
<p>I would recommend using an API token instead of user/password.
simply add <code>X-LighthouseToken: TOKEN</code> to the header
array, and remove the <code>CURLOPT_USERPWD</code> line.</p>
</li>
<li>
<p>I would also recomment using an XML library to generate the XML
rather than handcrafting it, which is error prone.</p>
</li>
</ul>
<p>Let me know if you have questions.</p></div>Julientag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-26T19:47:41Z2013-04-26T19:47:41ZUsing the API with PHP<div><p>This new PHP code works for me!</p></div>gazugafantag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-26T23:19:09Z2013-04-27T01:47:57ZUsing the API with PHP<div><p>I can confirm that the new code works for us. I'd recommend
placing this in your knowledge base, as well as making reference to
it in the threads that have solutions that no longer work.</p>
<p>Thanks Julien and Courtenay!</p></div>Colin Graytag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-27T00:43:06Z2013-04-27T01:47:57ZUsing the API with PHP<div><p>This worked for us as well. I'd recommend putting this sample in
the KB and referencing it from the other thread whose approach no
longer works.</p>
<p>Thank you Julien and Courtenay for all your help!</p></div>Colin Graytag:help.lighthouseapp.com,2008-09-20:Comment/265730732013-04-29T17:03:33Z2013-04-29T17:03:33ZUsing the API with PHP<div><p>Hi Colin,</p>
<p>Courtenay pasted the correct solution in the other thread as a
follow up.</p>
<p>Glad things are working now.</p>
<p>Cheers!</p></div>Julien