SlideShare a Scribd company logo
Coding 102
REST API Basics using Spark
David STAUDT, Developer Evangelist, dstaudt@cisco.com
Stève SFARTZ, API Evangelist, stsfartz@cisco.com
DEVNET-2002
• REST API Basics
• A tour of Cisco Spark API
• Interactive Documentation Hands-on
• Postman Hands-on
• Javascript examples
• Pre-requisites
• You know how to forge API requests with Postman (or a similar REST client)
• If not, attend DEVNET-1001: Coding 101- Introduction to REST APIs
Agenda
REST API Basics
Coding 101 Prerequisites – DEVNET1001
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
What is so great about REST?
same concept, many Cisco APIs
Easy to Build
Web apps
Mobile apps
M2M, Bots…
REST API
DEVNET-2002 4
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Terminology of a REST API query
GET /../repos?page=1 HTTP/1.1 accept: application/json
HTTP 200 OK
browser api.github.com:443
method path protocol
status code
https://api.github.com/users/CiscoDevNet/repos?page=1&per_page=2
headers
URL:
response body
HTTP
request
HTTP
response
api endpoint
JSON payload
parameters
DEVNET-2002 5
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
http://getpostman.com
• Want to code along? Install POSTMAN now
• Free tool to forge API requests, examine responses
DEVNET-2002 6
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
method
url
request
headers
status code
response headers
content-type
response
body
query parameters
DEVNET-2002 7
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
JSON syntax
• square brackets for lists
• curly braces for objects
• name/value pairs for properties,
separated by commas
• pick an online editor
• http://codebeautify.org/jsonviewer
http://www.jsoneditoronline.org
DEVNET-2002 8
Cisco Spark for Developers
A tour of Cisco Spark APIs
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Cisco Spark
Secure & Open
Complete & Simple
Spark for Developers
User Integrations, APIs/SDKs, etc.
Spark Hybrid Services
Cloud + Prem
Partner Services
Interconnect
Message Meeting Call
DEVNET-2002 10
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
‘Your App’
now with
Cisco Collab!
Spark APIs
Extend Cisco Collaboration Cloud
GET
POST
DELETE
PUT /Rooms
/Memberships
/Messages
/Teams
/People
DEVNET-2002 11DEVNET-2002 11
/Webhooks
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Cisco Spark API v1 (July 2016)
/People /Rooms /Membership /Messages /Teams /Webhooks
List People List Rooms List Memberships List Messages List Teams List Webhooks
Create a Room Create a Membership Create a Message Create a Team Create a Webhook
Get Person Details Get Room details Get Membership details Get Message details Get Team details Get Webhook details
Update a Room Update a Membership Update a Team Update a Webhook
Delete a Room Delete a Membership Delete a Message Delete a Team Delete a Webhook
GET
POST
DELETE
PUT
DELETE DELETE DELETE
PUT PUT
POST POST POST
GET GET GET
GET GET
GET
GET GETGET
DEVNET-2002 12
DELETE
PUT
POST
GET
GET
Hands on
list your Spark Rooms
with the Interactive Documentation
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Developer Portal Interactive API
documentation
Client SDKs
developer.ciscospark.com
24/7 Dev Support
DEVNET-2002 14
15
16
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Hands-on Instructions
• Go to « List Rooms » documentation on the Developer Portal
https://developer.ciscospark.com/resource-rooms.html
• Login: and Turn « Test Mode » on:
• Run the query:
17
Hands on
add a Message to a Room
with Postman
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Demo : list Rooms from Postman
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco PublicDEVNET-2002
Hands on
Import the Postman collection
bit.ly/DEVNET2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Hands on
• Get your Cisco Spark Token from developer.ciscospark.com
• Fill in the Authentication Header
• Authorization : Bearer YOUR_SPARK_TOKEN
• List some Rooms you are a member of
Add a Message to a Room with Postman
21
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Hands on
• Pick a Room identifier « RoomId »
Add a Message to a Room with Postman
22DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Hands on
• Forge a POST request to create a message
• API documentation : https://developer.ciscospark.com/endpoint-messages-post.html
Add a Message to a Room with Postman
DEVNET-2002 23
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
POSTED !!!
• 200 OK
• Check Message Id & attachments
DEVNET-2002 24
Cisco Spark for Developers
Spark API calls in Javascript
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
How to request from Javascript
• A benefit of REST is that you can invoke Spark from any language
• Hand code with your favorite HTTP client library
• Or generate code from Postman
• OAuth 2 to inject user API token
Do It Yourself … with Postman code assistants
DEVNET-2002 26
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
How to request from NodeJS
1. Generate a nodejs skeleton from Postman, 2. Run from the command
line
Do It Yourself … with Postman code assistants
DEVNET-2002 27
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
How to request from NodeJS
• Official « ciscospark » SDK
• Community SDKs
• nmarus Sparky,
• drkchiloll/csco-spark
• …
… or choose with a ready-to-use SDK
https://github.com/nmarus/sparky https://www.npmjs.com/package/ciscospark
DEVNET-2002 28
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Continue Your Education in the DevNet Zone
• Take a Spark Learning Lab
1. Create Rooms, Adding Participants and Posting Messages
2. Learn to create a Webhook that will subscribe to new messages in a room
3. Register a new Spark app, and authenticate from a browser based app
https://developer.ciscospark.com/samples-tutorials.html
• Attend other Spark API sessions or take an instructor-driven Workshop
• DEVNET-2020: [Workshop] Working with Spark APIs
• DEVNET-2021: Spark API Authentication - Bots and Oauth
• DEVNET-2025: [Workshop] Build a Multi-Function iPaaS Application Using Python
• DEVNET-3002: [Workshop] Tour the DevNet Quiz App (Spark & Tropo Integration)
• BRKDEV-2004: Cloud Integration Platform Use-Cases and Coding Walk-Through
DEVNET-2002 29
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Continue Your Education in the DevNet Zone
• Take the DevNet « Coding Track »
• DEVNET-1001: Coding 101, Introduction to REST APIs
• DEVNET-1060: Intro to API Authentication Types (Oauth, token HTTP Basic)
• DEVNET-1080: Introduction to Git
• DEVNET-2002: Coding 102, REST API Basics using Spark
• DEVNET-2003: Coding 102, REST API Basics using APIC-EM
• DEVNET-2006: Coding 103, Deep Dive on JSON & more Python
• Meet the Experts at the Demo Pods
• Become a DevNet Community member www.developer.cisco.com
DEVNET-2002 30
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Continue Your Education
• Demos in the Cisco campus
• Walk-in Self-Paced Labs
• Lunch & Learn
• Meet the Engineer 1:1 meetings
• Related sessions
DEVNET-2002 31
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Complete Your Online Session Evaluation
Don’t forget: Cisco Live sessions will be available
for viewing on-demand after the event at
CiscoLive.com/Online
• Give us your feedback to be
entered into a Daily Survey
Drawing. A daily winner will
receive a $750 Amazon gift card.
• Complete your session surveys
through the Cisco Live mobile
app or from the Session Catalog
on CiscoLive.com/us.
DEVNET-2002 32
Thank you
@CiscoSparkDev
@CiscoDevNet
Coding 102 REST API Basics Using Spark

More Related Content

What's hot (20)

PPTX
How to Contribute to Ansible
Cisco DevNet
 
PPTX
Cisco's Open Device Programmability Strategy: Open Discussion
Cisco DevNet
 
PPTX
UCS Management APIs A Technical Deep Dive
Cisco DevNet
 
PPTX
Device Programmability with Cisco Plug-n-Play Solution
Cisco DevNet
 
PPTX
Open Device Programmability: Hands-on Intro to RESTCONF (and a bit of NETCONF)
Cisco DevNet
 
PPTX
Building a WiFi Hotspot with NodeJS: Cisco Meraki - ExCap API
Cisco DevNet
 
PPTX
DevNet Express - Spark & Tropo API - Lisbon May 2016
Cisco DevNet
 
PPTX
DevNet @TAG - Spark & Tropo APIs - Milan/Rome May 2016
Cisco DevNet
 
PDF
Webex APIs for Administrators - DEVNET_2610 - Cisco Live 2019
Cisco DevNet
 
PPTX
Javascript Essentials - Cisco Live Barcelona 2019
Cisco DevNet
 
PPTX
Webex APIs for Admins - Cisco Live Orlando 2018 - DEVNET-3610
Cisco DevNet
 
PDF
Webex Devices xAPI - DEVNET_2071 - Cisco Live - San Diego 2019
Cisco DevNet
 
PPTX
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
Cisco DevNet
 
PDF
Swiss IPv6 Council: The Cisco-Journey to an IPv6-only Building
Digicomp Academy AG
 
PPTX
NetDevOps for the Network Dude: How to get started with API's, Ansible and Py...
Cisco DevNet
 
PPTX
Chatbots 101: design, code, deploy - Cisco Live Orlando 2018 - DEVNET-2896
Cisco DevNet
 
PPTX
Integrated, Automated Video Room Systems - Webex Devices - Cisco Live Orlando...
Cisco DevNet
 
PPTX
Meeting rooms are talking! are you listening?
Cisco DevNet
 
PDF
Présentation cisco aci in action fundamentals - fcouderc - v6
Dig-IT
 
PPTX
API Deep Dive: APIC EM Rest API
Cisco DevNet
 
How to Contribute to Ansible
Cisco DevNet
 
Cisco's Open Device Programmability Strategy: Open Discussion
Cisco DevNet
 
UCS Management APIs A Technical Deep Dive
Cisco DevNet
 
Device Programmability with Cisco Plug-n-Play Solution
Cisco DevNet
 
Open Device Programmability: Hands-on Intro to RESTCONF (and a bit of NETCONF)
Cisco DevNet
 
Building a WiFi Hotspot with NodeJS: Cisco Meraki - ExCap API
Cisco DevNet
 
DevNet Express - Spark & Tropo API - Lisbon May 2016
Cisco DevNet
 
DevNet @TAG - Spark & Tropo APIs - Milan/Rome May 2016
Cisco DevNet
 
Webex APIs for Administrators - DEVNET_2610 - Cisco Live 2019
Cisco DevNet
 
Javascript Essentials - Cisco Live Barcelona 2019
Cisco DevNet
 
Webex APIs for Admins - Cisco Live Orlando 2018 - DEVNET-3610
Cisco DevNet
 
Webex Devices xAPI - DEVNET_2071 - Cisco Live - San Diego 2019
Cisco DevNet
 
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
Cisco DevNet
 
Swiss IPv6 Council: The Cisco-Journey to an IPv6-only Building
Digicomp Academy AG
 
NetDevOps for the Network Dude: How to get started with API's, Ansible and Py...
Cisco DevNet
 
Chatbots 101: design, code, deploy - Cisco Live Orlando 2018 - DEVNET-2896
Cisco DevNet
 
Integrated, Automated Video Room Systems - Webex Devices - Cisco Live Orlando...
Cisco DevNet
 
Meeting rooms are talking! are you listening?
Cisco DevNet
 
Présentation cisco aci in action fundamentals - fcouderc - v6
Dig-IT
 
API Deep Dive: APIC EM Rest API
Cisco DevNet
 

Viewers also liked (13)

PDF
SpringOne 2016 in a nutshell
Jeroen Resoort
 
PPTX
L08 Data Source Layer
Ólafur Andri Ragnarsson
 
PPTX
Cisco CSR1000V, VMware, and RESTful APIs
Private
 
PDF
SDN_NFV_Course
Sergio Calandra
 
PPTX
Cisco application infrastracture controller (apic) billyjones
Billy jones Monarquia
 
POTX
DEVNET-1126 APIC-EM API
Cisco DevNet
 
PDF
WorkShop SDN / ACI - Jeudi 12 Février 2015
Dig-IT
 
PPTX
How to Monitor Application Performance in a Container-Based World
Ken Owens
 
PPTX
DEVNET-1114 Automated Management Using SDN/NFV
Cisco DevNet
 
PDF
DEVNET-2002 Coding 201: Coding Skills 201: Going Further with REST and Python...
Cisco DevNet
 
PDF
Introduction to ACI APIs
Cisco DevNet
 
PPTX
SDN 101: Software Defined Networking Course - Sameh Zaghloul/IBM - 2014
SAMeh Zaghloul
 
SpringOne 2016 in a nutshell
Jeroen Resoort
 
L08 Data Source Layer
Ólafur Andri Ragnarsson
 
Cisco CSR1000V, VMware, and RESTful APIs
Private
 
SDN_NFV_Course
Sergio Calandra
 
Cisco application infrastracture controller (apic) billyjones
Billy jones Monarquia
 
DEVNET-1126 APIC-EM API
Cisco DevNet
 
WorkShop SDN / ACI - Jeudi 12 Février 2015
Dig-IT
 
How to Monitor Application Performance in a Container-Based World
Ken Owens
 
DEVNET-1114 Automated Management Using SDN/NFV
Cisco DevNet
 
DEVNET-2002 Coding 201: Coding Skills 201: Going Further with REST and Python...
Cisco DevNet
 
Introduction to ACI APIs
Cisco DevNet
 
SDN 101: Software Defined Networking Course - Sameh Zaghloul/IBM - 2014
SAMeh Zaghloul
 
Ad

Similar to Coding 102 REST API Basics Using Spark (20)

PPTX
DevNet 1056 WIT Spark API and Chat Bot Workshop
Tessa Mero
 
PPTX
Advanced Postman for Better APIs - Web Summit 2018 - Cisco DevNet
Cisco DevNet
 
PPTX
Steve Sfartz - How to embed Messaging and Video in your apps - Codemotion Mil...
Codemotion
 
PPTX
Embedding Messages and Video Calls in your apps
Cisco DevNet
 
PDF
Build advanced chat bots - Steve Sfartz - Codemotion Amsterdam 2017
Codemotion
 
PPTX
Webex APIs for Administrators - CL20B - DEVNET-2610
Cisco DevNet
 
PPTX
DevNetCreate Workshop - build a react app - React crash course
Cisco DevNet
 
PPTX
From ZERO to REST in an hour
Cisco DevNet
 
PPTX
Docs as Code: Publishing Processes for API Experiences
Anne Gentle
 
PPTX
Hackathon Poste Mobile 2016 Cisco Roma @TAG TalentGardenIT
Cisco DevNet
 
PDF
Build advanced Voice Assistants and Chat Bots - Stève Sfartz - Codemotion Mil...
Codemotion
 
PDF
Embed Spark calling SDK in Your App - Olivier PROFFIT - Cisco Live Berlin 2017
Cisco
 
PDF
Building advanced Chats Bots and Voice Interactive Assistants - Stève Sfartz ...
Codemotion
 
PPTX
Cisco Spark the Industry Challenge
Stefanie Maccarone
 
PPTX
Customizing Cisco Collaboration Devices - CL20B - DEVNET-2071
Cisco DevNet
 
PPTX
It’s All About Developers. Discover Cisco DevNet. - Jason Goecke - Codemotion...
Codemotion
 
PPTX
DeveloperWeek2018 - Let's Build a Chatbot
Tessa Mero
 
PPTX
Apic dc api deep dive
Cisco DevNet
 
PPTX
BEST REST in OpenStack
Vikram G Hosakote
 
PDF
IoT to Human interactions - Stève Sfartz - Codemotion Milan 2016
Codemotion
 
DevNet 1056 WIT Spark API and Chat Bot Workshop
Tessa Mero
 
Advanced Postman for Better APIs - Web Summit 2018 - Cisco DevNet
Cisco DevNet
 
Steve Sfartz - How to embed Messaging and Video in your apps - Codemotion Mil...
Codemotion
 
Embedding Messages and Video Calls in your apps
Cisco DevNet
 
Build advanced chat bots - Steve Sfartz - Codemotion Amsterdam 2017
Codemotion
 
Webex APIs for Administrators - CL20B - DEVNET-2610
Cisco DevNet
 
DevNetCreate Workshop - build a react app - React crash course
Cisco DevNet
 
From ZERO to REST in an hour
Cisco DevNet
 
Docs as Code: Publishing Processes for API Experiences
Anne Gentle
 
Hackathon Poste Mobile 2016 Cisco Roma @TAG TalentGardenIT
Cisco DevNet
 
Build advanced Voice Assistants and Chat Bots - Stève Sfartz - Codemotion Mil...
Codemotion
 
Embed Spark calling SDK in Your App - Olivier PROFFIT - Cisco Live Berlin 2017
Cisco
 
Building advanced Chats Bots and Voice Interactive Assistants - Stève Sfartz ...
Codemotion
 
Cisco Spark the Industry Challenge
Stefanie Maccarone
 
Customizing Cisco Collaboration Devices - CL20B - DEVNET-2071
Cisco DevNet
 
It’s All About Developers. Discover Cisco DevNet. - Jason Goecke - Codemotion...
Codemotion
 
DeveloperWeek2018 - Let's Build a Chatbot
Tessa Mero
 
Apic dc api deep dive
Cisco DevNet
 
BEST REST in OpenStack
Vikram G Hosakote
 
IoT to Human interactions - Stève Sfartz - Codemotion Milan 2016
Codemotion
 
Ad

More from Cisco DevNet (12)

PPTX
Application Visibility and Experience through Flexible Netflow
Cisco DevNet
 
PPTX
NETCONF & YANG Enablement of Network Devices
Cisco DevNet
 
PDF
Choosing PaaS: Cisco and Open Source Options: an overview
Cisco DevNet
 
PDF
Doing Business with Tropo
Cisco DevNet
 
PDF
Introduction to the DevNet Sandbox and IVT
Cisco DevNet
 
PDF
Introduction to Fog
Cisco DevNet
 
PDF
CSTA - Cisco Security Technical Alliances, New Ecosystem Program Built on the...
Cisco DevNet
 
PDF
Flare: an overview
Cisco DevNet
 
PDF
Enabling Fast IT using Containers, Microservices and DAVROS models: an overview
Cisco DevNet
 
PDF
Cisco Managed Private Cloud in Your Data Center: Public cloud experience on ...
Cisco DevNet
 
PDF
Starting the DevOps Train
Cisco DevNet
 
PDF
Getting Started with OpenStack
Cisco DevNet
 
Application Visibility and Experience through Flexible Netflow
Cisco DevNet
 
NETCONF & YANG Enablement of Network Devices
Cisco DevNet
 
Choosing PaaS: Cisco and Open Source Options: an overview
Cisco DevNet
 
Doing Business with Tropo
Cisco DevNet
 
Introduction to the DevNet Sandbox and IVT
Cisco DevNet
 
Introduction to Fog
Cisco DevNet
 
CSTA - Cisco Security Technical Alliances, New Ecosystem Program Built on the...
Cisco DevNet
 
Flare: an overview
Cisco DevNet
 
Enabling Fast IT using Containers, Microservices and DAVROS models: an overview
Cisco DevNet
 
Cisco Managed Private Cloud in Your Data Center: Public cloud experience on ...
Cisco DevNet
 
Starting the DevOps Train
Cisco DevNet
 
Getting Started with OpenStack
Cisco DevNet
 

Recently uploaded (20)

PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 

Coding 102 REST API Basics Using Spark

  • 1. Coding 102 REST API Basics using Spark David STAUDT, Developer Evangelist, [email protected] Stève SFARTZ, API Evangelist, [email protected] DEVNET-2002
  • 2. • REST API Basics • A tour of Cisco Spark API • Interactive Documentation Hands-on • Postman Hands-on • Javascript examples • Pre-requisites • You know how to forge API requests with Postman (or a similar REST client) • If not, attend DEVNET-1001: Coding 101- Introduction to REST APIs Agenda
  • 3. REST API Basics Coding 101 Prerequisites – DEVNET1001
  • 4. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public What is so great about REST? same concept, many Cisco APIs Easy to Build Web apps Mobile apps M2M, Bots… REST API DEVNET-2002 4
  • 5. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Terminology of a REST API query GET /../repos?page=1 HTTP/1.1 accept: application/json HTTP 200 OK browser api.github.com:443 method path protocol status code https://api.github.com/users/CiscoDevNet/repos?page=1&per_page=2 headers URL: response body HTTP request HTTP response api endpoint JSON payload parameters DEVNET-2002 5
  • 6. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public http://getpostman.com • Want to code along? Install POSTMAN now • Free tool to forge API requests, examine responses DEVNET-2002 6
  • 7. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public method url request headers status code response headers content-type response body query parameters DEVNET-2002 7
  • 8. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public JSON syntax • square brackets for lists • curly braces for objects • name/value pairs for properties, separated by commas • pick an online editor • http://codebeautify.org/jsonviewer http://www.jsoneditoronline.org DEVNET-2002 8
  • 9. Cisco Spark for Developers A tour of Cisco Spark APIs
  • 10. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Cisco Spark Secure & Open Complete & Simple Spark for Developers User Integrations, APIs/SDKs, etc. Spark Hybrid Services Cloud + Prem Partner Services Interconnect Message Meeting Call DEVNET-2002 10
  • 11. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public ‘Your App’ now with Cisco Collab! Spark APIs Extend Cisco Collaboration Cloud GET POST DELETE PUT /Rooms /Memberships /Messages /Teams /People DEVNET-2002 11DEVNET-2002 11 /Webhooks
  • 12. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Cisco Spark API v1 (July 2016) /People /Rooms /Membership /Messages /Teams /Webhooks List People List Rooms List Memberships List Messages List Teams List Webhooks Create a Room Create a Membership Create a Message Create a Team Create a Webhook Get Person Details Get Room details Get Membership details Get Message details Get Team details Get Webhook details Update a Room Update a Membership Update a Team Update a Webhook Delete a Room Delete a Membership Delete a Message Delete a Team Delete a Webhook GET POST DELETE PUT DELETE DELETE DELETE PUT PUT POST POST POST GET GET GET GET GET GET GET GETGET DEVNET-2002 12 DELETE PUT POST GET GET
  • 13. Hands on list your Spark Rooms with the Interactive Documentation
  • 14. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Developer Portal Interactive API documentation Client SDKs developer.ciscospark.com 24/7 Dev Support DEVNET-2002 14
  • 15. 15
  • 16. 16
  • 17. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Hands-on Instructions • Go to « List Rooms » documentation on the Developer Portal https://developer.ciscospark.com/resource-rooms.html • Login: and Turn « Test Mode » on: • Run the query: 17
  • 18. Hands on add a Message to a Room with Postman
  • 19. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Demo : list Rooms from Postman DEVNET-2002
  • 20. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco PublicDEVNET-2002 Hands on Import the Postman collection bit.ly/DEVNET2002
  • 21. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Hands on • Get your Cisco Spark Token from developer.ciscospark.com • Fill in the Authentication Header • Authorization : Bearer YOUR_SPARK_TOKEN • List some Rooms you are a member of Add a Message to a Room with Postman 21
  • 22. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Hands on • Pick a Room identifier « RoomId » Add a Message to a Room with Postman 22DEVNET-2002
  • 23. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Hands on • Forge a POST request to create a message • API documentation : https://developer.ciscospark.com/endpoint-messages-post.html Add a Message to a Room with Postman DEVNET-2002 23
  • 24. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public POSTED !!! • 200 OK • Check Message Id & attachments DEVNET-2002 24
  • 25. Cisco Spark for Developers Spark API calls in Javascript
  • 26. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public How to request from Javascript • A benefit of REST is that you can invoke Spark from any language • Hand code with your favorite HTTP client library • Or generate code from Postman • OAuth 2 to inject user API token Do It Yourself … with Postman code assistants DEVNET-2002 26
  • 27. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public How to request from NodeJS 1. Generate a nodejs skeleton from Postman, 2. Run from the command line Do It Yourself … with Postman code assistants DEVNET-2002 27
  • 28. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public How to request from NodeJS • Official « ciscospark » SDK • Community SDKs • nmarus Sparky, • drkchiloll/csco-spark • … … or choose with a ready-to-use SDK https://github.com/nmarus/sparky https://www.npmjs.com/package/ciscospark DEVNET-2002 28
  • 29. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Continue Your Education in the DevNet Zone • Take a Spark Learning Lab 1. Create Rooms, Adding Participants and Posting Messages 2. Learn to create a Webhook that will subscribe to new messages in a room 3. Register a new Spark app, and authenticate from a browser based app https://developer.ciscospark.com/samples-tutorials.html • Attend other Spark API sessions or take an instructor-driven Workshop • DEVNET-2020: [Workshop] Working with Spark APIs • DEVNET-2021: Spark API Authentication - Bots and Oauth • DEVNET-2025: [Workshop] Build a Multi-Function iPaaS Application Using Python • DEVNET-3002: [Workshop] Tour the DevNet Quiz App (Spark & Tropo Integration) • BRKDEV-2004: Cloud Integration Platform Use-Cases and Coding Walk-Through DEVNET-2002 29
  • 30. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Continue Your Education in the DevNet Zone • Take the DevNet « Coding Track » • DEVNET-1001: Coding 101, Introduction to REST APIs • DEVNET-1060: Intro to API Authentication Types (Oauth, token HTTP Basic) • DEVNET-1080: Introduction to Git • DEVNET-2002: Coding 102, REST API Basics using Spark • DEVNET-2003: Coding 102, REST API Basics using APIC-EM • DEVNET-2006: Coding 103, Deep Dive on JSON & more Python • Meet the Experts at the Demo Pods • Become a DevNet Community member www.developer.cisco.com DEVNET-2002 30
  • 31. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Continue Your Education • Demos in the Cisco campus • Walk-in Self-Paced Labs • Lunch & Learn • Meet the Engineer 1:1 meetings • Related sessions DEVNET-2002 31
  • 32. © 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public Complete Your Online Session Evaluation Don’t forget: Cisco Live sessions will be available for viewing on-demand after the event at CiscoLive.com/Online • Give us your feedback to be entered into a Daily Survey Drawing. A daily winner will receive a $750 Amazon gift card. • Complete your session surveys through the Cisco Live mobile app or from the Session Catalog on CiscoLive.com/us. DEVNET-2002 32

