Documentation

API version 1

Chevereto API v1 (also known as Bridge API) allows to upload pictures as guest to your Chevereto powered website. is called bridge API because is pretty much the same as the API from Chevereto 2.X and is the transition to the future API v2.

API v1 doesn't have rate limiting but is affected by the Flood upload limits setted in your admin dashboard. Because of this, you should only use this API for your very own applications or scripts.

API key

API v1 works with a single API key that you can set at Dashboard > Settings > API.

API call

Request method

API v1 calls can be done using the POST or GET request methods but since GET request are limited by the maximum allowed length of an URL you should prefer the POST request method.

Request URL

http://mysite.com/api/1/<action>/

Parameters

Example call

GET http://mysite.com/api/1/upload/?key=12345&source=http://somewebsite/someimage.jpg&format=json

Note: Always use POST when uploading local files. Url encoding may alter the base64 source due to encoded characters or just by URL request length limit due to GET request.

API response

API v1 responses will vary depending on the format parameter:

When using JSON the response will have headers status codes to allow you to easily notice if the request was OK or not. It will also output the status_txt and status_code properties.

Example response (JSON)

{
		"status_code": 200,
		"success": {
			"message": "image uploaded",
			"code": 200
		},
		"image": {
			"name": "example",
			"extension": "png",
			"size": 53237,
			"width": 1151,
			"height": 898,
			"date": "2014-06-04 15:32:33",
			"date_gmt": "2014-06-04 19:32:33",
			"storage_id": null,
			"description": null,
			"nsfw": "0",
			"md5": "c684350d722c956c362ab70299735830",
			"storage": "datefolder",
			"original_filename": "example.png",
			"original_exifdata": null,
			"views": "0",
			"id_encoded": "L",
			"filename": "example.png",
			"ratio": 1.2817371937639,
			"size_formatted": "52 KB",
			"mime": "image/png",
			"bits": 8,
			"channels": null,
			"url": "http://127.0.0.1/images/2014/06/04/example.png",
			"url_viewer": "http://127.0.0.1/image/L",
			"thumb": {
				"filename": "example.th.png",
				"name": "example.th",
				"width": 160,
				"height": 160,
				"ratio": 1,
				"size": 17848,
				"size_formatted": "17.4 KB",
				"mime": "image/png",
				"extension": "png",
				"bits": 8,
				"channels": null,
				"url": "http://127.0.0.1/images/2014/06/04/example.th.png"
			},
			"medium": {
				"filename": "example.md.png",
				"name": "example.md",
				"width": 500,
				"height": 390,
				"ratio": 1.2820512820513,
				"size": 104448,
				"size_formatted": "102 KB",
				"mime": "image/png",
				"extension": "png",
				"bits": 8,
				"channels": null,
				"url": "http://127.0.0.1/images/2014/06/04/example.md.png"
			},
			"views_label": "views",
			"display_url": "http://127.0.0.1/images/2014/06/04/example.md.png",
			"how_long_ago": "moments ago"
		},
		"status_txt": "OK"
	}

Example response (txt)

http://127.0.0.1/images/2014/06/04/example.png

API user upload workaround

API V1 one doesn't have a way to upload images associated with a given user but Chevereto comes ready for route overriding and you can easily customize your own API that can accomplish this task. Copy the default app/routes/route.api.php file to something like app/routes/overrides/route.myapi.php folder. We will do our job in this new route.myapi.php file.

Change this:

CHV\Image::uploadToWebsite($source);

To this (replace jesse with the target username or user_id):

// This will upload images to 'jesse' account 
CHV\Image::uploadToWebsite($source, 'jesse');

By doing this the /myapi route (Custom API) will now upload images in the name of that user. If you want to use a different API key in this new customized API simply change this:

!G\timing_safe_compare(CHV\getSetting('api_v1_key'), $_REQUEST['key'])

To this:

!G\timing_safe_compare('NowThisIsAnotherAPIKEY!', $_REQUEST['key'])

By doing this you will be able to use the default API (/api) with one key and the customized API (/myapi) with another key.