Populate a fixedCollection with loadOptionsMethod

Hi,

I’m trying to add Update client operation on Invoice Ninja node.
For updating a client it’s needed to set existing linked contacts ids to the payload otherwise contacts are deleted.

So before update a client I need to get the client like: GET /api/v1/clients/1
{“name”:“test”, “contacts”:[{“id”: 1, “first_name”: “test”}]}
Get contacts and put into the update payload.

On n8n GUI I would like to create a fixedCollection for Contacts fields (like for client create) and populate it by calling loadOptionsMethod I guess in order to send existing contacts when update client.

How could I make this? The loadOptionsMethod seems to be uncompatible with fixedCollection…

Thanks for your help

Hey @dokime7!

@RicardoE105 or @ivov maybe able to help you here :slight_smile:

Thanks @harshil1712 :wink:

On n8n GUI I would like to create a fixedCollection for Contacts fields (like for client create) and populate it by calling loadOptionsMethod I guess in order to send existing contacts when update client.

What do you need to populate exactly? if it’s the content of the fixed collection, that is not possible. You can use the loadOptionsMethod in a field within the fixedCollection.

Can you share how do you picture the UI to be? Also, can you share the endpoint you are trying to use?

I need to populate the content of fixed collection…
Like the screenshot, the contacts of a client must be specified when update client in order to not be deleted.
If it is not possible, maybe another approach could be used, but I don’t know which one…

Call examples:
GET /api/v1/clients/1
Response: {“name”:“test”, “contacts”:[{“id”: 1, “first_name”: “test”}]}

PUT /api/v1/clients/1
Payload: {“name”:“test-updated”, “contacts”:[{“id”: 1, “first_name”: “test”}]}

If do not specify {“id”: 1, “first_name”: “test”}, the contact is deleted.

Here the api doc : API — Invoice Ninja 4.5.21 documentation

Ahh got it. What about if you do {"name":"test-updated", "contacts":[{"id": 1]} Would that also delete the contacts the client has? Asking to be able to come up with the best solution.

Yes, contacts are kept when pass only ids.
it would be great if we could already find a solution to pass these ids.

But the best would be to can update contacts fields also.

Thanks for you help.

Ok I would do the following:

Grab the client ID and get all the contact ids. Before sending the request, check the fixedCollection. if the fixedCollection has data, make sure to add those ids to the initial array of contact ids (if already in the initial array, edit the data the user set ). If the fixedCollection does no have data, then just end all the ids that initial array has. Does that make sense?

Yes absolutely.
But, if I want to update the second contact, how to match fixedCollection contact data fields with the id of the existing one?

Good question, for that you need to use an option type within the fixedCollection that loads all the clients (ids).

Hmm… So if I clic on Add contact I will have a select box with contact IDs and I can select one and fill firstname, email,… in order to update contact?

Any suggestion?

Sorry for the late response. Somehow missed your question.

Yes, that is correct.

Thanks.

So, I want to update a client that has 2 contacts, I click on Add contact, select ID 1 on select box and fill firstname, now I click another time on Add contact, the select box should contains only ID 2, is it possible?

Yes, you can do that a fixedCollection that has multipleValues set to true.