Editor's Notes

  • #2: http://www.ciscolive.com/us/learn/sessions/session-catalog/?search=DEVNET-2002 Join this session to learn about REST principles and get hands on with Cisco Spark APIs. Throughout this session, we'll illustrate the REST APIs principles with Cisco Spark examples. You'll learn to forge your own REST API requests with Postman, understand rudiments of authentication, and get insights of programming in NodeJS, via instructor-driven demos. Pre-requisites : the participant knows to forge API requests with Postman, and/or attended the Coding 101 session
  • #6: The same HTTP principles that apply to the Web (HTML page) - apply to Web APIs Here ‘s what happens when you consume the github API, More concretely : you hit an Endpoint (here the host: github.com, port: 443), remember it is what HTTPS defaults to, the connection is established and the HTTP protocol is used as specified by the scheme, the resource path /CiscoDevNet is asked for, with a GET method, the web browser adds an Accept Header to the request because an HTML page is what it expects the server to return This is the request, now let’s look at the answer : the github server returns on the same channel a response with the statuts code 200 to tell everything went OK and it writes the JSON contents on the wire Now, we got this HTTP intrinsics, we’re ready to place the call over the wire with POSTMAN. -- ADVANCED DO : open Chrome, go to github, open Dev Toolbar, show what’s happening Several resources are being accessed To different endpoints And different types of Data are being sent and received. That’s the way the Web works, we issue HTTP calls, asking for resources. Then all you need to know to start building calls yourself.
  • #7: If you have not installed Postman, this is the last call. Go to getpostman.com, Click Chrome App for the purpose of this training
  • #8: Now let’s place our HTTP request to github.com Leave the GET method as is. Enter the URL of the resource. Press the Send button DO : open POSTMAN, issue the call https://github.com/CiscoDevNet Postman issues the HTTP call on your behalf, and shows the response transmitted by the Github service : statuts of 200 OK if everything went ok If you get 404, the URL is malformed The HTML page contents are placed in the Body Note that the HTML content-type specified by the server is also displayed If you encounter an issue, ask for assistance in the Spark room and sending a Snapshot of your work in Postman may be your best bet to get an hand from the team.
  • #9: Carrets for list of elements, Braces to describe an element, Contents can also be nested. See how JSON entry ‘s got a name which makes it easy to understand what’s received. Though, the API documentation can help when you’re wondering.
  • #11: Let’s break it down into the 3 elements. SPARK MESSAGING – is an easy to use, always connected, service built on the idea of VIRTUAL ROOMS with a excellent MOBILE EXPERIENCE. Messaging, content sharing and BASIC conferencing capabilities are now all in one place. These “rooms” reduce the need for other tools like email and SHAREPOINT that were not truly built to support these types of workers and workstyles. SPARK MEETINGS – People shouldn’t have to worry about what KIND OF MEETING they’re having. Video Rooms, home office, branch office, Driver’s seat, Airport…Face to Face Video, Voice, and Content Sharing from any DEVICE, any ROOM, and any WORK ENVIRONMENT. Leveraging the #1 Web collaboration tool WebEx. SPARK CALL – This is your phone system or PBX in the cloud. One-touch directory dialing, Single Number Reach, Single Voicemail from any device, anywhere. All delivered in a single experience and managed through a single Cloud Collaboration Management Portal. Cloud Collaboration Management provides a single tool for administration, entitlement, management and reporting for Cisco Spark and Cisco WebEx Building on these 3 ELEMENTS . Cisco Spark is an Open Platform with… Open APIs for application integrations and a playground for developers Partner Services provides inbound dialing, and PSTN connectivity And Hybrid Services for integrating Cloud Spark applications with existing on prem investments
  • #14: Note: that this is the only way to create a 1 person only room
  • #15: Use our open APIs, available through our site or as a JavaScript SDK Use our cloud APIs alone or in tandem to customize the way administrators and teams use Cisco Spark capabilities. Share all the cool integrations you create with us, so we can publicize it with our community. Utilize a 24/7 world-class support desk powered by Tropo to answer your questions and discuss your ideas. We will be enhancing our APIs and publishing new ones so check back often. Initial APIs: /People /Rooms /Messages /Memberships /Webhooks Note: this site is launching in a ‘preview’ mode with an initial API framework for partners and customers to leverage. We will transition from preview to GA once we have additional APIs and SDKs available in CY 2016.
  • #19: Note: that this is the only way to create a 1 person only room
  • #21: A Postman collection regroups a set of API requests You can save any requests you forge manually into a collection, group several requests and share your collections with Postman If you need to inject dynamic parameters such as API token you can inject them using the {{ variable }} notation. Note that it is also possible to share environments with Postman
  • #25: var settings = { "async": true, "crossDomain": true, "url": "https://api.ciscospark.com/v1/rooms?max=3&type=group", "method": "GET", "headers": { "authorization": "Bearer YOUR_SPARK_TOKEN", "cache-control": "no-cache",} } $.ajax(settings).done(function (response) { console.log(response); });
  • #27: Note that adding your Spark Token into a Web page is not something you want to do Rather have it dynamically injected
  • #29: https://www.npmjs.com/package/ciscospark https://github.com/drkchiloll/csco-spark https://github.com/nmarus/sparky