40
June 3-5, 2014 | Berlin, Germany

AtlasCamp2014: Introducing the Confluence REST API

Embed Size (px)

DESCRIPTION

Confluence published the first version of its official, supported REST API in February. The new REST API makes it easy to create, retrieve and manipulate Confluence content with either Atlassian Connect or P2 plugins. Steve Lancashire, a senior developer on the API team, will give you a tour of its capabilities and key features, like new Content Property persistence, expansions to help you get what you need out of the API in a single request, and potential extensions to the API available with P2 plugins.

Citation preview

Page 1: AtlasCamp2014: Introducing the Confluence REST API

June 3-5, 2014 | Berlin, Germany

Page 2: AtlasCamp2014: Introducing the Confluence REST API

Steve Lancashire, Senior Developer - Confluence Platform, Atlassian

Introducing the Confluence REST

API

Page 3: AtlasCamp2014: Introducing the Confluence REST API

Confluence Platform

Tweet any questions using #confluenceREST

Page 4: AtlasCamp2014: Introducing the Confluence REST API

Confluence Platform Goal

Make Confluence a simple, fast, reliable product, and platform supporting content applications, for the next ten years. ”

Page 5: AtlasCamp2014: Introducing the Confluence REST API

Confluence Platform

Page 6: AtlasCamp2014: Introducing the Confluence REST API

Who are our “customers”?

Other Atlassian

Devs

Internal Confluence

Devs

Our Ecosystem

(you)

Page 7: AtlasCamp2014: Introducing the Confluence REST API

Remote APIs - the past

SOAP and Xml RPC

!

Json RPC

Prototype REST

(read only)Feature specific REST Resources

Page 8: AtlasCamp2014: Introducing the Confluence REST API

Many different APIs

• Developing a feature could end up using all of them!• RPC and SOAP ignores the architecture of the Web!• Incompatible representations between APIs!• No cross version stability for feature specific resources

Page 9: AtlasCamp2014: Introducing the Confluence REST API

Confluence REST API Tweet any questions using #confluenceREST

Page 10: AtlasCamp2014: Introducing the Confluence REST API

• Language agnostic!• Doesn’t ignore the architecture of the web!• cross version stability guarantees

Benefits of a REST API

Page 11: AtlasCamp2014: Introducing the Confluence REST API

Features of our REST API

• Default JSON representation!• Hypermedia inside entities!• Embed entities through expansions!• Common Content model

Page 12: AtlasCamp2014: Introducing the Confluence REST API

• Paginated, filterable list of content!• Content is any page, blogpost,

comment or attachment in Confluence!

• Initially terse, but accepts nested expansions!

• lets have a look at it

/rest/api/contentGET

Tooltip: The most readily available REST client

is your browser install a JSON formatting extension, like JSONView

for Chrome

Page 13: AtlasCamp2014: Introducing the Confluence REST API

DEMO - list content

https://confluence.atlassian.com/rest/api/content

Page 14: AtlasCamp2014: Introducing the Confluence REST API

• Retrieve a piece of content by id!• has a default set of expansions!• supports nested, dot separated

expansions!• example : confluence.atlassian.com/

rest/api/content/12

/api/content/{id}GET

Tooltip: The most readily available REST client

is your browser install a JSON formatting extension, like JSONView

for Chrome

Page 15: AtlasCamp2014: Introducing the Confluence REST API

Content Body Representations

STORAGE EDITOR (internal)

VIEW (read only)

WIKI (write only)

Page 16: AtlasCamp2014: Introducing the Confluence REST API

• Converts content representations from one representation to another!

• lets have a look at an example using cURL!

• you can find more about storage format on confluence.atlassian.com!!

!

!

…/contentbody/convert/{to}POST

Tooltip: cURL is a simple command line tool, there are some cUrl examples using

the new REST API on developer.atlassian.com

Page 17: AtlasCamp2014: Introducing the Confluence REST API

DEMO - Convert content

curl -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"value":"<ac:structured-macro ac:name=\"cheese\" />","representation":"storage"}' "http://localhost:8080/confluence/rest/api/contentbody/convert/view" | python mjson.tool

Page 18: AtlasCamp2014: Introducing the Confluence REST API

• Creates a new piece of content!• Similar required fields as creating

content in the Confluence Editor!• create from STORAGE, EDITOR

or WIKI content representations!• returns the new piece of content

with generated id

/api/content/POST

Tooltip: The REST API Browser on Atlassian Marketplace provides a useful UI for

exploring the REST API

Page 19: AtlasCamp2014: Introducing the Confluence REST API

