Homepage

Creating Items from an External API Call

Last edit: Dec 28, 2023

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

Warning

This article is deprecated. The easiest way to build your API to be consumed by third party systems is by creating Pages with manually implemented business logic

Requirements

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

Steps

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

Step 1: Create Table

Create the following Table:

app/schema/flowers.yml
name: flower
properties:
- name: name
  type: string
- name: creator_id
  type: integer

Step 2: Create Form

Define what data you expect, and required validations:

app/forms/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

Log in to the Partner Portal, and click your user icon on the top right. Select Your Profile and click on Show/Hide to show the Access 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/records
  -H "Authorization: Token token=[YOUR API TOKEN]"
  -H 'Content-Type: application/json'
  --data '{"form": { "properties_attributes: {"name": "Red flowers", "creator_id":"1" }}, "form_name": "import_flowers", "parent_object_class":"CustomModelType","parent_object_id":"flower"}'

Questions?

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

contact us