kazoocon 2014 - introduction to kazoo apis!

55
PRESENTED BY: INTRODUCTION TO KAZOO APIs Sean & Ricky

Upload: james-solada

Post on 25-Dec-2014

1.570 views

Category:

Technology


7 download

DESCRIPTION

Kazoo APIs are an example of a restful web-service. They are APIs are provided over HTTP/HTTPS. Kazoo APIs mostly uses the JavaScript Object Notation (JSON) data format for most payloads!

TRANSCRIPT

Page 1: KazooCon 2014 - Introduction to Kazoo APIs!

PRESENTED BY:

INTRODUCTION TO KAZOO APIs

Sean & Ricky

Page 2: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

What is an API?

Page 3: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

ApplicationProgrammingInterface

Page 4: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

An API as a bolt.

Page 5: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

REST

Kazoo APIs are an example of a RESTFul web-service.

Page 6: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

HTTP/HTTPS

Kazoo APIs are provided over HTTP/HTTPS

Page 7: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

In most cases Kazoo APIs work just like a website!

Page 8: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

What do the HTTP requests do?

Page 9: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Resources

Resources are just “Things”.

Page 10: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Collections

Collections are just a group of resources of the same type.

Page 11: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

EntitiesEntities are a single instance of a resource.

Page 12: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

IDs

We use IDs to identify entities.

Page 13: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

But how do we tell the server what resources we want to

interact with?

Page 14: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Uniform Resource Identifiers (URIs)

http://test.2600hz.com:8000/v1/accounts/C1234/users/U3456

Page 15: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

URI – Uniform Resource Identifier

http://test.2600hz.com:8000/v1/accounts/C1234/users/U3456

Base URL = http://test.2600hz.com:8000

Page 16: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

URI – Uniform Resource Identifier http://test.2600hz.com:8000/v1/accounts/C1234/users/U3456

Base URL = http://test.2600hz.com:8000

/v1/

Page 17: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

URI – Uniform Resource Identifier http://test.2600hz.com:8000/v1/accounts/C1234/users/U3456

Base URL = http://test.2600hz.com:8000

/v1/

/v1/accounts/

Page 18: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

URI – Uniform Resource Identifier http://test.2600hz.com:8000/v1/accounts/C1234/users/U3456

Base URL = http://test.2600hz.com:8000

/v1/

/v1/accounts/

/v1/accounts/C1234/

Page 19: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

URI – Uniform Resource Identifier http://test.2600hz.com:8000/v1/accounts/C1234/users/U3456

Base URL = http://test.2600hz.com:8000

/v1/

/v1/accounts/

/v1/accounts/C1234/

/v1/accounts/C1234/users/

Page 20: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

URI – Uniform Resource Identifier http://test.2600hz.com:8000/v1/accounts/C1234/users/U3456

Base URL = http://test.2600hz.com:8000

/v1/

/v1/accounts/

/v1/accounts/C1234/

/v1/accounts/C1234/users/

/v1/accounts/C1234/users/U3456/

Page 21: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

How do we tell the server what to do with the resource

we identified?

Page 22: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

HTTP Verbs or Methods

GET - /v1/accounts/C1234/users/

PUT - /v1/accounts/C1234/devices/ + data payload

POST /v1/accounts/C1234/users/U1112 + data payload

DELETE - /v1/accounts/C1234/users/U1112

Page 23: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Verbs for interacting with collections

GET - /v1/accounts/C1234/users/

PUT - /v1/accounts/C1234/users/ + data payload

Page 24: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Verbs for interacting with entities

GET - /v1/accounts/C1234/users/U1112

POST /v1/accounts/C1234/users/U1112 + data payload

DELETE /v1/accounts/C1234/users/U1112

Page 25: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

HTTP Response codes

2xx - successful request!200 - means the request was successful 201 - Entity was created

4xx - you messed up!401 - unauthorized (check your auth token)404 - entity or endpoint doesn't exist.

5xx - server messed up!500 - generic server error

Page 26: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

HTTP headers

Headers are used to set parameters used in processing the request.

Example: X-Auth-Token: <your auth token> Content-Type: application/json

Page 27: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

What is the payload?

Page 28: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Payload

A payload is the representation of the resource we requested.

Page 29: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Kazoo APIs mostly uses the JavaScript Object Notation (JSON) data format for most payloads

{ “key” : “value”}

Page 30: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Key value pairs

“key” : “value”

Page 31: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Key example:

“key” : “value”

Page 32: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Value examples

“key” : “value”

Page 33: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

JSON Data Types:

“string_example” : “a string”,

“number_example” : 1,

“boolean_example” : true,

“null_example” : null,

“array_example” : [ “a string”, “a number” ],

“object_example” : { “some_key” : “some_value”, “other_key” : 1 }

Page 34: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

JSON BASE OBJECT

{ “key” : “value”}

Page 35: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Complex nested JSON example:

{ “level_one_object” : { “level_two_object” : { “level3_key” : “level3_value”, “level3_array” : [ “level4_value” ] }, “level_two_array” : [ “level3_value” ] }}

Page 36: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

In the API, we always have a “data” object which contains the payload.

{ “data” : { “parameters_for_resource” : “some value” } “metadata_stuff” : …}

Page 37: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Putting it all together.

Page 38: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Page 39: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Page 40: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Page 41: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Page 42: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

To recap.

Page 43: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

• The URI is a “noun” which Identifies a specific resource.

• The HTTP method is a “verb” which defines what type of action we want to take against the resource.

• The contents of the payload is a JSON object.

Page 44: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Ok, let’s play with the Kazoo APIs!!!

Page 45: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Tools for exploring Kazoo APIs

• Kazoo UI, Developer tools• Curl – Command Line Tool• Postman – Browser based.• SDKs (Software Development Kit)

Page 46: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Tools for exploring Kazoo APIs

• Kazoo UI, Developer tools http://kazooui.kazoocon.com

• Curl – Command Line Tool• Postman – Browser based.• SDKs (Software Development Kit)

Page 47: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Authentication TokensTemporary “Security tokens” used to authenticate clients.

credentials = an md5 hash of the string username:password echo -n “user:pass” | md5

PUT http://api.sandbox.2600hz.com:8000/v1/user_auth{ “data”: { “credentials” : “12345678”, “realm” : “your.realm.com” }} or { “data”: { “credentials” : “12345678”, “account_name” : “account_name”}}

PUT http://api.sandbox.2600hz.com:8000/v1/api_auth{ “data” : { “api_key” : “YOUR_API_KEY” }}

NOTE: you can get API key with GET -/v1/accounts/<Account_ID>/api_key

How to get one:

Page 48: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Tools for exploring Kazoo APIs

• Kazoo UI, Developer tools• Curl – Command Line Tool• Postman – Browser based.• SDKs (Software Development Kit)

Page 49: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Tools for exploring Kazoo APIs

• Kazoo UI, Developer tools• Curl – Command Line Tool• Postman – Browser based.• SDKs (Software Development Kit)

Page 50: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Tools for exploring Kazoo APIs

• Kazoo UI, Developer tools• Curl – Command Line Tool• Postman – Browser based.• SDKs (Software Development Kit)

Page 51: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

CreateNewAdminAccount

Page 52: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

CreateNewAdminUser

Page 53: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

PHP SDK example sign-up form.

Page 54: KazooCon 2014 - Introduction to Kazoo APIs!

#kazoocon14

Links

Github link for PHP SDK:https://github.com/2600hz/kazoo-php-sdk

Google Groups:https://groups.google.com/forum/#!forum/2600hz-devhttps://groups.google.com/forum/#!forum/2600hz-users

Sign-up page:http://userxxx.u.kazoocon.com/sign_up/gobblin/#ajax/signup.html

Page 55: KazooCon 2014 - Introduction to Kazoo APIs!

Thank You!

#kazoocon14