Tổng đài hỗ trợ - 
1900 6750
( 7:00 - 22:00 )

Asset

Assets là các file riêng biệt tạo nên theme của shop.

Assets có thể là bất cứ loại file nào: từ file ảnh, file style tới các file code thêm. Assets có thể dễ dàng được thêm vào, thay đổi hay xóa đi từ theme của shop.

Bạn có thể làm gì với Asset?

Sapo API cho phép bạn thực hiện các thao tác sau với tài nguyên Asset. Các phiên bản chi tiết hơn của những thao tác này có thể có:

Các thuộc tính của Asset

id
{ "id" : "123456" }

Số duy nhất định danh Asset.

content_type
{ "content_type" : "image/gif" }

Kiểu MIME của nội dung, bao gồm type và subtype của the asset.

created_on
{ "created_on" : "2010-07-12T15:31:50Z" }

Ngày tạo Asset. API trả về kết quả theo định dạng chuẩn ISO 8601.

key
{ "key" : "assets/bg-body-green.gif" }

Đường dẫn tới asset trong shop. Ví dụ, asset bg-body-green.gif được đặt trong thư mục assets.

public_url
{ "public_url" : "bizweb.dktcdn.net/assets/bg.gif?1" }

Đường dẫn public của asset.

size
{ "size" : 1542 }

Dung lượng asset tính theo byte.

theme_id
{ "theme_id" : 828155753 }

Số duy nhất định danh theme.

modified_on
{ "modified_on" : "2010-07-12T15:31:50Z" }

Thời gian asset được update lần cuối. API trả về kết quả theo định dạng chuẩn ISO 8601.

value
{ "value" : "<img src='backsoon-postit.png'>" }

Asset được thêm vào.

Endpoints

GET/admin/themes/828155753/assets.json

Liệt kê các Theme Asset chỉ trả về dữ liệu metadata của các Asset. Bạn phải lấy về từng Asset để lấy dữ liệu của chúng.

fields

danh sách các trường trong kết quả trả về, cách nhau bởi dấu phẩy

Lấy danh sách các Theme Asset

GET /admin/themes/#{id}/assets.json
Xem kết quả
HTTP/1.1 200 OK
{
  "assets": [
    {
      "key": "assets\/bg-body-green.gif",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/bg-body-green.gif?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "image\/gif",
      "size": 1542,
      "theme_id": 828155753
    },
    {
      "key": "assets\/bg-body-orange.gif",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/bg-body-orange.gif?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "image\/gif",
      "size": 1548,
      "theme_id": 828155753
    },
    {
      "key": "assets\/bg-body-pink.gif",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/bg-body-pink.gif?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "image\/gif",
      "size": 1562,
      "theme_id": 828155753
    },
    {
      "key": "assets\/bg-body.gif",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/bg-body.gif?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "image\/gif",
      "size": 1571,
      "theme_id": 828155753
    },
    {
      "key": "assets\/bg-content.gif",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/bg-content.gif?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "image\/gif",
      "size": 134,
      "theme_id": 828155753
    },
    {
      "key": "assets\/bg-footer.gif",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/bg-footer.gif?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "image\/gif",
      "size": 1434,
      "theme_id": 828155753
    },
    {
      "key": "assets\/bg-main.gif",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/bg-main.gif?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "image\/gif",
      "size": 297,
      "theme_id": 828155753
    },
    {
      "key": "assets\/bg-sidebar.gif",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/bg-sidebar.gif?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "image\/gif",
      "size": 124,
      "theme_id": 828155753
    },
    {
      "key": "assets\/shop.css",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/shop.css?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "text\/css",
      "size": 14058,
      "theme_id": 828155753
    },
    {
      "key": "assets\/shop.css.bwt",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/shop.css.bwt?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "text\/x-liquid",
      "size": 14675,
      "theme_id": 828155753
    },
    {
      "key": "assets\/shop.js",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/shop.js?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "application\/javascript",
      "size": 348,
      "theme_id": 828155753
    },
    {
      "key": "assets\/sidebar-devider.gif",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/sidebar-devider.gif?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "image\/gif",
      "size": 1016,
      "theme_id": 828155753
    },
    {
      "key": "assets\/sidebar-menu.jpg",
      "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/sidebar-menu.jpg?7364251289859092031",
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "image\/jpeg",
      "size": 1609,
      "theme_id": 828155753
    },
    {
      "key": "config\/settings_data.json",
      "public_url": null,
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "application\/json",
      "size": 4570,
      "theme_id": 828155753
    },
    {
      "key": "config\/settings_schema.json",
      "public_url": null,
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "application\/json",
      "size": 4570,
      "theme_id": 828155753
    },
    {
      "key": "layout\/theme.bwt",
      "public_url": null,
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "text\/x-liquid",
      "size": 3252,
      "theme_id": 828155753
    },
    {
      "key": "templates\/article.bwt",
      "public_url": null,
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "text\/x-liquid",
      "size": 2486,
      "theme_id": 828155753
    },
    {
      "key": "templates\/blog.bwt",
      "public_url": null,
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "text\/x-liquid",
      "size": 786,
      "theme_id": 828155753
    },
    {
      "key": "templates\/cart.bwt",
      "public_url": null,
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "text\/x-liquid",
      "size": 2047,
      "theme_id": 828155753
    },
    {
      "key": "templates\/collection.bwt",
      "public_url": null,
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "text\/x-liquid",
      "size": 946,
      "theme_id": 828155753
    },
    {
      "key": "templates\/index.bwt",
      "public_url": null,
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "text\/x-liquid",
      "size": 1068,
      "theme_id": 828155753
    },
    {
      "key": "templates\/page.bwt",
      "public_url": null,
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "text\/x-liquid",
      "size": 147,
      "theme_id": 828155753
    },
    {
      "key": "templates\/product.bwt",
      "public_url": null,
      "created_on": "2010-07-12T15:31:50Z",
      "modified_on": "2010-07-12T15:31:50Z",
      "content_type": "text\/x-liquid",
      "size": 2796,
      "theme_id": 828155753
    }
  ]
}
GET/admin/themes/828155753/assets.json

