Joshua's Thoughts

quickbase php api examples

Tags: , , , , ,

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.

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).

$queries = array(
			array(
				'fid'	=> '15',
				'ev'	=> 'ex',
				'cri'	=> 'somevalue')
			 );

$results = $quickbase->do_query($queries, '', '', '3');

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.

$fields = array(
			array(
				'fid'	=> '1',
				'value'	=> 'some value'),
			array(
				'fid'	=> '2',
				'value'	=> 'some value'),
			array(
				'fid'	=> '3',
'value'=>'some value')
						  );
$quickbase->add_record($fields);

edit a quickbase record

almost identical to add_record, setup the array and use the add_record method.

$fields = array(
			array(
				'fid'	=> '1',
				'value'	=> 'some value'),
			array(
				'fid'	=> '2',
				'value'	=> 'some value'),
			array(
				'fid'	=> '3',
'value'=>'some value')
						  );
$quickbase->edit_record($fields);

do a quickbase query

here, we setup a query to return field 3 where (field id 15 is equal to somevalue).

$queries = array(
			array(
				'fid'	=> '15',
				'ev'	=> 'ex',
				'cri'	=> 'somevalue')
			 );

$results = $quickbase->do_query($queries, '', '', '5');

20 Comments, Comment or Ping

  1. Eytan

    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.

  2. 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.

  3. 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.

  4. 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.

  5. Thank Joshua, everything work perfect now. Great API library and very friendly support !!

  6. Will

    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

  7. Will

    Thank you!

    For developing this class; for responding so quickly; for the help troubleshooting my configuration error.

  8. DBG

    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

  9. John

    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 .

  10. Hunter

    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

  11. 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.

  12. Hunter

    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.

  13. 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

  14. Hunter

    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!

  15. 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

  16. Len

    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

  17. Nicolas

    Hello,

    I just want to know if there is a possibility to update the password in QuickBase via API ?

    Thanks for your answers.

    Nicolas

  18. Unfortunately, no – you cannot update a users password via the api.

  19. Rico

    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

  20. 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

Reply to “quickbase php api examples”