public
Last active — forked from nifl/qbAPI.cfc

Quickbase REST API calls

  • Download Gist
qbAPI.cfc
ColdFusion
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
<!---
Name: qbAPI.cfc
Author: Gernot Bartels
Description: Methods to interact with QuickBase
History: Migrated from CF8 to Railo 2010-04-02.
Created: 2009-03-25
Updated: 2010-04-02
--->
<cfcomponent output="false">
<!--- Login --->
<cffunction name="qbLogin" returntype="any" access="public" output="false" hint="" description="Request login and get ticket">
<cfargument name="qbURL" type="string" required="true" />
<cfargument name="user" type="string" required="true" />
<cfargument name="pass" type="string" required="true" />
<!--- Auth --->
<cfhttp url="#qbURL#/main?act=API_Authenticate&username=#user#&password=#pass#" method="post" result="authGet">
<cfhttpparam type="Header" name="Content-Type" value="application/xml" />
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
</cfhttp>
<!--- Parse Filecontent --->
<cfset theContent = xmlParse(authGet.Filecontent) />
<!--- Get Ticket --->
<cfset theTicket = trim(theContent.xmlRoot.XmlChildren[4].XmlText) />
<cfreturn theTicket />
</cffunction>
 
<!--- Get Schema --->
<cffunction name="getSchema" returntype="any" access="public" output="false" hint="" description="Request application schema">
<cfargument name="qbURL" type="string" required="true" />
<cfargument name="appID" type="string" required="true" />
<cfargument name="tableID" type="string" required="false" />
<cfargument name="theTicket" type="string" required="true" />
<cfargument name="theToken" type="string" required="true" />
<!--- call GetSchema --->
<cfhttp url="#qbURL#/#appID#?act=API_GetSchema&ticket=#theTicket#&apptoken=#theToken#" method="post" result="schemaGet">
<cfhttpparam type="Header" name="Content-Type" value="application/xml" />
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
</cfhttp>
<!--- Parse Filecontent --->
<cfset appSchema = xmlParse(schemaGet.Filecontent) />
<cfreturn appSchema />
</cffunction>
<!--- Get table Schema --->
<cffunction name="tableSchema" returntype="any" access="public" output="false" hint="" description="Request application schema">
<cfargument name="qbURL" type="string" required="true" />
<cfargument name="appID" type="string" required="false" />
<cfargument name="tableID" type="string" required="false" />
<cfargument name="theTicket" type="string" required="true" />
<cfargument name="theToken" type="string" required="true" />
<cfhttp url="#qbURL#/#tableID#?act=API_GetSchema&ticket=#theTicket#&apptoken=#theToken#" method="post" result="schemaGet">
<cfhttpparam type="Header" name="Content-Type" value="application/xml" />
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
</cfhttp>
<!--- Parse Filecontent --->
<cfset appSchema = xmlParse(schemaGet.Filecontent) />
<cfreturn appSchema />
</cffunction>
<!--- Return List of Table Names --->
<cffunction name="returnTableNames" returntype="any" access="public" output="false" displayname="Return Table List" description="Return Table Names List">
<cfargument name="theSchema" type="string" required="true" hint="QB Application XML Schema" />
<cfscript>
// Search Schema for QB Application Tables
selectedElements = XmlSearch(theSchema, "qdbapi/table/chdbids/chdbid");
// Return Table Names
for (i = 1; i LTE ArrayLen(selectedElements); i = i + 1)
arrTableName[i] = selectedElements[i].XmlAttributes.name;
// Convert to list
listTableNames = ArrayToList(arrTableName);
</cfscript>
<cfreturn listTableNames />
</cffunction>
<!--- Return Table ID --->
<cffunction name="returnTableID" returntype="any" access="public" output="false" displayname="Return Table ID" description="Return Table ID">
<cfargument name="theSchema" type="string" required="true" hint="QB Application XML Schema" />
<cfscript>
// Search Schema for QB Application Tables
selectedElements = XmlSearch(theSchema, "qdbapi/table/chdbids/chdbid");
// Return Table Names
for (i = 1; i LTE ArrayLen(selectedElements); i = i + 1)
arrTableName[i] = selectedElements[i].XmlAttributes.name;
// Return Table ID's
for (i = 1; i LTE ArrayLen(selectedElements); i = i + 1)
arrTableID[i] = selectedElements[i].XmlText;
// Create struct containing Table Names (key) & Table ID's (value)
for (i = 1; i LTE ArrayLen(selectedElements); i = i + 1)
strTables["#arrTableName[i]#"] = arrTableID[i];
</cfscript>
<cfreturn strTables />
</cffunction>
 