Có một vài bucket khác nhau để lưu trữ các loại Asset khác nhau, mỗi cái tương ứng với một folder trong file zip của theme: layouts, templates, and assets. Một key đầy đủ của Asset luôn bắt đầu bằng tên bucket và đường dẫn sẽ như sau layouts/theme.bwt hoặc assets/bg-body.gif.

fields

danh sách các trường trong kết quả trả về, cách nhau bởi dấu phẩy

Lấy một file liquid

GET /admin/themes/#{id}/assets.json?key=templates/index.bwt&theme_id=828155753
Xem kết quả
HTTP/1.1 200 OK
{
  "asset": {
    "key": "templates\/index.bwt",
    "public_url": null,
    "value": "<!-- LIST 3 PER ROW -->\n<h2>Featured Products<\/h2>\n<table id=\"products\" cellspacing=\"0\" cellpadding=\"0\">\n{% tablerow product in collections.frontpage.products cols:3  %}\n   <a href=\"{{product.url}}\">{{ product.featured_image | product_img_url: 'small' | img_tag }}<\/a>\n   <h3><a href=\"{{product.url}}\">{{product.title}}<\/a><\/h3>\n   <ul class=\"attributes\">\n     <li><span class=\"money\">{{product.price_min | money}}<\/span><\/li>\n   <\/ul>\n{% endtablerow %}\n<\/table>\n<!-- \/LIST 3 PER ROW  -->\n\n  <div id=\"articles\">\n  \t{% assign article = pages.frontpage %}\n\n    <div class=\"article\">\n    {% if article.content != \"\" %}\n\t\t  <h3>{{ article.title }}<\/h3>\n      <div class=\"article-body textile\">\n  \t\t  {{ article.content }}\n  \t\t<\/div>\n  \t{% else %}\n      <div class=\"article-body textile\">\n  \t  In <em>Admin &gt; Blogs &amp; Pages<\/em>, create a page with the handle <strong><code>frontpage<\/code><\/strong> and it will show up here.<br \/>\n  \t   <\/div>\n  \t{% endif %}\n    <\/div>\n\n  <\/div>\n\n",
    "created_on": "2010-07-12T15:31:50Z",
    "modified_on": "2010-07-12T15:31:50Z",
    "content_type": "text\/x-liquid",
    "size": 1068,
    "theme_id": 828155753
  }
}

Lấy một ảnh trong theme

GET /admin/themes/#{id}/assets.json?key=assets/bg-body.gif&theme_id=828155753
Xem kết quả
HTTP/1.1 200 OK
{
  "asset": {
    "key": "assets\/bg-body.gif",
    "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/bg-body.gif?9786007440285130435",
    
    "created_on": "2010-07-12T15:31:50Z",
    "modified_on": "2010-07-12T15:31:50Z",
    "content_type": "image\/gif",
    "size": 1571,
    "theme_id": 828155753
  }
}
PUT/admin/themes/828155753/assets.json

PUT đảm nhiệm cả 2 vai trò là tạo mới assets và cập nhật assets

Cập nhật một ảnh bằng cách cung cấp đường dẫn ảnh để lấy giá trị

PUT /admin/themes/#{id}/assets.json
{
  "asset": {
    "key": "assets\/bg-body.gif",
    "src": "http:\/\/apple.com\/new_bg.gif"
  }
}
Xem kết quả
HTTP/1.1 200 OK
{
  "asset": {
    "key": "assets\/bg-body.gif",
    "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/bg-body.gif?16829845728213008615",
    "created_on": "2010-07-12T15:31:50Z",
    "modified_on": "2015-09-02T14:51:51Z",
    "content_type": "image\/gif",
    "size": 43,
    "theme_id": 828155753
  }
}

Thay đổi giá trị một file liquid sẵn có

PUT /admin/themes/#{id}/assets.json
{
  "asset": {
    "key": "templates\/index.bwt",
    "value": "<img src='backsoon-postit.png'><p>We are busy updating the store for you and will be back within the hour.<\/p>"
  }
}
Xem kết quả
HTTP/1.1 200 OK
{
  "asset": {
    "key": "templates\/index.bwt",
    "public_url": null,
    "created_on": "2010-07-12T15:31:50Z",
    "modified_on": "2015-09-02T14:51:52Z",
    "content_type": "text\/x-liquid",
    "size": 110,
    "theme_id": 828155753
  }
}

Copy một asset thông qua source_key

PUT /admin/themes/#{id}/assets.json
{
  "asset": {
    "key": "layouts\/alternate.bwt",
    "source_key": "layouts\/theme.bwt"
  }
}
Xem kết quả
HTTP/1.1 200 OK
{
  "asset": {
    "key": "layouts\/alternate.bwt",
    "public_url": null,
    "created_on": "2015-09-02T14:51:55Z",
    "modified_on": "2015-09-02T14:51:55Z",
    "content_type": "text\/x-liquid",
    "size": 3174,
    "theme_id": 828155753
  }
}

Tạo mới một Asset bằng dữ liệu base64

PUT /admin/themes/#{id}/assets.json
{
  "asset": {
    "key": "assets\/empty.gif",
    "base64": "R0lGODlhAQABAPABAP\/\/\/wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==\n"
  }
}
Xem kết quả
HTTP/1.1 200 OK
{
  "asset": {
    "key": "assets\/empty.gif",
    "public_url": "https:\/\/bizweb.dktcdn.net\/s\/files\/1\/0006\/9093\/3842\/t\/1\/assets\/empty.gif?16418212202600161583",
    "created_on": "2015-09-02T14:51:55Z",
    "modified_on": "2015-09-02T14:51:55Z",
    "content_type": "image\/gif",
    "size": 43,
    "theme_id": 828155753
  }
}
DELETE/admin/themes/828155753/assets.json

Xóa Asset khỏi shop

Xóa ảnh khỏi theme

DELETE /admin/themes/#{id}/assets.json?key=assets/bg-body.gif
Xem kết quả
HTTP/1.1 200 OK
{}

Có một vài file bạn không thể xóa

DELETE /admin/themes/#{id}/assets.json?key=layouts/theme.bwt
Xem kết quả
HTTP/1.1 403 Forbidden
{}

Bài viết trên có hữu ích cho bạn không?

Hữu ích Không hữu ích
Số lượt đánh giá hữu ích: