SlideShare a Scribd company logo
1 of 14
Getting REST API JSON data into
Excel
cRest primer from Excel Liberation
Excel Liberation for details
cRest purpose
REST APIs return all kinds of
data shapes. Getting that to a
2 dimensional Excel table can
be labor intensive
{
"Definition": "rest definition: repose, sleep; '''specifically'''.",
"DefinitionSource": "Merriam-Webster",
"Heading": "Rest",
"AbstractSource": "Wikipedia",
"Image": "",
"RelatedTopics": [
{
"Result": "<a href="http://duckduckgo.com/Rest_(music)">Rest (music)</a>, a pause
in a piece of music",
"Icon": {
"URL": "https://i.duckduckgo.com/i/1dca4003.png",
"Height": "",
"Width": ""
},
"FirstURL": "http://duckduckgo.com/Rest_(music)",
"Text": "Rest (music), a pause in a piece of music"
},
{
"Result": "<a href="http://duckduckgo.com/Leisure">Leisure</a> - Leisure, or free
time, is time spent away from business, work, and domestic chores.",
"Icon": {
"URL": "https://i.duckduckgo.com/i/753cd753.jpg",
"Height": "",
"Width": ""
},
"FirstURL": "http://duckduckgo.com/Leisure",
cRest is a VBA class that can
organize most JSON API data
an populate an Excel table
Excel Liberation for details
Pre-requisite classes
cRest uses two important VBA classes; cJobject (for
organizing data of variable structural depth and
converting to and from JSON) and cDataSet (for
abstracting Excel data)
You can find write ups and primer decks on Excel
Liberation.
 How to use cJobject
 How to use cDataSet
You can also find detail on cRest here.
Excel Liberation for details
REST API calls
These are usually made through a base API URL with
arguments to describe the query.
For example
http://api.duckduckgo.com/?format=json&q=rest
The data format is usually JSON or XML. cRest is
designed to deal with JSON. Excel has other tools
for manipulating XML
Excel Liberation for details
REST Excel Library
cRest is generally expecting to use a library (although you
can specify many parameters as arguments). This
simplifies re-use of APIS and also encourages the
establishment of a base of useful APIs
The library entry – (itself a cJobect) – for the duckduckgo
API looks like this
With .add("duckduckgo")
.add "restType", erSingleQuery
.add "url", "http://api.duckduckgo.com/?format=json&q="
.add "results", "relatedtopics"
.add "treeSearch", True
.add "ignore", vbNullString
End With
Excel Liberation for details
Setting up the output sheet
Getting data out of the JSON response and into your sheet
is a simple matter of naming the columns the same thing
as the data you want. Anything that matches gets
populated, everything else is ignored
{
"Definition": "rest definition: repose, sleep; '''specifically'''.",
"DefinitionSource": "Merriam-Webster",
"Heading": "Rest",
"AbstractSource": "Wikipedia",
"Image": "",
"RelatedTopics": [
{
"Result": "<a href="http://duckduckgo.com/Rest_(music)">Rest (music)</a>, a pause
in a piece of music",
"Icon": {
"URL": "https://i.duckduckgo.com/i/1dca4003.png",
"Height": "",
"Width": ""
},
"FirstURL": "http://duckduckgo.com/Rest_(music)",
"Text": "Rest (music), a pause in a piece of music"
},
{
"Result": "<a href="http://duckduckgo.com/Leisure">Leisure</a> - Leisure, or free
time, is time spent away from business, work, and domestic chores.",
"Icon": {
"URL": "https://i.duckduckgo.com/i/753cd753.jpg",
"Height": "",
"Width": ""
},
"FirstURL": "http://duckduckgo.com/Leisure",
Data starts at
.add "results", "relatedtopics“
We only want these 2 fields
Excel Liberation for details
restQuery execution
These can generally be written as a very simple one liner.
Here is a typical procedure to execute an API call and
populate the sheet. The arguments are the sheet to put
the result in, the rest library entry to use and some query
value
Public Sub testDuckDuckGo()
generalQuery("duckduckgo", "duckduckgo", _
InputBox("Enter your duckduckgo query")).tearDown
End Sub
Excel Liberation for details
Specifying Type of query
The duckduckgo query was this type.
.add "restType", erSingleQuery
That means that for a single query, multiple lines of data
are returned. There is another type of query
erQueryPerRow. In this case, some variable data in
each row is used as input to the query.
Excel Liberation for details
Query per row
In this example we want to use each value in the ‘domain
column’ and execute an API call based on it.
The library entry
With .add("page rank")
.add "restType", erRestType.erQueryPerRow
.add "url", "http://prapi.net/pr.php?f=json&url="
.add "results", ""
.add "treeSearch", False
.add "ignore", ""
End With
The caller
Public Sub testPageRank()
generalDataSetQuery("page rank", "page rank", "domain").tearDown
End Sub
Excel Liberation for details
More complicated column headers
Of course API data is often not two dimensional. You can
use subclass column titles as well The data
{
"total_pages": 1,
"current_page": 1,
"total_records": 73,
"records": [
{
"id": "51c857b60693b9dd1d06ce24",
"field_82": "Fashion/Wedding ",
"field_38": [
{
"id": "519a2ecd09f3ace950c70276",
"identifier": "Shopcade"
}
],
"field_39": [
{
"id": "a",
"identifier": "john doe"
},
{
"id": "b",
"identifier": "jane doe"
}
],
The column titles
Field_38.1.id
the id propertyof the first item in the Field_38 object
Field_39..identifier
all properties named identifier in the Field_39 array of objects, separated by
commas
Excel Liberation for details
Portability
The Google Apps Script version of cRest has the same
syntax (allowing for minor javaScript/VBA linguistic
differences)
Examples – Google Apps Script
function testDuckDuckGo() {
generalQuery("duckduckgo", "duckduckgo", _
InputBox("Enter your duckduckgo query")).tearDown();
}
There are other ways of doing this in Google Apps
Script but using cJobject in GAS allows portability to
and from VBA. It also uses Google Caching
Infrastructure is used by default so often results will
not need an API call at all.
Excel Liberation for details
Extensibility
Easy to extend with powerful capabilities
Examples
Get data directly from Google Fusion and populate a work sheet
getDataFromFusion "Fusion", getFusionKey(), "1pvt-tlc5z6Lek8K7vAIpXNUsOjX3qTbIsdXx9Fo“
Create queries using the Google Wire Protocol (as used by google docs)
With .add("googlecurrencyconverter")
.add "restType", erRestType.erQueryPerRow
.add "url", "http://www.google.com/ig/calculator?hl=en&q=1USD=?"
.add "results", ""
.add "treeSearch", False
.add "ignore", vbNullString
.add "wire", True
End With
Access the cJobject containing returned jSon data
for each job in crest.jobject,children
‘ do some special processing
next job
Access the cDataSet just populated
for each row in crest.dset.rows
‘ do some special processing
next row
Excel Liberation for details
Memory recovery
Like many objects with recursive linking, memory will not be
recovered by the VBA garbage collector simply by going out of
scope. A teardown is provided, and should be used for efficient
memory recovery.
Examples
Public Sub testFqlStream()
Dim fqlQuery As String
‘ get facebook stream data
fqlQuery = "SELECT message,share_count,likes " & _
"FROM stream WHERE CONTAINS('" & _
InputBox("message contains ?") & "')"
generalQuery("fqlStream", "fql", fqlQuery).tearDown
End Sub
Excel Liberation for details
Summary
These examples show some of the capabilities of
cRest Excel REST library and how to extend Excel to
use JSON REST APIs
For more detail, and to download see Excel Liberation

More Related Content

More from Bruce McPherson

Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appBruce McPherson
 
Do something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a databaseDo something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a databaseBruce McPherson
 
Do something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseDo something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseBruce McPherson
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed versionBruce McPherson
 
Google cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionGoogle cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionBruce McPherson
 
Using script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and ExcelUsing script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and ExcelBruce McPherson
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerBruce McPherson
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primerBruce McPherson
 

More from Bruce McPherson (9)

Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing app
 
Do something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a databaseDo something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a database
 
Do something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseDo something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as database
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed version
 
Google cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionGoogle cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstraction
 
Dbabstraction
DbabstractionDbabstraction
Dbabstraction
 
Using script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and ExcelUsing script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and Excel
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primer
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
 

Recently uploaded

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 

Recently uploaded (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 

Getting REST API JSON data into Excel

  • 1. Getting REST API JSON data into Excel cRest primer from Excel Liberation
  • 2. Excel Liberation for details cRest purpose REST APIs return all kinds of data shapes. Getting that to a 2 dimensional Excel table can be labor intensive { "Definition": "rest definition: repose, sleep; '''specifically'''.", "DefinitionSource": "Merriam-Webster", "Heading": "Rest", "AbstractSource": "Wikipedia", "Image": "", "RelatedTopics": [ { "Result": "<a href="http://duckduckgo.com/Rest_(music)">Rest (music)</a>, a pause in a piece of music", "Icon": { "URL": "https://i.duckduckgo.com/i/1dca4003.png", "Height": "", "Width": "" }, "FirstURL": "http://duckduckgo.com/Rest_(music)", "Text": "Rest (music), a pause in a piece of music" }, { "Result": "<a href="http://duckduckgo.com/Leisure">Leisure</a> - Leisure, or free time, is time spent away from business, work, and domestic chores.", "Icon": { "URL": "https://i.duckduckgo.com/i/753cd753.jpg", "Height": "", "Width": "" }, "FirstURL": "http://duckduckgo.com/Leisure", cRest is a VBA class that can organize most JSON API data an populate an Excel table
  • 3. Excel Liberation for details Pre-requisite classes cRest uses two important VBA classes; cJobject (for organizing data of variable structural depth and converting to and from JSON) and cDataSet (for abstracting Excel data) You can find write ups and primer decks on Excel Liberation.  How to use cJobject  How to use cDataSet You can also find detail on cRest here.
  • 4. Excel Liberation for details REST API calls These are usually made through a base API URL with arguments to describe the query. For example http://api.duckduckgo.com/?format=json&q=rest The data format is usually JSON or XML. cRest is designed to deal with JSON. Excel has other tools for manipulating XML
  • 5. Excel Liberation for details REST Excel Library cRest is generally expecting to use a library (although you can specify many parameters as arguments). This simplifies re-use of APIS and also encourages the establishment of a base of useful APIs The library entry – (itself a cJobect) – for the duckduckgo API looks like this With .add("duckduckgo") .add "restType", erSingleQuery .add "url", "http://api.duckduckgo.com/?format=json&q=" .add "results", "relatedtopics" .add "treeSearch", True .add "ignore", vbNullString End With
  • 6. Excel Liberation for details Setting up the output sheet Getting data out of the JSON response and into your sheet is a simple matter of naming the columns the same thing as the data you want. Anything that matches gets populated, everything else is ignored { "Definition": "rest definition: repose, sleep; '''specifically'''.", "DefinitionSource": "Merriam-Webster", "Heading": "Rest", "AbstractSource": "Wikipedia", "Image": "", "RelatedTopics": [ { "Result": "<a href="http://duckduckgo.com/Rest_(music)">Rest (music)</a>, a pause in a piece of music", "Icon": { "URL": "https://i.duckduckgo.com/i/1dca4003.png", "Height": "", "Width": "" }, "FirstURL": "http://duckduckgo.com/Rest_(music)", "Text": "Rest (music), a pause in a piece of music" }, { "Result": "<a href="http://duckduckgo.com/Leisure">Leisure</a> - Leisure, or free time, is time spent away from business, work, and domestic chores.", "Icon": { "URL": "https://i.duckduckgo.com/i/753cd753.jpg", "Height": "", "Width": "" }, "FirstURL": "http://duckduckgo.com/Leisure", Data starts at .add "results", "relatedtopics“ We only want these 2 fields
  • 7. Excel Liberation for details restQuery execution These can generally be written as a very simple one liner. Here is a typical procedure to execute an API call and populate the sheet. The arguments are the sheet to put the result in, the rest library entry to use and some query value Public Sub testDuckDuckGo() generalQuery("duckduckgo", "duckduckgo", _ InputBox("Enter your duckduckgo query")).tearDown End Sub
  • 8. Excel Liberation for details Specifying Type of query The duckduckgo query was this type. .add "restType", erSingleQuery That means that for a single query, multiple lines of data are returned. There is another type of query erQueryPerRow. In this case, some variable data in each row is used as input to the query.
  • 9. Excel Liberation for details Query per row In this example we want to use each value in the ‘domain column’ and execute an API call based on it. The library entry With .add("page rank") .add "restType", erRestType.erQueryPerRow .add "url", "http://prapi.net/pr.php?f=json&url=" .add "results", "" .add "treeSearch", False .add "ignore", "" End With The caller Public Sub testPageRank() generalDataSetQuery("page rank", "page rank", "domain").tearDown End Sub
  • 10. Excel Liberation for details More complicated column headers Of course API data is often not two dimensional. You can use subclass column titles as well The data { "total_pages": 1, "current_page": 1, "total_records": 73, "records": [ { "id": "51c857b60693b9dd1d06ce24", "field_82": "Fashion/Wedding ", "field_38": [ { "id": "519a2ecd09f3ace950c70276", "identifier": "Shopcade" } ], "field_39": [ { "id": "a", "identifier": "john doe" }, { "id": "b", "identifier": "jane doe" } ], The column titles Field_38.1.id the id propertyof the first item in the Field_38 object Field_39..identifier all properties named identifier in the Field_39 array of objects, separated by commas
  • 11. Excel Liberation for details Portability The Google Apps Script version of cRest has the same syntax (allowing for minor javaScript/VBA linguistic differences) Examples – Google Apps Script function testDuckDuckGo() { generalQuery("duckduckgo", "duckduckgo", _ InputBox("Enter your duckduckgo query")).tearDown(); } There are other ways of doing this in Google Apps Script but using cJobject in GAS allows portability to and from VBA. It also uses Google Caching Infrastructure is used by default so often results will not need an API call at all.
  • 12. Excel Liberation for details Extensibility Easy to extend with powerful capabilities Examples Get data directly from Google Fusion and populate a work sheet getDataFromFusion "Fusion", getFusionKey(), "1pvt-tlc5z6Lek8K7vAIpXNUsOjX3qTbIsdXx9Fo“ Create queries using the Google Wire Protocol (as used by google docs) With .add("googlecurrencyconverter") .add "restType", erRestType.erQueryPerRow .add "url", "http://www.google.com/ig/calculator?hl=en&q=1USD=?" .add "results", "" .add "treeSearch", False .add "ignore", vbNullString .add "wire", True End With Access the cJobject containing returned jSon data for each job in crest.jobject,children ‘ do some special processing next job Access the cDataSet just populated for each row in crest.dset.rows ‘ do some special processing next row
  • 13. Excel Liberation for details Memory recovery Like many objects with recursive linking, memory will not be recovered by the VBA garbage collector simply by going out of scope. A teardown is provided, and should be used for efficient memory recovery. Examples Public Sub testFqlStream() Dim fqlQuery As String ‘ get facebook stream data fqlQuery = "SELECT message,share_count,likes " & _ "FROM stream WHERE CONTAINS('" & _ InputBox("message contains ?") & "')" generalQuery("fqlStream", "fql", fqlQuery).tearDown End Sub
  • 14. Excel Liberation for details Summary These examples show some of the capabilities of cRest Excel REST library and how to extend Excel to use JSON REST APIs For more detail, and to download see Excel Liberation