<!--- Count Records --->
<cffunction name="countRecords" returntype="any" access="public" output="false" hint="" description="Count number of records">
<cfargument name="qbURL" type="string" required="true" />
<cfargument name="appID" type="string" required="true" />
<cfargument name="tableID" type="string" required="false" />
<cfargument name="theTicket" type="string" required="true" />
<cfargument name="theToken" type="string" required="true" />
<cfhttp url="#qbURL#/#appID#?act=API_GetNumRecords&ticket=#theTicket#&apptoken=#theToken#"
method="post" result="GetNumRecords">
<cfhttpparam type="Header" name="Content-Type" value="application/xml" />
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
</cfhttp>
<!--- Parse Filecontent --->
<cfset XMLResult = xmlParse(GetNumRecords.Filecontent) />
<!--- Get count --->
<cfset recordCount = trim(XMLResult.xmlRoot.XmlChildren[4].XmlText) />
<cfreturn recordCount />
</cffunction>
<!--- Create Record --->
<cffunction name="createRecord" returntype="any" access="public" output="false" description="Create new record">
<cfargument name="qbURL" type="string" required="true" />
<cfargument name="tableID" type="string" required="true" />
<cfargument name="newRecord" type="string" required="true" />
<cfargument name="theTicket" type="string" required="true" />
<cfargument name="theToken" type="string" required="true" />
<!--- call AddRecord --->
<cfhttp url="#qbURL#/#tableID#?" method="post" charset="utf-8" result="addRecord">
<cfhttpparam type="body" value="#newRecord#" />
<cfhttpparam type="Header" name="Content-Type" value="application/xml" />
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
<cfhttpparam type="Header" name="Content-length" value="#len(newRecord)#"/>
<cfhttpparam type="URL" name="act" value="API_AddRecord">
<cfhttpparam type="URL" name="ticket" value="#theTicket#">
<cfhttpparam type="URL" name="apptoken" value="#theToken#">
</cfhttp>
<cfreturn addRecord.Filecontent />
</cffunction>
<!--- Update Record --->
<cffunction name="updateRecord" returntype="any" access="public" output="false" description="Updates existing record">
<cfargument name="qbURL" type="string" required="true" />
<cfargument name="tableID" type="string" required="true" />
<cfargument name="recordID" type="string" required="true" />
<cfargument name="content" type="string" required="true" />
<cfargument name="theTicket" type="string" required="true" />
<cfargument name="theToken" type="string" required="true" />
<!--- call EditRecord --->
<cfhttp url="#qbURL#/#tableID#?" method="post" charset="utf-8" result="recordUpdate">
<cfhttpparam type="body" value="#content#" />
<cfhttpparam type="URL" name="act" value="API_EditRecord">
<cfhttpparam type="URL" name="rid" value="#recordID#">
<cfhttpparam type="URL" name="ticket" value="#theTicket#">
<cfhttpparam type="URL" name="apptoken" value="#theToken#">
<cfhttpparam type="Header" name="Content-Type" value="application/xml" />
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
</cfhttp>
<cfreturn recordUpdate.Filecontent />
</cffunction>
</cfcomponent>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.