Skip to content

Developer Function: Script: $p.apiCreate

Overview

This section describes the methods that allow you to create new records.

Syntax

JavaScript
$p.apiCreate({
    id: (Site ID),
    data: {
       Column name: '(value)'
    },
      done: (optional process),
      fail: (optional process),
      always: (optional process)
});

Explanation Of Each Parameter

Parameter name Description
id Optional site ID
data JSON to POST
done Processing when API communication is successful (optional)
fail Processing when API communication fails (optional)
always Processing when API communication is complete (optional)

Usage Example

The following sample code creates a record with title "Coffee" and category A "Black" in the table for site ID:123.

JavaScript
$p.apiCreate({
    id: 123,
    data: {
        Title: 'coffee',
        ClassHash: {
            ClassA: 'black'
        }
    },
    done: function (data) {
        $p.clearMessage();
        const message = {
            Css: 'alert-success',
            Text: 'A new record was created'
        };
        $p.setMessage('#Message',JSON.stringify(message));
    },
    fail: function (data) {
        console.log(data);
    }
});