API Article

From Spiffy Stores Knowledge Base

Revision as of 13:03, 24 May 2018 by Admin (talk | contribs)

An article is a single entry in a blog.

Articles appear in reverse chronological order, with the most recent entry at the top of the blog's page. An article belongs to only one blog.

Article Properties

id
{ "id" : 191 }

A unique numeric identifier for the article.

blog_id
{ "blog_id" : 472 }

A unique numeric identifier for the blog that the article belongs to.

title
{ "title": "My First Article" }

The title of the article.

handle
{ "handle": "my-first-article" }

A unique, human-friendly string for the article, generated automatically from its title. In online store themes, the Liquid templating language refers to a article by its handle.

author
{ "author": "Bilbo Baggins" }

The author of the article.

body
{ "body": "This is a test blog article" }

The text content of the article in Textile markup. This is automatically translated into body_html for display on a browser.

body_html
{ "body_html": "<p>This is a test blog article</p>" }

The text content of the article, complete with HTML markup.

created_at
{ "created_at": "2008-07-15T20:00:00-04:00" }

The date and time (ISO 8601 format) when the article was created.

updated_at
{ "updated_at": "2008-07-16T20:00:00-04:00" }

The date and time (ISO 8601 format) when the article was last updated.

published
{ "published" : true }

Indicates whether the blog is published and visible to customers.

published_at
{ "published_at": "2008-07-16T20:00:00-04:00" }

The date and time (ISO 8601 format) when the article was published.

Endpoints

GET /api/blogs/BLOG_ID/articles.json

Retrieve a list of all articles belonging to the blog.

Optional Parameters

limit Number of results returned. The default is 30, with a maximum of 50 in a single request.
page The number of the page to return. The number of results per page is set by the limit parameter. If more results are required, then submit the request again, increasing the page number each time.
since_id Limit the results to only include objects which have an id greater than the given value.
title Limit the results to only include articles with the given title.
handle Limit the results to only include articles with the given handle.
author Limit the results to only include articles written by the given author.
published_status Limit the results to only include articles with the given published status ('published' or 'unpublished').
created_at_min Return only the articles created after the given date and time. Use the format "2014-12-31 12:00".
created_at_max Return only the articles created before the given date and time. Use the format "2014-12-31 12:00".
updated_at_min Return only the articles updated after the given date and time. Use the format "2014-12-31 12:00".
updated_at_max Return only the articles updated before the given date and time. Use the format "2014-12-31 12:00".
fields A comma-separated list of fields to return in the response.

Example Request and Response

GET /api/blogs/BLOG_ID/articles.json

HTTP/1.1 200 OK

{
  "articles": [
    {
      "id": 190,
      "blog_id": 472,
      "title": "Test API blog article",
      "handle": "test-api-blog-article",
      "author": "Bilbo Baggins",
      "body": "This is a test blog article",
      "body_html": "<p>This is a test blog article</p>",
      "created_at": "2016-03-30T17:10:44.992+11:00",
      "updated_at": "2016-03-30T17:10:44.992+11:00",
      "published": true,
      "published_at": "2016-03-30T17:10:44.986+11:00"
    }, ...
  ]
}

Examples using filters

GET /api/blogs/BLOG_ID/articles.json?fields=id,title

GET /api/blogs/BLOG_ID/articles/count.json

Return a count of the number of articles.

Optional Parameters

since_id Limit the results to only include objects which have an id greater than the given value.
title Limit the results to only include articles with the given title.
handle Limit the results to only include articles with the given handle.
author Limit the results to only include articles written by the given author.
published_status Limit the results to only include articles with the given published status ('published' or 'unpublished').
created_at_min Return only the articles created after the given date and time. Use the format "2014-12-31 12:00".
created_at_max Return only the articles created before the given date and time. Use the format "2014-12-31 12:00".
updated_at_min Return only the articles updated after the given date and time. Use the format "2014-12-31 12:00".
updated_at_max Return only the articles updated before the given date and time. Use the format "2014-12-31 12:00".

Example Request and Response

GET /api/blogs/BLOG_ID/articles/count.json

HTTP/1.1 200 OK

{
  "count": 15
}

GET /api/blogs/BLOG_ID/articles/ARTICLE_ID.json

Retrieves a single article by ID.

Optional Parameters

fields A comma-separated list of fields to return in the response.

Example Request and Response

GET /api/blogs/472/articles/190.json

HTTP/1.1 200 OK

{
  "article": {
    "id": 190,
    "blog_id": 472,
    "title": "Test API blog article",
    "handle": "test-api-blog-article",
    "author": "Bilbo Baggins",
    "body": "This is a test blog article",
    "body_html": "<p>This is a test blog article</p>",
    "created_at": "2016-03-30T17:10:44.992+11:00",
    "updated_at": "2016-03-30T17:10:44.992+11:00",
    "published": true,
    "published_at": "2016-03-30T17:10:44.986+11:00"
  }
}

GET /api/articles/authors.json

Retrieves all the authors that have contributed to the store blogs.

Example Request and Response

GET /api/articles/authors.json

HTTP/1.1 200 OK

{
  "authors": [
    "Bilbo Baggins",
    "Willy Wonker",
    "System Admin"
  ]
}

POST /api/blogs/BLOG_ID/articles.json

Add an article to the blog.

Example Request and Response

POST /api/blogs/472/articles.json

{
  "article": {
    "title": "My Latest Product Article",
    "author": "Bilbo Baggins",
    "body": "Buy this product. It's great!",
    "published": true
  }
}

HTTP/1.1 201 Created

PUT /api/blogs/BLOG_ID/articles/ARTICLE_ID.json

Updates an article.

Example Request and Response

PUT /api/blogs/472/articles/248.json

{
  "article": {
    "id": 248,
    "published": false
  }
}

HTTP/1.1 200 OK

DELETE /api/blogs/BLOG_ID/articles/ARTICLE_ID.json

Deletes an article from a blog.

Example Request and Response

DELETE /api/blogs/472/articles/248.json

HTTP/1.1 200 OK

{}

Further Reference