Skip to content

Instantly share code, notes, and snippets.

@krhoyt
Created April 5, 2013 03:30
Show Gist options
  • Select an option

  • Save krhoyt/5316391 to your computer and use it in GitHub Desktop.

Select an option

Save krhoyt/5316391 to your computer and use it in GitHub Desktop.
General access to QuickBase database through the XML-RPC API using PHP.
<?php
$username = "_USER_NAME_";
$password = "_PASSWORD_";
$token = "_TOKEN_";
$dbid = "_DATABASE_ID_";
$access = authenticate( $username, $password );
$survey = questions( $dbid, $token, $access["ticket"] );
echo json_encode( $survey );
function authenticate( $user, $pass )
{
$query = array(
"username" => $user,
"password" => $pass
);
$request = curl_init();
$request = curl_init( "https://www.quickbase.com/db/main" );
curl_setopt( $request, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $request, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $request, CURLOPT_HTTPHEADER, array(
"QUICKBASE-ACTION: API_Authenticate"
) );
curl_setopt( $request, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt( $request, CURLOPT_POSTFIELDS, $query );
$response = curl_exec( $request );
$dom = new DOMDocument();
$dom -> loadXML( $response );
return array(
"ticket" => $dom -> getElementsByTagName( "ticket" ) -> item( 0 ) -> textContent,
"userid" => $dom -> getElementsByTagName( "userid" ) -> item( 0 ) -> textContent
);
}
function events( $db, $token, $ticket )
{
$query = array(
"apptoken" => $token,
"dbid" => $db,
"ticket" => $ticket
);
$request = curl_init( "https://www.quickbase.com/db/" . $db );
curl_setopt( $request, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $request, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $request, CURLOPT_HTTPHEADER, array(
"QUICKBASE-ACTION: API_DoQuery"
) );
curl_setopt( $request, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt( $request, CURLOPT_POSTFIELDS, $query );
$response = curl_exec( $request );
}
function questions( $db, $token, $ticket )
{
$query = array(
"apptoken" => $token,
"dbid" => $db,
"ticket" => $ticket
);
$request = curl_init( "https://www.quickbase.com/db/" . $db );
curl_setopt( $request, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $request, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $request, CURLOPT_HTTPHEADER, array(
"QUICKBASE-ACTION: API_DoQuery"
) );
curl_setopt( $request, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt( $request, CURLOPT_POSTFIELDS, $query );
$response = curl_exec( $request );
$dom = new DOMDocument();
$dom -> loadXML( $response );
$records = $dom -> getElementsByTagName( "record" );
$results = array();
for( $q = 0; $q < $records -> length; $q++ )
{
$item = array(
"question" => $records -> item( $q ) -> getElementsByTagName( "question" ) -> item( 0 ) -> textContent,
"answer" => explode( "\n", $records -> item( $q ) -> getElementsByTagName( "answer" ) -> item( 0 ) -> textContent ),
"placement" => $records -> item( $q ) -> getElementsByTagName( "placement" ) -> item( 0 ) -> textContent,
"name" => $records -> item( $q ) -> getElementsByTagName( "event_name" ) -> item( 0 ) -> textContent,
"date" => $records -> item( $q ) -> getElementsByTagName( "event_date" ) -> item( 0 ) -> textContent
);
array_push( $results, $item );
}
return $results;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment