tag:help.lighthouseapp.com,2008-09-20:/discussions/api-developers/39-api-php-example
Lighthouse: Discussion
2013-04-29T17:01:45Z
tag:help.lighthouseapp.com,2008-09-20:Comment/12303
2008-09-24T16:32:32Z
2009-06-20T20:01:35Z
API PHP Example
<div><p>Will, this should go into the KB.</p></div>
Tiger Team
tag:help.lighthouseapp.com,2008-09-20:Comment/12303
2008-09-24T16:49:32Z
2009-06-20T20:01:35Z
API PHP Example
<div><pre>
<code class=
"php">$l_sUrl = "http://{your_app_name}.lighthouseapp.com/projects/{project-id}/tickets.xml";
$l_oCurl = curl_init();
curl_setopt( $l_oCurl,CURLOPT_URL, $l_sUrl ); curl_setopt( $l_oCurl, CURLOPT_USERPWD, "username:password" );
$l_sTitle = "title_here"; $l_sDescription = "description here";
$l_sXml = "<?xml version="1.0" encoding="UTF-8"?>".
"<ticket>".
"<title>".$l_sTitle."</title>".
"<body>".$l_sDescription."</body>".
"</ticket>";
$l_sHeader = "X-LighthouseToken: {token_here}\r\n"; $l_sHeader .= "Content-type: application/xml\r\n"; $l_sHeader .= "Content-length: ".strlen( $l_sXml ) . "\r\n\n"; // Important! Two linebreaks. $l_sHeader .= $l_sXml;
curl_setopt( $l_oCurl, CURLOPT_HTTPHEADER, array( $l_sHeader ) );
$l_oResult = curl_exec( $l_oCurl ); curl_close($l_oCurl);</code>
</pre></div>
Rick
tag:help.lighthouseapp.com,2008-09-20:Comment/12303
2008-09-24T16:50:52Z
2009-06-20T20:01:35Z
API PHP Example
<div><p>I'd suggest you html encode the title and description fields. If
you use any raw html entities like <, it will break the XML.</p></div>
Rick
tag:help.lighthouseapp.com,2008-09-20:Comment/12303
2008-12-03T21:22:01Z
2012-07-20T15:35:59Z
API PHP Example
<div><p>This discussion was assigned to Will, on ticket 22.</p></div>
System
tag:help.lighthouseapp.com,2008-09-20:Comment/12303
2009-04-21T15:06:54Z
2009-04-21T15:06:54Z
API PHP Example
<div><p>thanks for getting me started. I found one thing missing for
creating a ticket:</p>
<p>curl_setopt($l_oCurl, CURLOPT_POST, 1);</p>
<p>(Need to send the XML request as POST to create a ticket)</p></div>
bryan
tag:help.lighthouseapp.com,2008-09-20:Comment/12303
2009-04-21T20:13:57Z
2009-04-21T20:13:57Z
API PHP Example
<div><pre>
<code><?php
// Account and user settings
$account = "yourapp";
$project_id = "12345";
$user = "username@email.com";
$password = "yourpass123";
$token = "XXXXXXX";
// Assemble the account url
$url = "http://" . $account . ".lighthouseapp.com/projects/" . $project_id . "/tickets.xml";
// Setup the cURL object
$curl = curl_init();
curl_setopt($l_oCurl, CURLOPT_POST, 1);
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_USERPWD, ($user . ":" . $password) );
// Create the XML to post
$title = "Create a new ticket";
$description = "A new lighthouse ticket";
$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/xml\r\n";
$header .= "Content-length: " . strlen( $xml ) . "\r\n\n"; // Important! Two linebreaks.
$header .= $xml;
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( $header ) );
// Execute the request and get the result
$result = curl_exec( $curl );
curl_close($curl);
?></code>
</pre></div>
Will Duncan
tag:help.lighthouseapp.com,2008-09-20:Comment/12303
2013-04-26T00:33:52Z
2013-04-29T17:01:45Z
API PHP Example
<div><p>anyone following this, here is a better post for the business
end of things that actually generates a valid http request o_O</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></div>
Tiger Team