Skip to content

API Assets

Anthony Blackshaw edited this page May 8, 2018 · 1 revision

API - Assets

The following list of API endpoints allow assets to be managed.

/

List assets for the current account.

  • q A query string that will filter the list of assets returned. The * character can be used as a wildcard, e.g *.jpg for find all files with the jpg extension.
  • type The type of asset to return can be file or image.
curl "http://hangar51.local/?api_key={api_key}&q={query}&type={asset_type}"

-

{
  "status": "success",
  "payload": {
    "assets": [
      {
        "created": "2016-03-27 14:20:01",
        "store_key": "file.bf6yfw.zip",
        "type": "file",
        "uid": "bf6yfw"
      }, {
        "created": "2016-03-27 14:27:44",
        "store_key": "image.lxfngl.jpg",
        "type": "image",
        "uid": "lxfngl"
      }
    ],
    "total_assets": 2t,
    "total_pages": 1
  }
}

/get

Get the details of an asset.

  • uid The 6 digit asset unique Id.
curl "http://hangar51.local/get?api_key={api_key}&uid={uid}"

-

{
  "status": "success",
  "payload": {
    "created": "2016-03-27 14:27:44",
    "ext": "jpg",
    "meta": {
      "filename": "image.jpg",
      "image": {
        "mode": "RGB",
        "size": [
          720,
          960
        ]
      },
      "length": 130793
    },
    "modified": "2016-03-27 14:27:44",
    "name": "image",
    "store_key": "image.lxfngl.jpg",
    "type": "image",
    "uid": "lxfngl",
    "variations": []
  }
}

/download

Download the asset.

  • uid The 6 digit asset unique Id.
curl "http://hangar51.local/download?api_key={api_key}&uid={uid}"

/upload [POST]

Upload an asset.

  • asset The file or image to store.
  • name A name for the asset (if not provided the file name will be used).
curl -F "[email protected]" "http://hangar51.local/upload?api_key={api_key}&name={name}"

-

{
  "status": "success",
  "payload": {
    "created": "2016-03-27 14:27:44",
    "ext": "jpg",
    "meta": {
      "filename": "image.jpg",
      "image": {
        "mode": "RGB",
        "size": [
          720,
          960
        ]
      },
      "length": 130793
    },
    "modified": "2016-03-27 14:27:44",
    "name": "image",
    "store_key": "image.lxfngl.jpg",
    "type": "image",
    "uid": "lxfngl",
    "variations": []
  }
}

/generate-variations [POST]

Generate one of more image variations for an image asset.

  • uid The 6 digit asset unique Id.
  • variations A dictionary of variations to generate for the asset in JSON format.
  • on_delivery Determines if the process should wait for the variation to be created or run the task in background and return straight away. The value should be 'wait' (the default) or 'peg_it' (it really doesn't matter what you send as an alternative to wait).
  • webhook A URL to call (using GET) once the variation has been generated. Only applicable if on_delivery is not set to wait and the task will run in the background. The webhook URL will be called with the folloing attributes:
    • account_name The name of the Hangar51 account.
    • asset The unique Id of the asset.
    • variations Details of the generated variations.
curl -d 'api_key={api_key}&uid={uid}&variations={variations}' http://hangar51.local/generate-variations

-

{
  "status": "success",
  "payload": {
    "thumb": {
      "ext": "webp",
      "meta": {
        "image": {
          "mode": "RGB",
          "size": [
            100,
            133
          ]
        },
        "length": 3004
      },
      "name": "thumb",
      "store_key": "image.lxfngl.thumb.j1l.webp",
      "version": "j1l"
    }
  }
}

/set-expires [POST]

Set the expiry date for an asset, once an asset expires it will be removed (along with any variations in the case of images).

  • expires If not specified the asset will be set to never expire, if specified the value must be set as Epoch time (number of seconds since 1 January 1970).
  • uid The 6 digit asset unique Id.
curl -d 'api_key={api_key}&uid={uid}' http://hangar51.local/set-expires

- 

{
  "status": "success"
}
Clone this wiki locally