Creating Items from an External API Call

Last edit: Jun 05, 2019

This guide will help you create items from an external API call. The example shows the steps of creating a Customization from existing data through an API call to our service.

Requirements

This is an advanced tutorial. To follow it, you should be familiar with basic platformOS concepts, HTML, Liquid, APIs and Form Configurations, and the topics in the Get Started section.

Steps

Creating items from an external API call is a four-step process:

Step 1: Create CustomModelType

Create the following CustomModelType:

custom_model_types/flowers.yml

name: flower
properties:
- name: name
  type: string
- name: creator_id
  type: integer

Step 2: Create FormConfiguration

Define what data you expect, and required validations:

form_configurations/import_flowers.liquid

---
name: import_flowers
resource: flower
fields:
  properties:
    name:
      validation:
        presence: true
    creator_id:
      validation:
        presence: true
resource_owner: anyone
---

Step 3: Generate API token

Generate API token from instance admin [Settings -> API Keys -> Generate new API Key].

Step 4: Create curl command

Here is an example POST request you need to send. You need to set:

  • the token in the header
  • data payload in a JSON format

curl https://example.platform-os.com/api/user/customizations
  -H "Authorization: Token token=[YOUR API TOKEN]"
  -H 'Content-Type: application/json'
  --data '{"form": { "properties_attributes: {"name": "Red flowers", "creator_id":"1" }}, "form_configuration_name": "import_flowers", "parent_object_class":"CustomModelType","parent_object_id":"flower"}'

Questions?

We are always happy to help with any questions you may have.