QuickBase PHP API Examples
i’ve had a few requests for examples of how to use the quickbase php api wrapper. so here goes:
setup the quickbase object with login info
include the library and setup the object by passing in username, password, true/false (xml/http), and dbID of the db/table you’ll be transacting with.
1 2 | include_once('../includes/qb.php'); $quickbase = new QuickBase('username','password', true, 'dbID'); |
do a quickbase query
here, we setup a query to return field 3 where (field id 15 is equal to somevalue).
1 2 3 4 5 6 7 8 |
adding a record to a quickbase
this one is super easy. create an associative array with field id’s and values and then use the add_record method.
1 2 3 4 5 6 7 8 9 10 11 12 |
edit a quickbase record
almost identical to add_record, setup the array and use the edit_record method.
1 2 3 4 5 6 7 8 9 10 11 12 |
do a quickbase query
here, we setup a query to return field 3 where (field id 15 is equal to somevalue).
Enjoy this Post?
Spread the word by promoting this post on FaceBook and Twitter.

Josh,
Thanks for putting these examples together. They are helpful.
One thing that I think might be a mistake in the add_record example is that the example you have above has it passing in “fid” as the id parameter. The code in qb.php, however, is expecting just “id” and so that causes things to not work as expected.
I ran it both ways and when one uses “id” instead of “fid” it works as expected.
Josh , very nice sample.
I had a misstake is used QuickBaseClient.js java library to query database to my web . But HTML pages using QuickBaseClient.js must be hosted within QuickBase applications.
- I want to ask you: could i use quickbase php api wrapper for website hosted outside quickbase ?
I appreciate it ,John.
Absolutely you can use the php sdk for apps outside of quickbase. All you need is a QuickBase user with the proper permissions for the operations you are trying to perform.
Josh, Thank for your fast response . I just send a private mail to your email : goodespeler@gmail.com about my situation. I need your help with quickbase php api. Please check it.
I appreciate it, John.
Thank Joshua, everything work perfect now. Great API library and very friendly support !!
I can’t seem to make this work. I’m getting the following error…
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in includes/qb.php on line 61
Thank you!
For developing this class; for responding so quickly; for the help troubleshooting my configuration error.
Joshua, how goes it? I’ve just taken over a QB project and am trying to use your wrapper. Am not too familiar with QB and seem to be hitting a roadblock. I’ve checked my server settings for Curl and have included your library.
A few questions:
- When I try to use the library, for example do_query(), nothing is returned, no errors, no results, nothing… not too sure where I am going wrong.
- With do_query or edit_record: How do I determine which record I want to query or update? For example, I want FID 27 from #28845. Can you provide an example of this?
- Where do I enter the Ticket #? In the wrapper $ticket = ” says to not change. A bit confused about this.
- “setup a query to return field 3 where (field id 15 is equal to somevalue)”: A bit confused about this as well. If I want to return field 3, why am I using FID 15 instead of FID 3? Is this a miss-type?
Will keep working at it; feel like I’m shooting in the dark a bit though. If you can point me in the right direction, great.
Thanks,
DBG
Hi Joshua,
Do you have any solution for UTF-8 Font ? Query’s information do not display correct (explode) on website if database fields has UTF-8 content.
- Do we need to set fields in database use UTF-8 like a default font? And how ? I tried many way but not success.
Thank you very much .
Quickbase can’t interpret PHP files can it? So I would have to host these on my own server and execute them there?
Thanks for your help!
-Hunter
No, it can’t so you would need to host these files. However, you could use the Javascript SDK which can be hosted using a QuickBase DB page.
Good point. Thank you.
I am looking at ways of using Flex/Flash with QB, but am running into all sorts of Sandbox violations unless I host the SWF within the Quickbase domain. I am actually fine with that, but it makes development tricky b/c my local host triggers the Sandbox violation messages too…
Currently, I trust run a trace in Flex to make sure the API URLs have been built correctly. Then I upload the SWF and it runs perfectly. I am using Flash Builder 4 beta 2.
Yea – in order for your SWF to work, we’d have to add your domain to our crossdomain.xml file here: http://www.quickbase.com/crossdomain.xml
Which of course, we aren’t going to do as that isn’t feasible.
We actually have a flex app that we use for the front-end, but we route all API requests to PHP files to handle the heavy lifting. This may help you with development as you’ll spend more time debugging php than flex and having to go through multiple builds and then re-uploading it.
Firebug will also let you look at the request/response from the flex app to your PHP – again useful for local debugging.
Have you looked Intuit’s Partner Platform? It’s a QuickBase-based platform that comes with a Flex QuickBase SDK – and it provides you a dev. sandbox for your Flex app. Check it out: https://ipp.developer.intuit.com/
- Joshua
I have signed up for the IPP and definitely think it’s great. However we use QB to manage several aspects of clinical trials for biotechs. Each trial has customized components to it, so the “build once sell to many” concept of the IPP is a bit out of our (read “my”) development experience at the moment. At some point I’d like to build a product that could be sold on the marketplace and then adapted by the user for each trial. For now, though we can copy over apps and change what’s needed.
Flex has been great for building really nice graphs using the QB data. Also, I built an interface for transferring certain records from other systems into QB.
However, I like the idea of using PHP for getting the data in and out of QB for the Flex front end to use. It’s great that you made php wrapper for this. I will try it out today.
Thanks!
Don’t forget also that there are other options besides Flex for graphs. There are some really nice PHP graphing libraries that will let you feed it an XML file of your data and will spit out a nice graph.
This could be an alternative to Flex as well if the sandboxing issue is a pain.
Feel free to ping me on google talk if you ever have any other questions: goodespeler@gmail.com
- Joshua
Josh,
I have been using the QB Perl SDK for some time, but now must venture down the PHP path. The below is returning an invalid request, and I am not sure why. My test is to return all the records from a table. It appears that authentication is succeeding, and that the token is behaving correctly. What am I missing? Thanks much!
$quickbase = new QuickBase(‘$username’, ‘$password’, true, ‘$dbid’, ‘$QBToken’);
$queries = array(
array(
‘fid’ => ’0′,
‘ev’ => ‘ct’,
‘cri’ => ”)
);
$results = $quickbase->do_query($queries, ”, ”, ”);
-Len
Hello,
I just want to know if there is a possibility to update the password in QuickBase via API ?
Thanks for your answers.
Nicolas
Unfortunately, no – you cannot update a users password via the api.
Hi Joshua,
Good work on this API.
Do you have a sample code using the public function add_record but with uploads? (i am using $usexml = true;)
What kind of variable is $upload?
How do upload the file?
$response = $qb->add_record ($fields, $uploads);
~Rico
Hi,
I have an application where I parse the Quickbase results and display them on a search results page. In some cases the quickbase query returns so many records that I’m getting a memory error in PHP. I’d like to set up the results page so that I display a limited number of results and include links at the bottom so user can click to load the next set. I read about options skp-n and num-n but I haven’t had any luck figuring out how to specify those options in the do_query function. I tried the following with no luck:
$results = $quickbase->do_query($queries, ”, ”, ’6.9.11.13.14.20.31.33.34.81′, ”, ”,’num-500′);
Any suggestions on how I can add the options?
Thanks,
Jennifer
Hi Joshua,
Thanks for this! I was able to create a small front-end web form for QuickBase data entry using the concepts above. I just didn’t get how to use the PHP wrapper until I saw your examples. I was also able to satisfy those people in our group who said “the form is so ugly – I can’t stand it”
Thanks again!
Tim
It seems like maybe Quickbase has updated their API and this wrapper is out of date? For instance, I tried doing a simple $quickbase->get_schema and got an error 24 (“no app token”). If you go to the docs page you link to, they point you to new docs. Those docs say you must include an app token AND ticket on most API calls.
Changing line 884 to:
$url_string = $this->qb_ssl . $this->db_id. “?act=API_GetSchema&ticket=”. $this->ticket . “&apptoken=” . $this->app_token;
And also adding this line to the XML version of the call:
$xml_packet->addChild(‘apptoken’,$this->app_token);
seemed to fix the problem.
Hi Joshua:
First of all, thank you for creating this QuickBase wrapper. I’ve been using it to add and search records and all works great.
Today I need to update a record and I’m having difficulty achieving this task. I’m able to search & retrieve the record; but when I call the $quickbase->edit_record($fields); method I’m getting an error it doesn’t update the database.
Where/How do I tell it which record to update?
Thank you in advance for your help.
Hey Josh, great work! i’m trying to get member sign up and quickbooks to go together. Please feel free to call me…
Steven (305)964-6398
I added some code to my wrapper to use the API_UserRoles api call. I needed to simulate a user dropdown box – perhaps someone will find this useful.
QB Wrapper Code Addition:
public function user_roles() {
if($this->xml) {
$xml_packet = new SimpleXMLElement(”);
$xml_packet->addChild(‘ticket’,$this->ticket);
if ($this->app_token)
$xml_packet->addChild(‘apptoken’, $this->app_token);
$xml_packet = $xml_packet->asXML();
$response = $this->transmit($xml_packet, ‘API_UserRoles’);
}
if($response) {
return $response;
}
return false;
}
In my main php file, I use this to call the new function:
$results = $quickbase->user_roles();
$results will contain an array of all of the users in the database.
Hi Joshua, thanks for the nice wrapper, i wanted to know if you have some examples for the images uploads, that would be a great help. I have been trying it for a while now, but even though i get success on the upload, but the image does not show up in qb database. can you please post some examples of it?
This is what the XML in your request should look like:
Here’s what the XML of the request should look like:
POST https://quickbase.com/db/6mpjiez8?
Content-Type: application/xml
Content-Length:
QUICKBASE-ACTION:API_AddUserToRole
8D6AAAOEJJTQQIAAAAAAAQAAAAAQAAAkAAAAJAAAAAADhCSU0EBgAAAAAABwAEAAAAAQEA
4AJ0ZpbGUgd3JpdHRlbiBieSBBZG9iZSBQaG90b3Nob3CoIDQuMAD/7g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Kvwy/
Bz4rz+3+8wyxBmAk1xJDJr2l2c6xy2mlwT31xAw5Rx8jxjJ/
jXJbKLRGnfbm6foz1Dy6cPV9RvV+38Xp8vtV/3bz4YQjdZ8X1j9r67/svXp6n/UP6X/
PH1P8AizAl/9kA
Here’s a PHP example:
// any file upload?
if($_FILES['_fid_21']['name']) {
$file_name = $_FILES['_fid_21']['name'];
$f_tmp_name = $_FILES['_fid_21']['tmp_name'];
$file_size = $_FILES['_fid_21']['size'];
$fh = fopen($f_tmp_name, ‘r’);
$content = fread($fh, $file_size);
$content = base64_encode($content);
fclose($fh);
$uploads = array( array(‘fid’ => ’21′,
‘filename’ => $file_name,
‘value’ => $content) );
}
// add activity record
$quickbase = new QuickBase($username,$password,true, $dbID);
if ($quickbase) {
$payload = array(array(
‘fid’ => some_field_id,
‘value’ => some_val),
array(
‘fid’ => some_field_id,
‘value’ => some_val)
);
$resp = $quickbase->add_record($payload, $uploads);
Josh, In the $queries array can I add an slist parameter? Or how can I sort the query results? Thanks!
Gen_results_table is working but do_query is not. Can you please throw out a few things I need to double-check? DBID is correct and I’m connecting cause gen_results_table displays fine. I get no xml response with do_query.
Hi Josh, great work.
Are you aware of any work been done to integrate WordPress and Quickbase?
Thanks!
Hi Wilfredo,
I could building something pretty easily that would allow WordPress / QuickBase Integration.
What in particular would you want the plugin to do?
- Joshua
Can you post an example of how to use the import_from_csv function? I can’t seem to get it to work. Thanks! Keep up the great work!
It turned out that something was misspelled in the PHP wrapper code. I’m sorry I don’t exactly recall what it was right now…For those of you that use this function call, be sure to double-check the api call spellings, etc.
for the do_query example, can you give an example where i use AND for the criteria?
let’s say where user is ‘eve’ AND ‘role is ‘manager’
Hi Mery, I ran into the same issue. I was reading the framework and you can add a fourth element to the second or subsequent queries to add AND/OR…
$queries = array(
array(
‘fid’ => ’16′,
‘ev’ => ‘ex’,
‘cri’ => ‘eve’)
),
array(
‘fid’ => ’19′,
‘ev’ => ‘ex’,
‘cri’ => ‘manager’,
‘ao’ => ‘AND’
)
);
Hi Joshua,
Can u please give us an example to fetch data from multiple tables in quickbase.
Thanks,
-Sagar.
Hi Joshua,
For the do_query example, I need to retrieve a field from a record based on a criteria.
Something like “Select accountNo from Transaction where billingNo = some value
I have he following code but is not showing any output…
$line = fgetcsv($fp);
$ArhBillingNumber = $line[1];
$query= array(
array(‘fid’ => ’10′,
‘ev’ => ‘ex’,
‘cri’ => $ArhBillingNumber));
$results = quickbase->do_query($query,”,”,’11′);
echo $results.”;
Please Advise,
Alex
Hi Alex – you can’t just echo $results since the result will be a SimpleXML Object. Try var_dump($results); instead and see if it contains any data.
Hi Joshua,
I am evaluating a PHP editor called NuSphere 6.1 and I am running some php scripts with this product and I am getting the following error from the QuickBase api class.
Fatal error: Call to undefined function curl_init() in Z:\APO\qb-arh-php-works\QuickBaseClient.php on line 127
However, when I run the same scripts from the browser it runs fine without showing the error.
Do you know where is the curl-init method located? Any advise,
thank you,
Alex
Hi Alex,
I would run a phpinfo() from within the same environment and make sure curl is enabled.
The curl-init method is located at the top of the QuickBase SDK class.
- Joshua
Hello
I use the php api for QuickBase
and I look how I can make a request for selection according to multiple criteria
as this example
where field1=”x” and (field2=”y” or field3=”z”)
thank you
$query = array(
array(
“fid” => $fieldfid,
“ev” => “EX”,
“cri” => value
),
array(
“ao” => ‘AND’,
“fid” => $field2_fid,
“ev” => “EX”,
“cri” => value
),
array(
“ao” =>’AND’,
“fid” => $field3_fid,
“ev” => “EX”,
“cri” => value
)
);
$results = $qbconnect->do_query($query,”,”,2.3.5.7.9);
Hi Johsua,
I wrote a php script where I run queries that retrieve a single record from quickbase. Like,
$qbconnect = new QuickBase(username,password,true,$QB_Table);
$queries = array(
array(
“fid” => $QB_Table_field_fid,
“ev” => “EX”,
“cri” => $value )
);
$results = $qbconnect->do_query($queries,”,”,$QBfieldvalue1.’.’. $QBFieldValue2.’.’.$QBFieldValue3.’.’.$QBFieldValue4.’.’.$QBFieldValue5);
if( $results ){
$record = $results->table->records->record->f;
If( count($record) > 0){
$field1 = $record[ 0 ];
$field2 = $record[ 1 ];
$field3 = $record[ 2 ];
$field4 = $record[ 3 ];
$field5 = $record[ 4 ];
$return = array( $field1, $field2, $field3, $field4, $field5 );
}
}
But now I need to modify the query to retrieve multiple records, the instructions to parse a single record to access every single field value is like,
$record = $results->table->records->record->f;
Then I access every element of the array with an index.
Do you know or have an example that allows me to retrieve and access every field value from multiple records retrieved from quickbase?
Thank you,
Alex
Hi Alex – I’m about to leave for vacation, but email me and I will help you when I return: joshua@mcginn.is
Joshua,
Thank you – this page is still paying dividends.
There is a bug(?) in the QuickBase API that your do_query code above uncovers. It turns out using EX vs. ex in a query yields different results. What we demonstrated repeatedly is that EX is an exact match whereas ex acts like CT.
We demonstrated this by making direct calls via url to API_DoQuery so neither your sample nor quickbase.php code is at issue.
Hope it helps anyone else encountering this problem.,
-Mike