tag:help.lighthouseapp.com,2008-09-20:/discussions/api-developers/163-struggling-with-simple-api-transaction-in-php
Lighthouse: Discussion
2011-04-07T05:38:08Z
tag:help.lighthouseapp.com,2008-09-20:Comment/2600330
2010-08-17T14:02:51Z
2010-08-17T14:02:51Z
Struggling with simple API transaction in PHP
<div><p>I think I finally figured out the answer to my own question. I had to do it as CURLOPT_PUT instead and create an actual temporary XML file and specify the putfile and put file size.</p>
<p>In case it helps anyone else out, here's some working PHP code to update a ticket, that can be modified to suit your needs:</p>
<pre><code>define( 'LIGHTHOUSE_URL', 'https://myproject.lighthouseapp.com/' );
define( 'LIGHTHOUSE_USER', 'myemail@domain.com' );
define( 'LIGHTHOUSE_PASS', 'mypassword' );
define( 'LIGHTHOUSE_API_TOKEN', 'tokenxxxxxxxxxxxxxxxxxxxx' );
$project_id = '12345';
$ticket_id = '2';
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
"<ticket>" .
"<state>resolved</state>" .
"</ticket>";
$putFile = tmpFile();
fwrite( $putFile, $xml );
$header = "X-LighthouseToken: " . LIGHTHOUSE_API_TOKEN . "\r\n";
$header .= "Content-type: application/xml\r\n";
$header .= "Content-length: " . strlen( $xml ) . "\r\n\n"; // Important! Two linebreaks.
$header .= $xml;
$ch = curl_init();
curl_setopt( $ch, CURLOPT_PUT, true );
curl_setopt( $ch, CURLOPT_INFILE, $putFile );
curl_setopt( $ch, CURLOPT_INFILESIZE, strlen( $xml ) );
curl_setopt( $ch, CURLOPT_USERPWD, LIGHTHOUSE_USER . ':' . LIGHTHOUSE_PASS );
curl_setopt( $ch, CURLOPT_URL, LIGHTHOUSE_URL . "projects/{$project_id}/tickets/{$ticket_id}.xml" );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( $header ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$curl_result = curl_exec( $ch );
curl_close( $ch );</code></pre></div>
jared (at netrivet)