How to create a relation to a record from another table in a post request

Hi there,

How do I create the relationship to a record from another table in a post request?

I am creating a record with data from a registered customer device with a post request to the "Installed Base" custom module.
The Accounts module has a one-to-many relation with the "Installed Base" module.




The following body creates a new record in the Installed Base table, but does not create a relation to the Accounts record.
I thought it would be enough to pass the account ID in the request.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
{
"deleted": false,
"quantity": "1",
"serial_number": "27289",
"source_id": "302238023232",
"product_model": "alpha",
"purchase_date": "2025-03-11",
"timestamp": "2025-03-11T11:14:00+01:00",
"accounts": {
"id": "12686878-0363-11e7-b361-14187763417d"
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



How do I manage to create a relation? Anyone have a tip?

Thanks!
Steffen

Parents
  • Hi  

    To create a record
    that is related to an existing record you can start from the existing record you want to relate to.

    Use:

    <module>/:record/link/:link_name POST

    So, in your example, let's pretend your accountID is ffe8d826-81cb-11e7-8d9e-001a4a160206

    and the relationship between your Accounts and Installed Base modules is called: inst_installedbase_accounts_1

    To create an IstallBase relaed to that Account the API will be: 

    Accounts/ffe8d826-81cb-11e7-8d9e-001a4a160206/link/inst_installedbase_accounts_1

    FrancescaS

    PS. The easiest way to find the link_name is in the cached vardefs:

    cache/modules/Accounts/Accountvardefs.php

    search for your module name for the Installed Base.

Reply
  • Hi  

    To create a record
    that is related to an existing record you can start from the existing record you want to relate to.

    Use:

    <module>/:record/link/:link_name POST

    So, in your example, let's pretend your accountID is ffe8d826-81cb-11e7-8d9e-001a4a160206

    and the relationship between your Accounts and Installed Base modules is called: inst_installedbase_accounts_1

    To create an IstallBase relaed to that Account the API will be: 

    Accounts/ffe8d826-81cb-11e7-8d9e-001a4a160206/link/inst_installedbase_accounts_1

    FrancescaS

    PS. The easiest way to find the link_name is in the cached vardefs:

    cache/modules/Accounts/Accountvardefs.php

    search for your module name for the Installed Base.

Children