Download - Saving Time And Effort With QuickBase Api - Sergio Haro

Transcript
Page 1: Saving Time And Effort With QuickBase Api - Sergio Haro

Saving Time and Effort with the QuickBase APISergio Haro

Page 2: Saving Time And Effort With QuickBase Api - Sergio Haro

How does this help you?

Integration – Export/Import data from external sources (SQL / MS Access)

– Automate data entry

– Mash-ups (Add QuickBase data to other websites)

– See upcoming presentations ‘Connecting QuickBase with Databases’ and ‘Website Integration with QuickBase ‘

Custom Business Logic– Pull data to perform custom logic

– Insert calculated data back

Custom UI– Build your own app or website with QuickBase as your backing store

– Bypass the native UI to simplify or expand its capabilities

Page 3: Saving Time And Effort With QuickBase Api - Sergio Haro

Jump-Start with SDK @ code.intuit.com

Browser-Based• JavaScript

- Good for db-pages (beware of cross-domain policy if using on external websites)- http://intuitlabs.com/apps/yql-and-intuit-quickbase (Getting around cross-domain)- See upcoming sessions ‘Magic Buttons’ and ‘Building a QuickBase Mobile Application’

Scripting Languages• Ruby

- http://www.ruby-lang.org- Object-oriented scripting language- Write scripts in your favorite text editor- See upcoming session ‘Integrating with QuickBase Web Services’

• VB- http://msdn.microsoft.com/en-us/vbasic/- Build VB scripts in Visual Studio (Windows only)

• Perl- http://www.perl.org/- Write scripts in your favorite text editor

General Programming Languages• C#

- http://msdn.microsoft.com/en-us/vcsharp/- Build C#apps in Visual Studio (Windows only)

• Java- http://java.sun.com/- Build Java apps with your favorite IDE (Eclipse, NetBeans, etc)

Page 4: Saving Time And Effort With QuickBase Api - Sergio Haro

How does it work?

You QuickBase

HTTP (GET or POST)

XML

Page 5: Saving Time And Effort With QuickBase Api - Sergio Haro

HTTP Request

• URLPOST http://www.quickbase.com/db/main

Page 6: Saving Time And Effort With QuickBase Api - Sergio Haro

HTTP Request

• URLPOST http://www.quickbase.com/db/main

• HeadersHost: www.quickbase.comUser-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: UTF-8,*Keep-Alive: 300Connection: keep-alive

Page 7: Saving Time And Effort With QuickBase Api - Sergio Haro

HTTP Request

• URLPOST http://www.quickbase.com/db/main

• HeadersHost: www.quickbase.comUser-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: UTF-8,*Keep-Alive: 300Connection: keep-alive

• Bodyfoobar=true&type=unknown

Page 8: Saving Time And Effort With QuickBase Api - Sergio Haro

Components of an API Call

1. Scope• Set in the URL• Dependent on Action

Page 9: Saving Time And Effort With QuickBase Api - Sergio Haro

Components of an API Call

1. Scope

2. Action to perform

3. Parameters for action

Page 10: Saving Time And Effort With QuickBase Api - Sergio Haro

Scope

1. Main– https://www.quickbase.com/db/main

2. App– https://www.quickbase.com/db/{app_id}

3. Table– https://www.quickbase.com/db/{table_id}

Page 11: Saving Time And Effort With QuickBase Api - Sergio Haro

Components of an API Call

1. Scope

2. Action to perform• Set in the URL, Headers, or Body

Page 12: Saving Time And Effort With QuickBase Api - Sergio Haro

Action

• HeaderQUICKBASE-ACTION: API_AddRecord

• URLQuery string: “a=API_AddRecord”https://www.quickbase.com/db/b4ds?a=API_AddRecord

• Body <qdbapi>

<action>API_AddRecord</action></qdbapi>

Page 13: Saving Time And Effort With QuickBase Api - Sergio Haro

Components of an API Call

1. Scope

2. Action to perform

3. Parameters for action• Set in the URL and/or Body• Dependent on action• Encoded as XML or Form

Page 14: Saving Time And Effort With QuickBase Api - Sergio Haro

Parameters for Action (API_FindDBByName)

Parameter: Valuedbname: Test APIticket: kiedzc4rtab8gqdr6apptoken: asfkhlk35rnl4nn

Page 15: Saving Time And Effort With QuickBase Api - Sergio Haro

XML Parameters

<qdbapi><dbname>test API</dbname><ticket>kiedzc4rtab8gqdr6</ticket><apptoken>asfkhlk35rnl4nn<apptoken>

</qdbapi>

Page 16: Saving Time And Effort With QuickBase Api - Sergio Haro

XML Parameters

• URLPOST http://www.quickbase.com/db/main

• HeadersContent-Type: application/xmlContent-Length: 76QUICKBASE-ACTION: API_FindDBByName

• Body<qdbapi>

<dbname>test API</dbname><ticket>kiedzc4rtab8gqdr6</ticket><apptoken>asfkhlk35rnl4nn<apptoken>

</qdbapi>

Page 17: Saving Time And Effort With QuickBase Api - Sergio Haro

Form Parameters

dbname=test%20API&ticket=kiedzc4rtab8gqdr6&apptoken=asfkhlk35rnl4nn

Page 18: Saving Time And Effort With QuickBase Api - Sergio Haro

Form Parameters

• URLPOST http://www.quickbase.com/db/main

• HeadersContent-Type: application/x-www-form-urlencodedContent-Length: 76QUICKBASE-ACTION: API_FindDBByName

• Body dbname=test%20API&ticket=kiedzc4rtab8gqdr6&apptoken=asfkhlk35rnl4nn

Page 20: Saving Time And Effort With QuickBase Api - Sergio Haro

What will I get back?

<?xml version="1.0" ?><qdbapi><action>API_FindDBByName</action><errcode>0</errcode><errtext>No error</errtext><dbid>57pa5vjf</dbid><dbname>Test API</dbname>

</qdbapi>

Page 21: Saving Time And Effort With QuickBase Api - Sergio Haro

Example

09-15 02:49:58.550 I366aswux2 Process: Req: 0.013 [LB: 0.003 WS: 0.004 Q: 0.004] Bytes=[R: 0 W: 24957] Uid=56752832 OP=/db/main

• Date• Time• Request ID• Logging Function• Request Time• Load Balancer time• App Server time• Queue time• Bytes Read• Bytes Written• User ID• URL

Page 22: Saving Time And Effort With QuickBase Api - Sergio Haro

Example

Main Script Tasks:1. Get lines from input2. Parse lines3. Calculate Statistics4. Upload Statistics

Page 23: Saving Time And Effort With QuickBase Api - Sergio Haro

Example - Create Request

string action; // Get POST data string data = addRecord(stats, out action);

// Create HTTP Request string url = “http://www.quickbase.com/db/” + dbid; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);

// Set HTTP Headers webRequest.Method = "POST"; webRequest.ContentType = "application/xml"; webRequest.Headers.Add("QUICKBASE-ACTION", action);

// Write Body byte[] postBytes = Encoding.ASCII.GetBytes(data); webRequest.ContentLength = postBytes.Length; Stream postStream = webRequest.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close();

Page 24: Saving Time And Effort With QuickBase Api - Sergio Haro

Example - Create Body

// Create Root Document action = "API_AddRecord";

XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("qdbapi");

XmlElement child;

// Add Field child = doc.CreateElement("field"); child.SetAttribute("fid", "6"); child.InnerText = stats.webServerAverage.ToString(); root.AppendChild(child);

// Add App token child = doc.CreateElement("apptoken"); child.InnerText = "ye6wbdh59j7rbsf3txbd679ha7"; root.AppendChild(child);

doc.AppendChild(root);

StringWriter sw = new StringWriter(); XmlTextWriter tx = new XmlTextWriter(sw); doc.WriteTo(tx);

return sw.ToString();

Page 25: Saving Time And Effort With QuickBase Api - Sergio Haro

Example - Create Request

string action; // Get POST data string data = addRecord(stats, out action);

// Create HTTP Request string url = “http://www.quickbase.com/db/” + dbid; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);

// Set HTTP Headers webRequest.Method = "POST"; webRequest.ContentType = "application/xml"; webRequest.Headers.Add("QUICKBASE-ACTION", action);

// Write Body byte[] postBytes = Encoding.ASCII.GetBytes(data); webRequest.ContentLength = postBytes.Length; Stream postStream = webRequest.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close();

Page 26: Saving Time And Effort With QuickBase Api - Sergio Haro

Example - Create Request

string action; // Get POST data string data = addRecord(stats, out action);

// Create HTTP Request string url = “http://www.quickbase.com/db/” + dbid; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);

// Set HTTP Headers webRequest.Method = "POST"; webRequest.ContentType = "application/xml"; webRequest.Headers.Add("QUICKBASE-ACTION", action);

// Write Body byte[] postBytes = Encoding.ASCII.GetBytes(data); webRequest.ContentLength = postBytes.Length; Stream postStream = webRequest.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close();

Page 27: Saving Time And Effort With QuickBase Api - Sergio Haro

Example - Create Request

string action; // Get POST data string data = addRecord(stats, out action);

// Create HTTP Request string url = “http://www.quickbase.com/db/” + dbid; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);

// Set HTTP Headers webRequest.Method = "POST"; webRequest.ContentType = "application/xml"; webRequest.Headers.Add("QUICKBASE-ACTION", action);

// Write Body byte[] postBytes = Encoding.ASCII.GetBytes(data); webRequest.ContentLength = postBytes.Length; Stream postStream = webRequest.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close();

Page 28: Saving Time And Effort With QuickBase Api - Sergio Haro

Resources

• Developer Resources– http://quickbase.intuit.com/developer/

• API Guide (old)– https://www.quickbase.com/up/6mztyxu8/g/rc7/en/

Page 29: Saving Time And Effort With QuickBase Api - Sergio Haro

API’S YOU SHOULD KNOW

Page 30: Saving Time And Effort With QuickBase Api - Sergio Haro

API_Authenticate

Parameters:

– username– password

Page 31: Saving Time And Effort With QuickBase Api - Sergio Haro

API_AddRecord

Parameters:

– Field (name=“Field Name” or fid=“14”)– apptoken– ticket

Page 32: Saving Time And Effort With QuickBase Api - Sergio Haro

API_EditRecord

Parameters:

– rid– Field (name=“Field Name” or fid=“14”)– apptoken– ticket

Page 33: Saving Time And Effort With QuickBase Api - Sergio Haro

API_DoQuery

Parameters:

– query/qid/qname– clist– slist– apptoken– ticket