• Log in
  • Contact Sales
  • Evaluate

Get in touch  

Developer Guides • Flows

Create a Blog schema with Flows

Last updated: 05 Jul 2019

Add custom data to create and manage blog.

If you want to use a single platform for multiple solutions, Moltin API gives you the ability to use custom data to create a blog and manage your content with some light configuration.

Prerequisites

  • Moltin dashboard (you'll need Client ID and Client Secret of your store).
  • Basic understanding of object-oriented programming or JavaScript.

Summary of steps required

  • Create a Flow that will contain your blog object.
  • Create Fields to create blog's building blocks (date, title, blog post entry, fields, etc.).
  • Create Entries to store the actual content (blog posts).
  • Create relationships to organize data and manage the content.
  • Fetch blog content to display and render it according to your needs on your blog site.

Step-by-step walkthrough

Use Flow API (custom data) to create a new resource: a blog object to store blog content you can surface on your website.

1. Get your access token

Get a client_credentials access token to follow along making the API requests outlined below.

curl -X POST https://api.moltin.com/oauth/access_token \
     -d "client_id=XXXX" \
     -d "client_secret=XXXX" \
     -d "grant_type=client_credentials"

2. Create a new custom Flow

Create a custom (non-core) Flow. This Flow is going to power a blog website, and used to store blog content objects.

curl -X POST https://api.moltin.com/v2/flows \
     -H "Authorization: XXXX" \
     -H "Content-Type: application/json" \
     -d $'{
      "data": {
        "type": "flow",
        "name": "Posts",
        "slug": "posts",
        "description": "Stores content that will be used for a blog",
        "enabled": true
      }
    }'

Make sure to take note of the Flow ID returned (the id field in the response), you'll need this to create relationship between the Flow and its Fields.

3. Create Fields

Fields will be returned when you call the blog object. Repeat this for every blog feature you'd like to include, e.g. blog title, blog date, blog post content, etc. The example below shows how to create fields to store basic blog detail: title.

Each Field must be passed separately.

Populate the data.relationships.flow.id field with the Flow ID generated as part of the create (POST) Flow response.

curl -X POST https://api.moltin.com/v2/fields \
     -H "Authorization: XXXX" \
     -H "Content-Type: application/json" \
     -d $'{
        "data": {
          "type": "field",
          "name": "blogTitle",
          "slug": "blogTitle",
          "description": "This is going to return the blog title",
          "unique": true,
          "enabled": true,
          "field_type": "string",
          "required": true,
          "relationships": {
            "flow": {
              "data": {
                "type": "flow",
                "id": "FLOW-ID"
                }
            }
          }
        }
     }'

4. Create Entries for a Blog

Entries represent the actual content each Field will contain. Create an Entry for every Field added. In this example, the Title, Date and Content Fields will be a part of the Entry created, as they were all flagged as required.

Using slugs

Slug forms the end part of the URL. Use it to create human-readable and search-engine-friendly URIs for your blog.

Note that the slug used in the URL is case sensitive.

curl -X POST https://api.moltin.com/v2/flows/:flow-slug/entries \
     -H "Authorization: XXXX" \
     -H "Content-Type: application/json" \
     -d $'{
       "data": {
         "type": "entry",
         "blogTitle": "Creating a Blog",
         "blogDate": "8.24.2018",
         "blogContent": "Learn how to create blogs with the Moltin API"
       }
     }'

5. Create relationships to organize your data

You can use the Moltin API to manage your content. You would use custom Flows for that. If you have a more robust CMS in mind, we recommend plugging in a third party content management tool, such as Contentful.

First, create Fields related to a Flow to adapt a data model to how you wish to present it on the frontend, e.g. posts per author, posts per category, etc.

To create a relationship, take the Flow you want to relate your Fields to, and use its slug in the URL of the request. Then, specify which Field you wish to relate to in the request body, and repeat it for every Field you wish to relate to this Flow.

When fetching the Flow, it will list all Fields that are related to it.

a) Create a Flow

curl -X POST https://api.moltin.com/v2/flows \ 
     -H "Authorization:XXXX" \ 
     -H "Content-Type:application/json" \ 
     -d $'{  
        "data":{  
          "type":"flow",
          "name":"Joannas blog post",
          "slug":"blog-joanna",
          "description":"Stored Joannas blog posts",
          "enabled":true
   }
}'

b) Create Related Field

curl -X POST https://api.moltin.com/v2/fields \ 
     -H "Authorization:XXXX" \ 
     -H "Content-Type:application/json" \ 
     -d $'{  
        "data":{  
          "type":"field",
          "name":"blog_title_3",
          "slug":"blog_title_3",
          "field_type":"string",
          "description":"Joannas third blog post",
          "required":true,
          "unique":true,
          "default":0,
          "enabled":true,
          "order":1,
          "relationships":{  
            "flow":{  
              "data":{  
                "type":"flow",
                "id":"FLOW-ID"
            }
         }
      }
   }
}'


c) Fetch the Flow with all related Fields

curl -X GET https://api.moltin.com/v2/flows/:flow-id \
     -H "Authorization: XXXX" \
     -H "Content-Type: application/json" 

6. Fetch Blog content to display

Using the Moltin API, fetch the blog Flow which will now contain the blog post created above. 

curl -X GET "https://api.moltin.com/v2/flows/posts/entries" \
     -H "Authorization: XXXX" \
     -H "Content-Type: application/json"

Expected outcome

Your blog is now surfaced on your website. The data you've fetched is in JSON format, and you can render it according to your needs directly on your blog site. You can now expand it by adding photo galleries, comments, reviews, etc.

Further reading

Explore More Developer Guides

26 Jun 2019

Manage abandoned carts with Flows

Quick intro on how carts work There are three aspects of how Moltin carts operate:

Read More
author
Matt Foyle
in Flows | Carts
14 Jun 2019

Extend the order and cart resource with Flows

Extend the order resource to add shipping provider and a consignment number.

Read More
author
Joanna Suau
in Flows | Orders | Carts
14 Jun 2019

Store data form third party integration with Flows

Store nexus locations from a tax calculation service using Flows.

Read More
author
Joanna Suau
in Flows | Integrations