Skip to content

Links: Add endpoint to bulk create entity links#885

Open
BigRoy wants to merge 1 commit into
developfrom
enhancement/add_batch_create_link_endpoint
Open

Links: Add endpoint to bulk create entity links#885
BigRoy wants to merge 1 commit into
developfrom
enhancement/add_batch_create_link_endpoint

Conversation

@BigRoy
Copy link
Copy Markdown
Member

@BigRoy BigRoy commented Mar 23, 2026

Description of changes

Links: Add endpoint to bulk add links in one go

Technical details

Implements a bulk endpoint to allow batch creating links in one post request.

Example usage:

import ayon_api

project_name = "test"
response = ayon_api.post(
    f"/projects/{project_name}/links/bulk",
    links=[
        {
          "input": "c9996fa8273711f09f1a3c0af39c4c02",
          "output": "f4e39c0a273711f0aa9b3c0af39c4c02",
          "linkType": "generative|version|version",
          "data": {},
        },
        {
          "input": "c9996fa8273711f09f1a3c0af39c4c02",
          "output": "f4e39c0a273711f0aa9b3c0af39c4c02",
          "linkType": "generative|version|version",
          "data": {"TEST": "HELLO"},
        },
      ]
)

print(response.data)

Additional context

Please read the code a few times to make sure it doesn't do anything stupid.

@BigRoy BigRoy requested a review from martastain March 23, 2026 21:41
@BigRoy BigRoy self-assigned this Mar 23, 2026
@BigRoy BigRoy added the type: enhancement Improvement of existing functionality or minor addition label Mar 23, 2026
BigRoy added a commit to BigRoy/ayon-core that referenced this pull request Mar 23, 2026
Comment thread api/links/links.py
Copy link
Copy Markdown
Member Author

@BigRoy BigRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martastain I understood you weren't too happy with the bulk entry point to this. If you have better ideas to get the route/API name to align with the rest of the backend API let's do it.

Comment thread api/links/links.py
Comment on lines +252 to +265
link_type = link.link_type or link.link
if link_type is None:
raise BadRequestException("Link type is not specified")

if perms is not None:
if perms.links.enabled and link_type not in perms.links.link_types:
raise ForbiddenException(
"You do not have permission to create this link type."
)

if len(link_type.split("|")) != 3:
raise BadRequestException(
"Link type must be in the format 'name|input_type|output_type'"
)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too happy myself that it duplicates the link type checks, permission checks and link type format checks compared to the 'create single link'. So may want to generalize that.

May want make a private _validate_link function that is used both here and in the single link create function to ensure logic remains consistent between the two?

Comment thread api/links/links.py
) from None

await EventStream.dispatch(
"links.created",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does introduce a new "bulk" event - is that what we'd want - or would we still want to continue emitting an event per created link?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement Improvement of existing functionality or minor addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants