Getting Started with Cisco Spark REST-API

I want to access Cisco Spark with REST-API

Learning content is available on Cisco DevNet (https://developer.cisco.com/site/devnet/home/index.gsp) (DevNet> Collaboration> Spark for Developers has three Learning Labs) ..

It's carefully crafted, so if you follow the steps, you'll learn how to access Cisco Spark via REST-API using POSTMAN.

The next step here is to summarize how to change POSTMAN to Python.

Get Access Token

An Access Token is required to access Cisco Spark via REST-API. An Access Token is an authentication string given to an individual when registering with Cisco Spark. Get it in the following ways:

https://developer.ciscospark.com/ Access and log in.

If you log in successfully, an avatar (an icon with a human face) will be displayed in the upper right corner.

Click on the avatar to see the Access Token. Access Token is information that should never be known to others, so you need to be careful when handling it.

Experiment 1: Get a Room List from Cisco Spark

Reference: Cisco Spark API Reference (https://developer.ciscospark.com/endpoint-rooms-get.html)

You can run http GET under the following conditions:

Use requests to perform an HTTP GET in Python. The code is, for example:

import requests

access_token = 'Enter your Access Token here'

url = 'https://api.ciscospark.com/v1/rooms'
headers = {
    'Authorization' : 'Bearer ' + access_token,
    'Content-Type' : 'application/json'
}

r = requests.get(url, headers = headers)

print(r.json())

If you just want to retrieve the Room ID, change print (r.json ()) on the last line to:

for line in r.json()['items']:
    print line['id']

Experiment 2: Get Room Message from Cisco Spark

To get the Message, use the Room ID obtained in Experiment 1 and execute http GET under the following conditions:

Below is a sample script that displays the user's email ID and message:

# -*- coding: utf-8 -*-

import requests

urlr = 'https://api.ciscospark.com/v1/rooms'
urlm = 'https://api.ciscospark.com/v1/messages'
headers = {
    'Authorization' : 'Bearer ' + access_token,
    'Content-Type' : 'application/json'
}

r = requests.get(urlr, headers = headers)

for line in r.json()['items']:
    payload = {'roomId' : line['id']}
    print '################### Room: ', line['title']
    r2 = requests.get(urlm, headers = headers, params = payload)
    try:
        for mline in r2.json()['items']:
            try:
                print mline['personEmail'], '>>>', mline['text']
            except KeyError:
                pass
    except KeyError:
        pass

Recommended Posts

Getting Started with Cisco Spark REST-API
Getting started with Spark
Getting started with Android!
1.1 Getting Started with Python
Getting started with apache2
Getting Started with Golang 1
Getting Started with Django 1
Getting Started with Optimization
Getting Started with Golang 3
Getting Started with Numpy
Getting Started with Python
Getting Started with Pydantic
Getting Started with Golang 4
Getting Started with Jython
Getting Started with Django 2
Translate Getting Started With TensorFlow
Getting Started with Tkinter 2: Buttons
Getting Started with Go Assembly
Getting Started with PKI with Golang ―― 4
Getting Started with Python Django (1)
Getting Started with Python Django (4)
Getting Started with Python Django (3)
Getting Started with Python Django (6)
Getting Started with Django with PyCharm
Python3 | Getting Started with numpy
Getting Started with Python Django (5)
Getting Started with Python responder v2
Getting started with Sphinx. Generate docstring with Sphinx
Getting Started with Python Web Applications
Getting Started with Python for PHPer-Classes
Getting Started with Sparse Matrix with scipy.sparse
Getting Started with Julia for Pythonista
Getting started with USD on Windows
Getting Started with Python Genetic Algorithms
Getting started with Python 3.8 on Windows
Getting Started with Python for PHPer-Functions
Getting Started with CPU Steal Time
Getting Started with python3 # 1 Learn Basic Knowledge
Getting Started with Flask with Azure Web Apps
Getting Started with Python for PHPer-Super Basics
Getting started with Dynamo from Python boto
Getting Started with Lisp for Pythonista: Supplement
Getting Started with Heroku, Deploying Flask App
Getting Started with TDD with Cyber-dojo at MobPro
Grails getting started
Getting started with Python with 100 knocks on language processing
Getting Started with Drawing with matplotlib: Writing Simple Functions
Getting started with Keras Sequential model Japanese translation
[Translation] Getting Started with Rust for Python Programmers
Django Getting Started Part 2 with eclipse Plugin (PyDev)
Getting started with AWS IoT easily in Python
Getting Started with Python's ast Module (Using NodeVisitor)
Materials to read when getting started with Python
Settings for getting started with MongoDB in python
Django 1.11 started with Python3.6
Getting Started with python3 # 2 Learn about types and variables
Basket analysis with Spark (1)
Getting Started with pandas: Basic Knowledge to Remember First
Getting Started with Google App Engine for Python & PHP
Getting Started with Tensorflow-About Linear Regression Hypothesis and Cost
Get started with MicroPython