View-Based POST for Inserting a Connected Record

In this example, the page we will be working with has a detail view of a Company, but also contains a form view to insert a connected Employee record. The form data source is configured as "This form inserts a Employee record connected to this page's Business record."

Identify the scene URL and parent Company record id for which children records you want to retrieve. Viewing the page in the Live App will give you this data in the URL. Example: https://my-account.knack.com/my-app#companies/company-details/5d65bad5614e4d001047b585/
Following the View-Based POST examples we can construct a URL to insert this new Employee record connected to this page's Company record. The POST URL will be a regular view-based request to this view:

URL
POST https://api.knack.com/v1/scenes/scene_xx/views/view_yy/records

Parameters

ParameterExplanationExample
scene_xxscene keyscene_3
view_yyview keyview_5

Headers

KeyValue
X-Knack-Application-IdYour application ID
AuthorizationA user token valid for the view (if view is nested under a login)
content-typeapplication/json

Example Request

curl -X POST "https://api.knack.com/v1/pages/scene_3/views/view_5/records" \
  -H "X-Knack-Application-Id: YOUR-APP-ID" \
  -H "X-Knack-REST-API-Key: knack" \
  -H "Content-Type: application/json" \
  --data-raw '{
  "field_1": "5d65bad5614e4d001047b585"
}'

📘

Note: this connection field value between the Employee and Company object is automatically set when using this form in the Live App but needs to be manually included when using the form for an API call.


What’s Next
Did this page help you?