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

  • 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.

  •  The answer from   is what you want here. But in case it helps  the UI actually consumes its own API so sometimes in instances like this the easiest way to work out how to do it over the API is to do it in the UI and watch the network requests it makes. Just thought I would put that out there in case you were not aware.

  • Thank you  , this is very helpful. I was able to solve it even easier, in the module installed_base was a field "account_id" - if I pass a valid account_id, the relation is created!

    All the best,
    Steffen

  • Thank you    - that's a very good tip!
    Best regards,
    Steffen

  • Glad you were able to get it to work. Sounds like your Account field in the installed base module is a Relate field.