API

QuickBase PHP API Examples

Added by Joshua McGinnis on April 23rd, 2009, filed under API, PHP, QuickBase, Web Development, XML

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

1
2
3
4
5
6
7
8
9
10
11
12
$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.

1
2
3
4
5
6
7
8
9
10
11
12
$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).

1
2
3
4
5
6
7
8
$queries = array(
            array(
                'fid'   => '15',
                'ev'    => 'ex',
                'cri'   => 'somevalue')
             );

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

Enjoy this Post?

Spread the word by promoting this post on FaceBook and Twitter.

Reader Comments (24)

  1. Eytan May 6, 2009 at 4:56 pm

    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. John May 25, 2009 at 11:52 pm

    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.

    • Joshua May 26, 2009 at 5:57 am

      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.

  3. John May 26, 2009 at 10:43 pm

    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.

  4. John June 2, 2009 at 12:51 am

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

  5. Will June 5, 2009 at 9:33 am

    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

  6. Will June 17, 2009 at 5:06 pm

    Thank you!

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

  7. DBG June 29, 2009 at 6:41 pm

    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

  8. John July 31, 2009 at 7:09 am

    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 .

  9. Hunter November 5, 2009 at 1:17 pm

    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

    • Joshua November 5, 2009 at 1:23 pm

      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.

  10. Hunter November 5, 2009 at 1:37 pm

    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.

  11. Joshua November 5, 2009 at 1:49 pm

    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

  12. Hunter November 5, 2009 at 3:33 pm

    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!

  13. Joshua November 5, 2009 at 3:39 pm

    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

  14. Len February 25, 2010 at 12:01 pm

    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

  15. Nicolas March 1, 2010 at 4:46 pm

    Hello,

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

    Thanks for your answers.

    Nicolas

    • Joshua March 1, 2010 at 5:08 pm

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

  16. Rico March 6, 2010 at 10:28 pm

    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

  17. Jennifer Strahan March 8, 2010 at 2:54 pm

    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

  18. Tim March 31, 2010 at 1:17 pm

    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

  19. Jon June 9, 2010 at 12:09 pm

    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.

  20. Wilfredo July 6, 2010 at 7:42 pm

    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.

  21. Steven The Nurse September 2, 2010 at 4:53 pm

    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

What do you think?