cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1246
Views
0
Helpful
0
Comments
Shaun Roberts
Cisco Employee
Cisco Employee

Howdy out there in Automation Land! I hope everyone is getting ready for summer and enjoying those last few weeks of school before the kids run home for their summer break. I had a great response from the python comparison blog before so I decided to take another stab at it and do a more "complex" version. This version is going to aim at making API calls. We are no longer looking at just some basic coding examples, we are wanting to make calls to servers and handle the responses from those calls... so speaking of lots of calls... how about this movie poster?

 

theCallPoster.JPG

 

Little scary and a little exciting at the same time... right? Anyways, we are going to look at a couple of things and a couple of tools that will be vital to you writing API calls and handling them in both Python and Cisco Process Orchestrator.

 

So we will want to write an easy "GET" call and an easy "POST" call. I needed to fine something easy to execute against as well so I found this...

 

https://jsonplaceholder.typicode.com/

 

It is a great place to test some web calls against and make the most out of your testing. It is a fake web server that will return output to you. It is perfect for our demo here as you can copy exactly what I am doing and there is no authentication scheme needed to follow.

 

The other tools that I love for this are http://jsonpath.com/ for your json path query needs and the XML Tools plugin for https://notepad-plus-plus.org/ to deal with your XPath Query needs. This would both be useful, but more so if you are doing work in CPO.

 

Here is the "finished" code we will work on in the VOD:

 

import requests
##https://jsonplaceholder.typicode.com/## GET
##https://jsonplaceholder.typicode.com/posts?userId=1

parameters = {   'userId': '1'}
r = requests.get('https://jsonplaceholder.typicode.com/posts', params=parameters)
print(r)
print(r.text)
print(r.status_code)

## POST

body = {   'title':'my title',   'body': 'a small body',   'userId': 1}
r = requests.post('https://jsonplaceholder.typicode.com/posts', data=body)
print(r)
print(r.text)

 

 

 

 

See... pretty simple stuff but makes it easy for us to do a comparison between Python and CPO. Just like it was done before, simple code, can grow into something much better and more complex and hopefully will allow you to see and understand more in the CPO space.

 

Having said that... ONTO THE VIDEO:

 

https://cisco.webex.com/ciscosales/lsr.php?RCID=0602e0686af645cb80a2516d620771f5

 

Recording password: 93QpFjUR

 

If you have any questions or want more information... please comment/post below!

 

Standard End-O-Blog Disclaimer:

 

Thanks as always to all my wonderful readers and those who continue to stick with and use CPO. Big things are on the horizon and I hope that you will continue to use CPO and find great uses for it! If you have a really exciting automation story, please email me it! (see below) I would love to compile some stories and feature customers or individual stories in an upcoming blog!!!

 

AUTOMATION BLOG DISCLAIMER: As always, this is a blog and my (Shaun Roberts) thoughts on CPO and automation, my thoughts on best practices, and my experiences with the product and customers. The above views are in no way representative of Cisco or any of it's partners, etc. None of these views, etc are supported and this is not a place to find standard product support. If you need standard product support please do so via the current call in numbers on Cisco.com or email tac@cisco.com

 

Thanks and Happy Automating!!!

 

--Shaun Roberts

shaurobe@cisco.com

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: