Cloudinary Blog

RESTful API for managing your website's images and other online assets

By Tal Lev-Ami
Different online services, websites and mobile applications have very different image management requirements. Despite the differences, the image management pipeline boils down to the same basic formula - upload the images, normalize them, store them and manipulate them to create derivatives (thumbnails, effects, watermarks, etc.). Afterwards, prepare them for delivery and make sure they are accessible to your users quickly and efficiently when browsing your website or using your mobile app.
 
When we set out to build Cloudinary, we envisioned a platform that could streamline an online service's entire asset management pipeline needs. We developed a simple yet powerful URL based API and made integration even simpler using client integration libraries for many web dev platforms and programming languages. It was a joy to see how each of our clients found new ways of utilizing our platform, hooking different API calls to solve scenarios we could barely imagine when Cloudinary was first conceived.
 
In the regular flow of web applications, this works perfectly. But sometimes, you'll want even more fine grained control over your online assets - browse through user uploaded images, find specific images, delete images, delete transformations and more. If you already tried Cloudinary, you probably know that you can use our Management Console for manually achieving such tasks via our web-based user interface. But as many of our customers told us and frequently requested, more control is sometimes required than what they can currently achieve manually.
 
Today, we've made another important step in making the Cloudinary platform even more customizable. 
 
Without further ado, we'd like to welcome Cloudinary's powerful new administrative API, an intuitive RESTful HTTP API for programmatically managing all of your Cloudinary hosted assets.
 

Supported Operations

When building the API, we did our best to cover all common management tasks:
  • Listing all uploaded images and raw files.
  • Receiving details and metadata for uploaded images, including timestamps, format, dimensions, etc.
  • Listing the derived images of uploaded images.
  • Finding all images that share a given tag.
  • Listing all transformations.
  • Listing tags.
  • Receiving transformation details.
  • Creating named transformations.
  • Updating an existing transformation.
  • Deleting images, raw files, derived images and transformations.
 

API Overview

The API is accessed using HTTPS to endpoints in the following format:
 
https://api.cloudinary.com/v1_1/:cloud_name/:action
 
For example, resource listing of the 'demo' account:
 
https://api.cloudinary.com/v1_1/demo/resources/images
 
Authentication is done using Basic Authentication over secure HTTP. Your Cloudinary API Key and API Secret are used for the authentication.
 
Request parameters are appended to the URL. The response is in a simple JSON snippet. Like any REST API, read-only requests are sent in HTTP GET while write requests are sent in PUT, POST and DELETE. 
 
For more details, check out our documentation page.
 
Our client libraries provide an easy to use wrapper for this URL-based API, utilizing your native programming language of choice. Request building and authentication are done automatically, and the JSON response is parsed and returned. 
 

Usage Examples

 
The following Ruby example lists all your Cloudinary hosted images:
Copy to clipboard
$ result = Cloudinary::Api.resources
=> {"resources"=>
  [{"public_id"=>"sample1", 
    "format"=>"png",
    "version"=>1349196740, 
    "resource_type"=>"image", 
    "type"=>"upload",
    "created_at"=>"2012-10-02T16:52:20Z",
    "bytes"=>71376, "width"=>261, "height"=>253,
    "url"=>
     "https://res.cloudinary.com/sam/image/upload/v1349196740/sample1.png",
    "secure_url"=>
     "https://d3jpl91pxevbkh.cloudfront.net/sam/image/upload/v1349196740/sample1.png"},
   {"public_id"=>"sample2", 
    "format"=>"png",
    "version"=>1349196732, 
    "resource_type"=>"image", 
    "type"=>"upload",
    "created_at"=>"2012-10-02T16:52:12Z",
    "bytes"=>133171, "width"=>278, "height"=>432,
    "url"=>
     "https://res.cloudinary.com/sam/image/upload/v1349196732/sample2.png",
    "secure_url"=>
     "https://d3jpl91pxevbkh.cloudfront.net/sam/image/upload/v1349196732/sample2.png"},
 
    ... 
],
 "next_cursor"=>"e39ef944e18cfda7deafa4aea96791e7"}
Here's the same example in PHP:
Copy to clipboard
require "cloudinary.php" ;
require "api.php" ;
$api = new \Cloudinary\Api();
$result = $api->resources();
Python:
Copy to clipboard
import cloudinary.api
result = cloudinary.api.resources()
And Node.js:
Copy to clipboard
var cloudinary = require('cloudinary');  
cloudinary.api.resources(function(result)  { console.log(result) });
By default, 10 results are returned in a single request. You can specify the max_results parameter if you want more results in a single request. You can use this in conjunction with the next_cursor parameter for paginating through all your assets.
 
The next example shows how to get the full details of a single uploaded image, including the list of its derived images:
Copy to clipboard
$ result = Cloudinary::Api.resource("sample1")
=> {"public_id"=>"sample1",
 "format"=>"png",
 "version"=>1349196740,
 "resource_type"=>"image",
 "type"=>"upload",
 "created_at"=>"2012-10-02T16:52:20Z",
 "bytes"=>71376, "width"=>261, "height"=>253,
 "url"=>
  "https://res.cloudinary.com/sam/image/upload/v1349196740/sample1.png",
 "secure_url"=>
  "https://d3jpl91pxevbkh.cloudfront.net/sam/image/upload/v1349196740/sample1.png",
 "next_cursor"=>"f329da74de2a9ac9cbf99d2a6bc147b8",
 "derived"=>
  [{"transformation"=>"c_fill,h_50,r_20,w_70",
    "format"=>"png",
    "bytes"=>7313,
    "id"=>"a3b44a715c63f7ee91f11fb20b97c5df",
    "url"=>
     "https://.../sam/image/upload/c_fill,h_50,r_20,w_70/v1349196740/sample1.png",
    "secure_url"=>
     "https://.../sam/image/upload/c_fill,h_50,r_20,w_70/v1349196740/sample1.png"},
   {"transformation"=>"c_fill,h_75,w_75/jpg",
    "format"=>"jpg",
    "bytes"=>2889,
    "id"=>"7c0ca85b966b928179ce336fa2a7d1f8",
    "url"=>
     "https://.../sam/image/upload/c_fill,h_75,w_75/v1349196740/sample1.jpg",
    "secure_url"=>
    "https://.../sam/image/upload/c_fill,h_75,w_75/v1349196740/sample1.jpg"}]}
