Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Last active April 3, 2025 06:17
Show Gist options
  • Save Crocoblock/106f0a10fd4b40301d4c950326e84998 to your computer and use it in GitHub Desktop.
Save Crocoblock/106f0a10fd4b40301d4c950326e84998 to your computer and use it in GitHub Desktop.
JetEngine Update relation with REST API

If you enable Register update REST API Endpoint switcher in Relation settings https://prnt.sc/5uVcmW01T7sk
then you can update relation items and / or meta

Endpoint URL is https://your-site.com/wp-json/jet-rel/RELATION_ID
Method - POST

Relation ID can be found in Relation URL when editing it

Authenticate with Application Password


When you are usind REST API with JetFormBuilder you can use form field macros, like "%post_id%"
For array values (like checkbox, multiple select, etc.) - do not wrap macros into quotes

Update / Replace related items

Parameters:

  • parent_id, child_id - single ID or array of IDs
  • context - either "child" or "parent"
    "child" means we replace / update (add) / disconnect child(ren) of parent(s)
    "parent" means we replace / update (add) / disconnect parent(s) of child(ren)
  • store_items_type - "replace" / "update" / "disconnect"

Example:
Relation is Many to Many
Set two children with IDs of 267234 and 267235 to parent with ID of 686

Parameters:

  • parent_id - 686
  • child_id - [267234,267235]
  • context - "child" so that we replace children for the parent
  • store_items_type - "replace"
{
    "parent_id": 686,
    "child_id": [267234,267235],
    "context": "child",
    "store_items_type": "replace",
}

Update relation meta

If you need to update relation meta, only one pair of parent / child should be updated.

Example:

Update relation meta for the parent-child pair 686-267234

"meta" is an object where keys are meta field keys, and values are meta field values;
for timestamp types you can pass date in a human readable format, it will be converted automatically.
All possible meta types have an example value here.

{
    "parent_id": 686,
    "child_id": 267234,
    "context": "child",
    "store_items_type": "update",
    "meta": {
        "text": "test phrase",
        "date": "2023-11-11",
        "date_timestamp": "2023-11-11",
        "time": "11:00",
        "datetime": "2023-11-11T11:00",
        "datetime_timestamp": "2023-11-11T11:00",
        "checkbox": [
            "op1",
            "op2"
        ],
        "media_id":266280,
        "media_url":"https://SOME.URL",
        "media_array": {
            "id": 266280,
            "url": "https://SOME.URL"
        },
        "radio": "op1",
        "select1": "op2",
        "select_multiple": [
            "op1",
            "op2"
        ]
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment