PHP API Wrapper (SDK) for QuickBase
For the latest on the QuickBase PHP SDK, please see this post.
The information below is not currently being maintained and may not present the latest news, information and code regarding the QuickBase PHP SDK.
For anyone interested in using PHP with QuickBase, here is a PHP wrapper. It uses cURL to post XML and HTTP POSTS to QuickBase. Big thanks to Alex Wilson for providing most of the original code base. The documentation for the QuickBase API can be found here.
Updates
- No longer being updated here.
- 6/5/2009 – Added support for tokens and realms
- 9/12/2008 – Fixed SimpleXMLElement Bug (added qdbapi tags)
- 9/12/2008 – Added support for API_RunImport
1 2 3 4 | /*---------------------------------------------------------------------- Title : QuickBase PHP SDK Author : Joshua McGinnis (joshua_mcginnis@intuit.com) Description : This is a php wrapper of the QuickBase HTTP API. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 | The QuickBase API is well documented here: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm The MIT License Copyright (c) 2008 Intuit, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE -----------------------------------------------------------------------*/ ini_set('display_errors', 'on'); // ini setting for turning on errors Class QuickBase { /*--------------------------------------------------------------------- // User Configurable Options -----------------------------------------------------------------------*/ var $user_name = ''; // QuickBase user who will access the QuickBase var $passwd = ''; // Password of this user var $db_id = ''; // Table/Database ID of the QuickBase being accessed var $app_token = ''; var $xml = true; var $user_id = 0; var $qb_site = "www.quickbase.com"; var $qb_ssl = "https://www.quickbase.com/db/"; var $ticketHours = ''; /*--------------------------------------------------------------------- // Do Not Change -----------------------------------------------------------------------*/ var $input = ""; var $output = ""; var $ticket = ''; /* --------------------------------------------------------------------*/ public function __construct($un, $pw, $usexml = true, $db = '', $token = '', $realm = '', $hours = '') { if($un) { $this->user_name = $un; } if($pw) { $this->passwd = $pw; } if($db) { $this->db_id = $db; } if($token) $this->app_token = $token; if($realm) { $this->qb_site = $realm . '.quickbase.com'; $this->qb_ssl = 'https://' . $realm . '.quickbase.com/db/'; } if($hours) { $this->ticketHours = (int) $hours; } $this->xml = $usexml; $uid = $this->authenticate(); if($uid) { $this->user_id = $uid; } } public function set_xml_mode($bool) { $this->xml = $bool; } public function set_database_table($db) { $this->db_id = $db; } private function transmit($input, $action_name = "", $url = "", $return_xml = true) { if($this->xml) { if($url == "") { $url = $this->qb_ssl. $this->db_id; } $content_length = strlen($input); $headers = array( "POST /db/".$this->db_id." HTTP/1.0", "Content-Type: text/xml;", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", "Content-Length: ".$content_length, 'QUICKBASE-ACTION: '.$action_name ); $this->input = $input; $ch = curl_init($url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $input); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); } else { $ch = curl_init($input); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); $this->input = $input; } $r = curl_exec($ch); if($return_xml) { $response = new SimpleXMLElement($r); } else { $response = $r; } return $response; } /* API_Authenticate: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579970 */ public function authenticate() { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('username',$this->user_name); $xml_packet->addChild('password',$this->passwd); if ($this->ticketHours) $xml_packet->addChild('hours',$this->ticketHours); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_Authenticate', $this->qb_ssl."main"); } else { $url_string = $this->qb_ssl . "main?act=API_Authenticate&username=" . $this->user_name ."&password=" . $this->passwd; $response = $this->transmit($url_string); } if($response) { $this->ticket = $response->ticket; $this->user_id = $response->userid; } } /* API_AddField: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579958 */ public function add_field ($field_name, $type) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('label',$field_name); $xml_packet->addChild('type',$type); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_AddField'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_AddField&ticket=". $this->ticket ."&label=" .$field_name."&type=".$type; $response = $this->transmit($url_string); } if($response->errcode == 0) { return $response->fid; } return false; } /* API_AddRecord: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579962 */ public function add_record ($fields, $uploads = false) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $i = intval(0); foreach($fields as $field) { $safe_value = preg_replace('/&(?!w+;)/', '&', $field['value']); $xml_packet->addChild('field',$safe_value); $xml_packet->field[$i]->addAttribute('fid', $field['fid']); $i++; } if ($uploads) { foreach ($uploads as $upload) { $xml_packet->addChild('field', $upload['value']); $xml_packet->field[$i]->addAttribute('fid', $upload['fid']); $xml_packet->field[$i]->addAttribute('filename',$upload['filename']); $i++; } } if ($this->app_token) $xml_packet->addChild('apptoken', $this->app_token); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_AddRecord'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_AddRecord&ticket=". $this->ticket; foreach ($fields as $field) { $url_string .= "&_fid_" . $field['fid'] . "=" . urlencode($field['value']) . ""; } $response = $this->transmit($url_string); } if($response) { return $response; } return false; } /* API_ChangePermission: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579974 */ public function change_permission($uname, $modify, $view, $create, $save_views, $delete, $admin) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('uname',$uname); $xml_packet->addChild('modify',$modify); $xml_packet->addChild('view',$view); $xml_packet->addChild('create',$create); $xml_packet->addChild('saveviews',$save_views); $xml_packet->addChild('delete',$delete); $xml_packet->addChild('admin',$admin); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_ChangePermission'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_ChangePermission&ticket=". $this->ticket . "&uname=".$uname ."&modify=".$modify ."&view=".$view ."&create=".$create ."&saveviews=".$save_views ."&delete=".$delete ."&admin=".$admin; $response = $this->transmit($url_string); } if($response) { return $response; } return false; } /* API_ChangeRecordOwner: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579977 */ public function change_record_owner($new_owner, $rid){ if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('rid',$rid); $xml_packet->addChild('newowner',$new_owner); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_ChangeRecordOwner'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_ChangeRecordOwner&ticket=". $this->ticket ."&rid=".$rid ."&newowner=".$new_owner; $response = $this->transmit($url_string); } if($response) { return true; } return false; } /* API_CloneDatabase: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579981 */ public function clone_database($new_name, $new_desc, $keep_data = 1){ if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('newdbname',$new_name); $xml_packet->addChild('newdbdesc',$new_desc); $xml_packet->addChild('keepData',$keep_data); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_CloneDatabase'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_CloneDatabase&ticket=". $this->ticket ."&newdbname=".$new_name ."&newdbdesc=".$new_desc ."&keepData=".$keep_data; $response = $this->transmit($url_string); } if($response) { return $response->newdbid; } return false; } /* API_CreateDatabase: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579984 */ public function create_database($db_name, $db_desc) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('dbname',$db_name); $xml_packet->addChild('dbdesc',$db_desc); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_CreateDatabase'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_CreateDatabase&ticket=". $this->ticket ."&dbname=".$db_name ."&dbdesc=".$db_desc; $response = $this->transmit($url_string); } if($response) { return $response->dbid; } return false; } /* API_DeleteDatabase: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579988*/ public function delete_database() { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_DeleteDatabase'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_DeleteDatabase&ticket=". $this->ticket; $response = $this->transmit($url_string); } if($response) { return true; } return false; } /* API_DeleteField: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579992*/ public function delete_field($fid) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('fid',$fid); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_DeleteField'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_DeleteField&ticket=". $this->ticket ."&fid=".$fid; $response = $this->transmit($url_string); } if($response) { return true; } return false; } /* API_DeleteRecord: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579996*/ public function delete_record($rid) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('rid',$rid); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_DeleteRecord'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_DeleteRecord&ticket=". $this->ticket ."&rid=".$rid; $response = $this->transmit($url_string); } if($response) { return true; } return false; } /* API_DoQuery: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126579999 */ public function do_query($queries =0, $qid= 0, $qname=0, $clist = 0, $slist=0, $fmt = 'structured', $options = "") { if($this->xml) { //A query in queries has the following items in this order: //field id, evaluator, criteria, and/or //The first element will not have an and/or $xml_packet=''; $pos = 0; if ($queries) { $xml_packet.=''; foreach ($queries as $query) { $criteria = ""; if($pos > 0) { $criteria .= $query['ao']; } $criteria .= "{'" . $query['fid'] . "'." . $query['ev'] . ".'" . $query['cri']."'}"; $xml_packet.= $criteria; $pos++; } $xml_packet.=''; } else if ($qid) { $xml_packet .= ''.$qid.''; } else if ($qname) { $xml_packet .= ''.$qname.''; } else { return false; } $xml_packet .= ' '.$fmt.''; if($clist) $xml_packet .= ''.$clist.''; if($slist) { $xml_packet .= ''.$slist.''; $xml_packet .= ' '.$options.''; } if ($this->app_token) $xml_packet .= '' . $this->app_token . ''; $xml_packet .= ''.$this->ticket.' '; $response = $this->transmit($xml_packet, 'API_DoQuery'); } else { // If not an xml packet $url_string = $this->qb_ssl . $this->db_id. "?act=API_DoQuery&ticket=". $this->ticket ."&fmt=".$fmt; $pos = 0; if ($queries) { $url_string .= "&query="; foreach ($queries as $query) { $criteria = ""; if($pos > 0) { $criteria .= $query['ao']; } $criteria .= "{'" . $query['fid'] . "'." . $query['ev'] . ".'" . $query['cri']."'}"; $url_string.= $criteria; $pos++; } } else if ($qid) { $url_string .= "&qid=".$qid; } else if ($qname) { $url_string .= "&qname=".$qname; } else { return false; } if($clist) $url_string .= "&clist=".$clist; if($slist) $url_string .= "&slist=".$slist; if($options) $url_string .= "&options=".$options; $response = $this->transmit($url_string); } if($response) { return $response; } return false; } /* API_EditRecord: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580003 */ public function edit_record($rid, $fields, $uploads = 0, $updateid = 0) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('rid',$rid); $i = intval(0); foreach($fields as $field) { $safe_value = preg_replace('/&(?!w+;)/', '&', $field['value']); $xml_packet->addChild('field',$safe_value); $xml_packet->field[$i]->addAttribute('fid', $field['fid']); $i++; } if ($uploads) { foreach ($uploads as $upload) { $xml_packet->addChild('field', $upload['value']); $xml_packet->field[$i]->addAttribute('fid', $upload['fid']); $xml_packet->field[$i]->addAttribute('filename',$upload['filename']); $i++; } } if ($this->app_token) $xml_packet->addChild('apptoken', $this->app_token); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_EditRecord'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_EditRecord&ticket=". $this->ticket ."&rid=".$rid; foreach ($fields as $field) { $url_string .= "&_fid_" . $field['id'] . "=" . $field['value']; } if ($uploads) { foreach ($uploads as $upload) { $xml_packet .= "" . $upload['value'] . ""; } } if($updateid) $url_string .= "&update_id=".$updateid; $response = $this->transmit($url_string); } if($response) { return $response->update_id; } return false; } /* API_FieldAddChoices: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580007 */ public function field_add_choices ($fid, $choices) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('fid',$fid); foreach($choices as $choice) { $xml_packet->addChild('choice',$choice); } $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_FieldAddChoices'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_FieldAddChoices&ticket=". $this->ticket ."&fid=".$fid; foreach ($choices as $choice) { $url_string.='&choice='.$choice; } $response = $this->transmit($url_string); } if($response) { return $response->numadded; } return false; } /* API_FieldRemoveChoices: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580011 */ public function field_remove_choices ($fid, $choices) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('fid',$fid); foreach($choices as $choice) { $xml_packet->addChild('choice',$choice); } $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_FieldRemoveChoices'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_FieldRemoveChoices&ticket=". $this->ticket ."&fid=".$fid; foreach ($choices as $choice) { $url_string.='&choice='.$choice; } $response = $this->transmit($url_string); } if($response) { return $response->numremoved; } return false; } /* API_GenAddRecordForm: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580019 */ public function find_db_by_name($db_name) { if($this->xml) { $xml_packet=' '.$db_name.' '.$this->ticket.' '; $response = $this->transmit($xml_packet, 'API_FindDBByName'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_FindDBByName&ticket=". $this->ticket ."&dbname=".$db_name; $response = $this->transmit($url_string); } if($response) { return $response->db_id; } return false; } /* API_GenAddRecordForm: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580019 */ public function gen_add_record_form($fields){ if($this->xml) { $xml_packet=''; foreach ($fields as $field) { $xml_packet .= "" . $field['value'] . ""; } $xml_packet .= ''.$this->ticket.' '; $response = $this->transmit($xml_packet, 'API_GenAddRecordForm', "", false); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_GenAddRecordForm&ticket=". $this->ticket; foreach ($fields as $field) { $url_string .= "&_fid_" . $field['id'] . "=" . $field['value']; } $response = $this->transmit($url_string, "" , "" , false); } if($response) { return $response; } return false; } /* API_GenResultsTable: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580023 */ public function gen_results_table($queries = 0, $qid = 0, $qname=0, $clist = 0, $slist = 0, $options = 0) { //A query in the queries array contains the following in this order: Field ID, Evaluator, Criteria //The first element in the second query in queries would contain "and/or" if needed. if ($this->xml) { $xml_packet=''; $pos = 0; if ($queries) { $xml_packet.=''; foreach ($queries as $query) { $criteria = ""; if($pos > 0) { $criteria .= $query['ao']; } $criteria .= "{'" . $query['fid'] . "'." . $query['ev'] . ".'" . $query['cri']."'}"; $xml_packet.= $criteria; $pos++; } $xml_packet.=''; } else if ($qid) { $xml_packet .= ''.$qid.''; } else if ($qname) { $xml_packet .= ''.$qname.''; } else { return false; } $xml_packet .= ' '.$fmt.''; if($clist) $xml_packet .= ''.$clist.''; if($slist) { $xml_packet .= ''.$slist.''; } if($options) { $xml_packet .= ' '.$options.''; } $xml_packet .= ''.$this->ticket.' '; $response = $this->transmit($xml_packet, 'API_GenResultsTable', "" , false); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_GenResultsTable&ticket=". $this->ticket; $pos = 0; if ($queries) { $url_string .= "&query="; foreach ($queries as $query) { $criteria = ""; if($pos > 0) { $criteria .= $query['ao']; } $criteria .= "{'" . $query['fid'] . "'." . $query['ev'] . ".'" . $query['cri']."'}"; $url_string.= $criteria; $pos++; } } if($clist) $url_string .= "&clist=".$clist; if($slist) { $url_string .= "&slist=".$slist; } if ($options) { $url_string .= '&options='; foreach ($options as $option) { if($cot>0) { $url_string .= "."; } $url_string .= $option; $cot++; } } echo $url_string; $response = $this->transmit($url_string, "" , "" , false); } if($response) { return $response; } return false; } /* API_GetDBPage: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580033 */ public function get_db_page($page_id) { if($this->xml) { $xml_packet = ' '.$page_id.' '; $response = $this->transmit($xml_packet, 'API_GetDBPage'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_GetDBPage&ticket=". $this->ticket ."&pageid=".$page_id; $response = $this->transmit($url_string); } } /* API_GetNumRecords: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580037 */ public function get_num_records() { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_GetNumRecords'); } $url_string = $this->qb_ssl . $this->db_id. "?act=API_GetNumRecords&ticket=". $this->ticket; $response = $this->transmit($url_string); if($response) { return $response; } } /* API_GetRecordAsHTML: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580040 */ public function get_record_as_html($rid) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('rid',$rid); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_GetRecordAsHTML', "", false); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_GetRecordAsHTML&ticket=". $this->ticket ."&rid=".$rid; $response = $this->transmit($url_string, "" , "" ,false); } if($response) { return $response; } return false; } /* API_GetRecordInfo: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580046 */ public function get_record_info($rid) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('rid',$rid); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_GetRecordInfo'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_GetRecordInfo&ticket=". $this->ticket ."&rid=".$rid; $response = $this->transmit($url_string); } if($response) { return $response; } return false; } /* API_GetSchema: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580049 */ public function get_schema () { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_GetSchema'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_GetSchema&ticket=". $this->ticket; $response = $this->transmit($url_string); } if($response) { return $response; } return false; } /* API_GrantedDB's: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580052 */ public function granted_dbs () { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_GrantedDBs'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_GrantedDBs&ticket=". $this->ticket; $response = $this->transmit($url_string); } if($response) { return $response; } return false; } /*API_ImportFromCSV: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580055 */ public function import_from_csv ($records_csv, $clist, $skip_first = 0) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('records_csv',$records_csv); $xml_packet->addChild('clist',$clist); $xml_packet->addChild('skipfirst',$skip_first); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_ImportFromCSV'); } if($response) { return $response; } return false; } /* API_PurgeRecords: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580061 */ public function purge_records($queries = 0, $qid = 0, $qname = 0) { if($this->xml) { $xml_packet = ''; if ($queries) { $xml_packet.=''; foreach ($queries as $query) { $criteria = ""; if($pos > 0) { $criteria .= $query['ao']; } $criteria .= "{'" . $query['fid'] . "'." . $query['ev'] . ".'" . $query['cri']."'}"; $xml_packet.= $criteria; $pos++; } $xml_packet.=''; } else if ($qid) { $xml_packet .= ''.$qid.''; } else if ($qname) { $xml_packet .= ''.$qname.''; } else { return false; } $xml_packet.=''.$this->ticket.' '; $response = $this->transmit($xml_packet, 'API_PurgeRecords'); } else { $url_string = $this->qb_ssl . $this->db_id. "?act=API_PurgeRecords&ticket=". $this->ticket; if ($queries) { $url_string .= "&query="; foreach ($queries as $query) { $criteria = ""; if($pos > 0) { $criteria .= $query['ao']; } $criteria .= "{'" . $query['fid'] . "'." . $query['ev'] . ".'" . $query['cri']."'}"; $url_string.= $criteria; $pos++; } } else if ($qid) { $url_string .= "&qid=".$qid; } else if ($qname) { $url_string .= "&qname=".$qname; } else { return false; } $response = $this->transmit($url_string); } if($response) { return $response->num_records_deleted; } return false; } /* API_SetFieldProperties: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580065 */ public function set_field_properties($properties, $fid) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('fid',$fid); foreach($properties as $key => $value) { $xml_packet->addChild($key,$value); } if ($this->app_token) $xml_packet->addChild('apptoken', $this->app_token); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_SetFieldProperties'); } if($response) { return true; } return false; } /* API_SignOut: https://www.quickbase.com/up/6mztyxu8/g/rc7/en/va/QuickBaseAPI.htm#_Toc126580069 */ public function sign_out() { if($this->xml) { $xml_packet =''; $response = $this->transmit($xml_packet, 'API_SignOut', $this->qb_ssl."main"); } else { $url_string="https://www.quickbase.com/db/main?act=API_SignOut&ticket=". $this->ticket; $response = $this->transmit($url_string); } if($response) { return true; } return false; } /* API_RunImport */ public function api_run_import($id) { if($this->xml) { $xml_packet = new SimpleXMLElement(''); $xml_packet->addChild('id',$id); $xml_packet->addChild('ticket',$this->ticket); $xml_packet = $xml_packet->asXML(); $response = $this->transmit($xml_packet, 'API_RunImport'); } else { $url_string = $this->qb_ssl . $this->db_id.'?act=API_RunImport&ticket='. $this->ticket .'&id='. $id; $response = $this->transmit($url_string); } |
1 2 3 4 5 6 | if($response) { return $response; } return false; } } |
Enjoy this Post?
Spread the word by promoting this post on FaceBook and Twitter.

What is the license on this code? BSD? MIT?
Could you give us an example of how to use this? I want to run a query on mysql and import that directly once a day to Quickbase.
Thanks! This looks really good.
@bennington
we do this all the time.
i’ve just posted some very basic examples of how to use the wrapper here:
http://blog.joshuamcginnis.com/2009/04/quickbase-php-api-examples/
basically, what you would need to do is loop over each mysql result, build your add_record query and then add the record.
Joshua,
Thank you for making this PHP API. It is great.
I just wanted to point out to others that might use this, that now that API Tokens are utilized more (I think will be mandatory), I have found in my brief expermintation with your Class library that some functions are missing support to send the app token.
I see that you recently updated the Class to support App Tokens in some functions, however For Example, I see it is missing from the XML portion of gen_results_table
If I figure out how/where to add, I will post the fix.
Thanks,
Brian
Thanks for making this Joshua. Have you or anyone you know changed/modified it to work without curl?
Hi Wilfredo,
While no one has published any changes to the PHP SDK to allow POSTing without cURL, it is possible. Just note that whatever you choose, you use POST and not GET as GET requests will eventually be phased out.
Here’s a blog post on how to POST data using PHP streams (@fopen):
http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl
Let me know how it turns out.
- Joshua
Thanks for making this Joshua. It’s been really helpful.
I’m using do_query to pull some information from quickbase but i need the results to be displayed in a drop down box. Based on the API documentation it says that do_query returns a XML file which i was trying to convert into an array that i could use to populate the ddl but i haven’t had any luck. Any suggestions?
The SDK automatically turns the response XML into a SimpleXML object (http://php.net/manual/en/book.simplexml.php) for easy traversal.
I’ve tried different functions that convert simplexml to arrays but none of them have worked. they either display a “Node does not exist” error or my drop down is blank. Would you be able to post an example?
Email me next week and I’ll help you out a little more: joshua_mcginnis@intuit.com
For do_query to work for me I had to change
$response = $this->transmit($xml_packet, ‘API_DoQuery’);
to
$response = $this->transmit($xml_packet, ‘API_DoQuery’, “” , false);
Hi Josh,
I found an error in the wrapper for the CSV import. Currently it says this:
$response = $this->transmit($xml_packet, ‘API_ImportFormCSV’);
It should say this:
$response = $this->transmit($xml_packet, ‘API_ImportFromCSV’);
The api was spelled wrong, which is why I was having so many issues trying to get it to work!
Thanks,
Tim
Hi Tim,
Thank you for the correction – I have updated the post.
It would be great to have you join the open source project for the PHP SDK:
https://code.intuit.com/sf/projects/qb_php_sdk
You’re bug reports could end up helping the larger community!
- Joshua
Hi Josh-
Just downloaded your sdk, have yet to try (thanks for your work!). I don’t see any discussion at code.intuit.com, what is the best way to stay in touch and contribute? I’m have a big project on my plate to integrate a large db with a site using flash/flex/actionscript and feel the php sdk would probable help bridging.
If you have questions, you’re always welcome to email me directly at joshua@mcginn.is.
Hi Josh-
I have been running a php script daily for about four months, and since friday last week I am getting that says something like ” Trying to get property of non-object in line 613,
the line is
$record=$results->table->records->record->f;
The program has not been changed. Has the xml document structure generated from a query been changed.
Thanks,
Alex