And now, the same example in PHP
Copy to clipboard
$result = $api->resource("sample1");
Python:
Copy to clipboard
cloudinary.api.resource("sample1")
And Node.js:
Copy to clipboard
cloudinary.api.resource("sample1", function(result)  { console.log(result) })
One final example - getting the details of a single transformation, including a list of all images assigned to this transformation:
Copy to clipboard
$ result = Cloudinary::Api.transformation("c_fill,h_75,w_75/jpg")
 
=> {"name"=>"c_fill,h_75,w_75/jpg",
       "allowed_for_strict"=>false,
       "used"=>true,
        "info"=>[{"width"=>75, "height"=>75, "format"=>"jpg", "crop"=>"fill"}],
        "derived"=>
  [{"public_id"=>"sample1",
    "resource_type"=>"image",
    "type"=>"upload",
    "format"=>"jpg",
    "url"=>
     "https://.../sam/image/upload/c_fill,h_75,w_75/v1349196740/sample1.jpg",
    "secure_url"=>
     "https://.../sam/image/upload/c_fill,h_75,w_75/sample1/sample1.jpg",
    "bytes"=>2889,
    "id"=>"7c0ca85b966b928179ce336fa2a7d1f8"},
  ...
]}
As you can see, the new API is quite powerful. Using this API allows for full control of all uploaded raw files and images, fetched social profile pictures, generated transformations and more. 
 
For more examples and a full reference, see our detailed documentation.
 

Usage Limits 

You can use the new API quite extensively. We ask for that you keep your ongoing API requests to 500 per hour (12,000 daily) when using our Free plan. Subscribe to our Basic plan onward to increase the limit to 2000 calls per hour. If you require more flexible limits, don't hesitate to contact us.
 
For each API call, standard HTTP headers are returned with details on your current usage statistics, including your per-hour limit, remaining number of actions and the time the hourly count will be reset.
 
Here is how these headers might look like:
 
    X-FeatureRateLimit-Limit: 500
    X-FeatureRateLimit-Remaining: 499
    X-FeatureRateLimit-Reset: Wed, 03 Oct 2012 08:00:00 GMT
 
Note that our client libraries provide easy access to the returned limit headers. In Ruby for example:
Copy to clipboard
$ result = Cloudinary::Api.resource_types
 => {"resource_types"=>["image"]} 
$ result.rate_limit_allowed
 => 500 
$ result.rate_limit_reset_at
 => 2012-10-03 10:00:00 +0200 
$ result.rate_limit_remaining
 => 499  
 

Summary 

The new admin API is available for all our free and paid plans. It would be great if you try it out, and tell us what you think. 
We have interesting ideas on how to further enhance this new API. If your want to be in the loop, go ahead and subscribe to our blog or Like Cloudinary on Facebook, and receive our timely updates.

Recent Blog Posts

Generate Waveform Images from Audio with Cloudinary

This is a reposting of an article written by David Walsh. Check out his blog HERE!
I've been working a lot with visualizations lately, which is a far cry from your normal webpage element interaction coding; you need advanced geometry knowledge, render and performance knowledge, and much more. It's been a great learning experience but it can be challenging and isn't always an interest of all web developers. That's why we use apps and services specializing in complex tasks like Cloudinary: we need it done quickly and by a tool written by an expert.

Read more
Make All Images on Your Website Responsive in 3 Easy Steps

Images are crucial to website performance, but most still don't implement responsive images. It’s not just about fitting an image on the screen, but also making the the image size relatively rational to the device. The srcset and sizes options, which are your best hit are hard to implement. Cloudinary provides an easier way, which we will discuss in this article.

Read more

The Future of Audio and Video on the Web

By Prosper Otemuyiwa
The Future of Audio and Video on the Web

Web sites and platforms are becoming increasingly media-rich. Today, approximately 62 percent of internet traffic is made up of images, with audio and video constituting a growing percentage of the bytes.

Read more

Embed Images in Email Campaigns at Scale

By Sourav Kundu
Embed Images in Email Campaigns at Scale

tl;dr

Cloudinary is a powerful image hosting solution for email marketing campaigns of any size. With features such as advanced image optimization and on-the-fly image transformation, backed by a global CDN, Cloudinary provides the base for a seamless user experience in your email campaigns leading to increased conversion and performance.

Read more
Build the Back-End For Your Own Instagram-style App with Cloudinary

Github Repo

Managing media files (processing, storage and manipulation) is one of the biggest challenges we encounter as practical developers. These challenges include:

A great service called Cloudinary can help us overcome many of these challenges. Together with Cloudinary, let's work on solutions to these challenges and hopefully have a simpler mental model towards media management.

Read more

Build A Miniflix in 10 Minutes

By Prosper Otemuyiwa
Build A Miniflix in 10 Minutes

Developers are constantly faced with challenges of building complex products every single day. And there are constraints on the time needed to build out the features of these products.

Engineering and Product managers want to beat deadlines for projects daily. CEOs want to roll out new products as fast as possible. Entrepreneurs need their MVPs like yesterday. With this in mind, what should developers do?

Read more