cityofaustin / knackpy

A Python client for interacting with Knack applications
https://cityofaustin.github.io/knackpy/docs/user-guide/
Other
39 stars 17 forks source link

How to fill in connection field (one to many) from knackpy #97

Closed rangganast closed 2 years ago

rangganast commented 2 years ago

Hello I have been using this knackpy package and it's awesome. However I haven't found a way to fill in knack "connection field" when creating a row in object. Any clue?

Thank you

johnclary commented 2 years ago

@rangganast sorry for the slow reply. Yes, this can be done. When you create or update a connection field, you need to use the record ID of the connected record. For example, if field_1 is your connection field, your payload would look like this:

{
   "field_1": "5d65bad5614e4d001047b585"
}

If you connection field is a many-to-one, you can use a list of record IDs:

{
   "field_1": ["5d65bad5614e4d001047b585",  "ad65badxe4d001047b585", "q9xcd65bad5614e4d0085"]
}

If you have doubts—take a look at the raw record data from Knack. You need to mirror this format.

This is not well documented, but see here: https://docs.knack.com/docs/view-based-post-for-inserting-a-connected-record

rangganast commented 2 years ago

Nice! Thank you so much.