DEMO - Creating Contenthttp://localhost:8080/confluence/plugins/servlet/restbrowser#/resource/api-content/POST !{ "title" : "Atlascamp 2014", "type" : "page", "body" : { "storage" : {"value" : "<p>Hi everyone</p>", “representation":"storage"} }, "space" : {"key":"DS"} }

Page 20: AtlasCamp2014: Introducing the Confluence REST API

• Modify and delete existing content!• Modifying requires an explicit version increment!• DELETE removes the content from the resource

and moves it to the trash

/api/content/{id}PUT / DELETE

Page 21: AtlasCamp2014: Introducing the Confluence REST API

DEMO - Updating Contenthttps://stevelan.jira-dev.com/wiki/plugins/servlet/restbrowser#/resource/api-content-id/PUT !{ "id":4685825, "type":"page", “body":{"storage": { "representation":"storage", "value":"<p>Hi to everyone else</p>“} }, "version":{"number":2} }

Page 22: AtlasCamp2014: Introducing the Confluence REST API

Content Properties A key / value store for the REST API

Page 23: AtlasCamp2014: Introducing the Confluence REST API

Content Properties

• Key / value store of properties on content!

• Store up to 32KB of JSON!• Great for Atlassian Connect

Page 24: AtlasCamp2014: Introducing the Confluence REST API

• Collection of properties on a piece of content!• GET to fetch all properties !• POST to create a new property!!

/api/content/{id}/propertyGET / POST

/api/content/{id}/property/arbitrary-key

Page 25: AtlasCamp2014: Introducing the Confluence REST API

• GET a particular property by specifying the key!• PUT the value to update!• DELETE removes the property

/api/content/{id}/property/{key}GET / PUT / DELETE

{!!! “key” : “arbitrary-key”, !!! “value” : { “random-json“: “data” } !!! ...!}

/api/content/{id}/property/arbitrary-key

Page 26: AtlasCamp2014: Introducing the Confluence REST API

DEMO - add a property

chrome://apps/

Page 27: AtlasCamp2014: Introducing the Confluence REST API

• spaces, child content, content history, labels!

• API Reference docs can be found via developer.atlassian.com!

• or google : confluence rest api docs

Plus lots more

Page 28: AtlasCamp2014: Introducing the Confluence REST API

• More small script examples on developer.atlassian.com

More examples

Page 29: AtlasCamp2014: Introducing the Confluence REST API

• Can extend the API with metadata!

• P2 plugins can surface their feature through the API!

• Implement ModelMetadataProvider interface

Extending the APIADVANCED TOPICS

Page 30: AtlasCamp2014: Introducing the Confluence REST API

• Capabilities API since Confluence 5.0!• provides api “feature” discovery!• confluence-content-api indicates the presence of the api

Migrating to the new APIADVANCED TOPICS

“application” : “confluence”, !“capabilities” : {! !! “confluence-content-api“: “/rest/api/content”,!!! ! … !}

/rest/capabilities

Page 31: AtlasCamp2014: Introducing the Confluence REST API

So what is next?

Page 32: AtlasCamp2014: Introducing the Confluence REST API

CQL Confluence Query Language for the REST API

Page 33: AtlasCamp2014: Introducing the Confluence REST API

• Query language for finding content !• Similar to JQL / SQL where clause!• API only, not user facing!• i.e.: space in (DEV, DOCS) and title ~ “rest api”!

What is CQL?

Page 34: AtlasCamp2014: Introducing the Confluence REST API

• Flexible!• Fast!• Familiar

CQL Benefits

Page 35: AtlasCamp2014: Introducing the Confluence REST API

Functions!• similar to JQL functions!• i.e. creator = currentUser()

ExtensibilityCQL BENEFITS

Fields!• plugins can add indexed fields to the CQL grammar!• i.e. macro = cheese

Page 36: AtlasCamp2014: Introducing the Confluence REST API

!

• https://pug.jira.com/wiki/plugins/cqlsearch/cql.action

Demo

Page 37: AtlasCamp2014: Introducing the Confluence REST API

Before and After

Page 38: AtlasCamp2014: Introducing the Confluence REST API

1.0 - MVP!• Existing fields in the index!

• Extensible fields and functions!

• Operators : =, !=, ~, !~, <=, >=, IN, NOT IN, EMPTY

• 1.1 Expand the index!• Indexing service for plugins!

• Additional fields from plugin data stored in AO!

• Content properties

CQL Roadmap

Page 39: AtlasCamp2014: Introducing the Confluence REST API

Questions Tweet any questions using #confluenceREST

Page 40: AtlasCamp2014: Introducing the Confluence REST API

Thank you Go build something awesome!