{"openapi":"3.0.0","info":{"version":"1.0.0","title":"Agent Sharing API Definition (v1)","description":"This document defines the **Agent Sharing REST API (v1)** for organizations in **WSO2 Identity Server**.\nIt follows the same pattern as **User Sharing (v2)** and enables organization administrators to:\n- Share agents (machine identities / service accounts) across child organizations.\n- Configure per-organization agent role assignments.\n- Manage and revoke shared access for agents.\n- Retrieve an agent's shared organizations and effective roles.","contact":{"name":"WSO2","url":"http://wso2.com/products/identity-server/","email":"iam-dev@wso2.org"},"license":{"name":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}},"servers":[{"description":"SwaggerHub API Auto Mocking","url":"https://virtserver.swaggerhub.com/HASINISAMA99/AgentSharingAPI/1.0.0"},{"url":"https://{server-url}/t/{tenant-domain}/api/server/v1","variables":{"tenant-domain":{"default":"carbon.super"},"server-url":{"default":"localhost:9443"}}}],"security":[{"OAuth2":[]},{"BasicAuth":[]}],"paths":{"/agents/share":{"post":{"tags":["Agent Sharing"],"summary":"Share agents with specific organizations","description":"Share one or more agents with a selected set of organizations, optionally\nassigning roles to each shared agent in each target organization.\n\nThis endpoint is treated as a **processing function**:\nit triggers a sharing process and responds with `202 Accepted`.\n\n**Scope required:** `internal_agent_share`","operationId":"shareAgentsWithSelected","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentShareSelectedRequestBody"},"example":{"agentCriteria":{"agentIds":["7a1b7d63-8cfc-4dc9-9332-3f84641b72d8","5d2a1c84-9f7a-43cd-b12e-6e52d7f87e16"]},"organizations":[{"orgId":"b028ca17-8f89-449c-ae27-fa955e66465d","policy":"SELECTED_ORG_ONLY","roleAssignment":{"mode":"SELECTED","roles":[{"displayName":"Org Admin","audience":{"display":"My Org 1","type":"organization"}}]}},{"orgId":"a17b28ca-9f89-449c-ae27-fa955e66465f","policy":"SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN"}]}}}},"responses":{"202":{"description":"Agent sharing process triggered successfully.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ProcessSuccessResponse"},"example":{"status":"Processing","details":"Agent sharing process triggered successfully."}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"patch":{"tags":["Agent Sharing"],"summary":"Perform incremental role assignment operations for already shared agents","description":"Perform **incremental updates** to the shared attributes (e.g., role assignments) of already shared agents.\n\nThis endpoint supports **SCIM-like PATCH semantics**:\n- `op: \"add\"`    → assign additional roles.\n- `op: \"remove\"` → remove specific roles.\n\n> **Note:**\n> Only **role assignment** updates are managed here as of now. Sharing/unsharing organizations\n> is handled via `/agents/share`, `/agents/share-with-all`, `/agents/unshare`,\n> and `/agents/unshare-with-all`.\n\n**Scope required:** `internal_agent_shared_access_update`","operationId":"patchAgentSharing","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentSharingPatchRequest"},"examples":{"addRolesToOrg":{"summary":"Add roles to a shared agent in a specific organization","value":{"agentCriteria":{"agentIds":["7a1b7d63-8cfc-4dc9-9332-3f84641b72d8"]},"Operations":[{"op":"add","path":"organizations[orgId eq b028ca17-8f89-449c-ae27-fa955e66465d].roles","value":[{"displayName":"Org Viewer","audience":{"display":"My Org 1","type":"organization"}},{"displayName":"App Editor","audience":{"display":"My App 1","type":"application"}}]}]}},"removeRolesFromOrg":{"summary":"Remove roles from a shared agent in a specific organization","value":{"agentCriteria":{"agentIds":["7a1b7d63-8cfc-4dc9-9332-3f84641b72d8"]},"Operations":[{"op":"remove","path":"organizations[orgId eq b028ca17-8f89-449c-ae27-fa955e66465d].roles","value":[{"displayName":"Org Viewer","audience":{"display":"My Org 1","type":"organization"}}]}]}}}}}},"responses":{"202":{"description":"Role assignment patch operation processed successfully.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ProcessSuccessResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Not Found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/agents/share-with-all":{"post":{"tags":["Agent Sharing"],"summary":"Share agents with all organizations","description":"Share one or more agents with **all organizations** according to the specified policy.\n\nA common `roleAssignment` can be provided to assign roles in all matching organizations.\n\nThis endpoint is treated as a **processing function** and responds with `202 Accepted`.\n\n**Scope required:** `internal_agent_share`","operationId":"shareAgentsWithAll","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentShareAllRequestBody"},"example":{"agentCriteria":{"agentIds":["7a1b7d63-8cfc-4dc9-9332-3f84641b72d8"]},"policy":"ALL_EXISTING_AND_FUTURE_ORGS","roleAssignment":{"mode":"SELECTED","roles":[{"displayName":"Global Org Viewer","audience":{"display":"My Org 1","type":"organization"}}]}}}}},"responses":{"202":{"description":"Share-all process triggered successfully.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ProcessSuccessResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/agents/unshare":{"post":{"tags":["Agent Sharing"],"summary":"Unshare agents from specific organizations","description":"Unshare one or more agents from a selected set of organizations.\n\n> **Note:**\n> This only removes the agent from the specified organizations. If the agent\n> was shared with a parent org plus its children via a broader policy,\n> you must explicitly include all relevant organization IDs when unsharing.\n\nThis endpoint is treated as a **processing function** and responds with `202 Accepted`.\n\n**Scope required:** `internal_agent_unshare`","operationId":"unshareAgentsFromSelected","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentUnshareSelectedRequestBody"},"example":{"agentCriteria":{"agentIds":["7a1b7d63-8cfc-4dc9-9332-3f84641b72d8"]},"orgIds":["b028ca17-8f89-449c-ae27-fa955e66465d","a17b28ca-9f89-449c-ae27-fa955e66465f"]}}}},"responses":{"202":{"description":"Unsharing process triggered successfully.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ProcessSuccessResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/agents/unshare-with-all":{"post":{"tags":["Agent Sharing"],"summary":"Unshare agents from all organizations","description":"Completely remove all shared access for one or more agents from **all organizations**.\n\nThis endpoint is treated as a **processing function** and responds with `202 Accepted`.\n\n**Scope required:** `internal_agent_unshare`","operationId":"unshareAgentsFromAll","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentUnshareAllRequestBody"},"example":{"agentCriteria":{"agentIds":["7a1b7d63-8cfc-4dc9-9332-3f84641b72d8"]}}}}},"responses":{"202":{"description":"Unshare-all process triggered successfully.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ProcessSuccessResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/agents/{agentId}/share":{"get":{"tags":["Agent Accessible Organizations"],"summary":"List organizations where the agent has shared access","description":"Retrieve the list of organizations where the specified agent has shared access,\nincluding per-organization effective role assignments.\n\nThis follows the same pattern as **`GET /users/{userId}/share`**.\n\n**Scope required:** `internal_agent_shared_access_view`","operationId":"getAgentSharedOrganizations","parameters":[{"in":"path","name":"agentId","required":true,"schema":{"type":"string"},"description":"The ID of the agent."},{"in":"query","name":"before","required":false,"schema":{"type":"string"},"example":"Ng==","description":"Base64 encoded cursor value for backward pagination."},{"in":"query","name":"after","required":false,"schema":{"type":"string"},"example":"Ng==","description":"Base64 encoded cursor value for forward pagination."},{"in":"query","name":"filter","required":false,"schema":{"type":"string"},"example":"orgId eq b028ca17-8f89-449c-ae27-fa955e66465d","description":"Condition to filter the retrieval of records.\nSupports `sw`, `co`, `ew`, and `eq` operations."},{"in":"query","name":"limit","required":false,"schema":{"type":"integer"},"example":10,"description":"Maximum number of records to return. If you do not specify this parameter,\nthis will return all shared organizations."},{"in":"query","name":"recursive","required":false,"schema":{"type":"boolean"},"description":"Determines whether a recursive search should happen.\nIf set to true, includes shared organizations in all levels of the hierarchy;\nif set to false, includes only shared organizations in the next level of the hierarchy."},{"in":"query","name":"attributes","required":false,"schema":{"type":"string"},"example":"roles","description":"Specifies the required parameters in the response.\nSupported values: `roles`, `sharingMode`."}],"responses":{"200":{"description":"Successful response with the agent's shared organizations.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentSharedOrganizationsResponse"},"example":{"links":[{"href":"/o/api/server/v1/agents/7a1b7d63-8cfc-4dc9-9332-3f84641b72d8/share?limit=10&after=MTA=","rel":"next"}],"sharingMode":{"policy":"ALL_EXISTING_AND_FUTURE_ORGS","roleAssignment":{"mode":"SELECTED","roles":[{"displayName":"Global Org Viewer","audience":{"display":"My Org 1","type":"organization"}}]}},"organizations":[{"orgId":"b028ca17-8f89-449c-ae27-fa955e66465d","orgName":"Child Org 1","orgHandle":"child-org-1","orgStatus":"ACTIVE","orgRef":"/t/wso2.com/api/server/v1/organizations/b028ca17-8f89-449c-ae27-fa955e66465d","hasChildren":true,"depthFromRoot":1,"parentOrgId":"08f8c1d2-4b3e-4c5a-9f6b-7d8e9f0a1b2c","parentAgentId":"7a1b7d63-8cfc-4dc9-9332-3f84641b72d8","sharedAgentId":"550e8400-e29b-41d4-a716-446655440000","sharedType":"SHARED","sharingMode":{"policy":"SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN","roleAssignment":{"mode":"SELECTED","roles":[{"displayName":"Org Admin","audience":{"display":"My Org 1","type":"organization"}}]}},"roles":[{"displayName":"Org Admin","audience":{"display":"My Org 1","type":"organization"}}]},{"orgId":"a17b28ca-9f89-449c-ae27-fa955e66465f","orgName":"Child Org 2","orgHandle":"child-org-2","orgStatus":"ACTIVE","orgRef":"/t/wso2.com/api/server/v1/organizations/a17b28ca-9f89-449c-ae27-fa955e66465f","hasChildren":false,"depthFromRoot":1,"parentOrgId":"08f8c1d2-4b3e-4c5a-9f6b-7d8e9f0a1b2c","parentAgentId":"7a1b7d63-8cfc-4dc9-9332-3f84641b72d8","sharedAgentId":"3f2504e0-4f89-41d3-9a0c-0305e82c3301","sharedType":"SHARED","sharingMode":{"policy":"SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN","roleAssignment":{"mode":"NONE"}},"roles":[]}]}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}},"components":{"securitySchemes":{"BasicAuth":{"type":"http","scheme":"basic"},"OAuth2":{"type":"oauth2","flows":{"authorizationCode":{"authorizationUrl":"https://localhost:9443/oauth2/authorize","tokenUrl":"https://localhost:9443/oauth2/token","scopes":{"internal_agent_share":"Share agents across organizations.","internal_agent_unshare":"Unshare agents from organizations.","internal_agent_shared_access_view":"View shared organizations and roles for an agent.","internal_agent_shared_access_update":"Update shared attributes (e.g., roles) for shared agents."}}}}},"schemas":{"AgentCriteria":{"type":"object","description":"Criteria for selecting agents to share/unshare.","properties":{"agentIds":{"type":"array","description":"List of agent IDs.","items":{"type":"string"}}},"required":["agentIds"]},"AgentShareSelectedRequestBody":{"type":"object","description":"Request body for sharing agents with a **selected set of organizations**.","required":["agentCriteria","organizations"],"properties":{"agentCriteria":{"$ref":"#/components/schemas/AgentCriteria"},"organizations":{"type":"array","description":"List of organizations to share agents with, along with policies and optional role assignments.","items":{"$ref":"#/components/schemas/AgentOrgShareConfig"}}}},"AgentOrgShareConfig":{"type":"object","description":"Per-organization sharing configuration for selected organizations.","required":["orgId","policy"],"properties":{"orgId":{"type":"string","description":"Organization ID to share the agents with."},"policy":{"type":"string","description":"Sharing scope for this organization.\n\nPossible values:\n- `SELECTED_ORG_ONLY`\n- `SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN`"},"roleAssignment":{"$ref":"#/components/schemas/RoleAssignment","description":"Optional role assignment configuration for this organization.\nIf omitted, the default behavior is to assign **no roles** (equivalent to `mode = NONE`)."}}},"AgentShareAllRequestBody":{"type":"object","description":"Request body for sharing agents with **all organizations** controlled by the selected policy.","required":["agentCriteria","policy"],"properties":{"agentCriteria":{"$ref":"#/components/schemas/AgentCriteria"},"policy":{"type":"string","description":"Global sharing policy.\n\nPossible values:\n- `ALL_EXISTING_AND_FUTURE_ORGS`"},"roleAssignment":{"$ref":"#/components/schemas/RoleAssignment","description":"Optional global role assignment configuration that applies to all organizations\ncovered by this policy. If omitted, default behavior is **no roles**."}}},"AgentUnshareSelectedRequestBody":{"type":"object","description":"Request body for unsharing agents from selected organizations.","required":["agentCriteria","orgIds"],"properties":{"agentCriteria":{"$ref":"#/components/schemas/AgentCriteria"},"orgIds":{"type":"array","description":"List of organization IDs from which agents should be unshared.","items":{"type":"string"}}}},"AgentUnshareAllRequestBody":{"type":"object","description":"Request body for unsharing agents from **all organizations**.","required":["agentCriteria"],"properties":{"agentCriteria":{"$ref":"#/components/schemas/AgentCriteria"}}},"AgentSharingPatchRequest":{"type":"object","description":"PATCH request for performing incremental role assignment operations\non already shared agents.","required":["agentCriteria","Operations"],"properties":{"agentCriteria":{"$ref":"#/components/schemas/AgentCriteria"},"Operations":{"type":"array","items":{"$ref":"#/components/schemas/AgentSharingPatchOperation"}}}},"AgentSharingPatchOperation":{"type":"object","description":"A single PATCH operation (SCIM-like) for agent sharing.\n\nCurrently supported:\n- `op: \"add\"`    → Add roles.\n- `op: \"remove\"` → Remove roles.","required":["op","path"],"properties":{"op":{"type":"string","description":"Operation type. Supported values: `add`, `remove`."},"path":{"type":"string","description":"JSON-like path in the format:\n- `organizations[orgId eq \\\"<org-id>\\\"].roles`"},"value":{"type":"array","description":"List of roles to add/remove under the specified path.","items":{"$ref":"#/components/schemas/RoleShareConfig"}}}},"RoleAssignment":{"type":"object","description":"Role assignment configuration for shared agents.\n\nThis controls which roles are assigned to the agent in the target organization.\n\n- `NONE`     → Do not assign any roles via agent sharing.\n- `SELECTED` → Assign only the roles listed under `roles`.","properties":{"mode":{"type":"string","enum":["NONE","SELECTED"],"default":"SELECTED","description":"Mode of role assignment."},"roles":{"type":"array","description":"List of roles to assign when `mode = SELECTED`.\nRequired when `mode = SELECTED`. Ignored when `mode = NONE`.","items":{"$ref":"#/components/schemas/RoleShareConfig"}}}},"RoleShareConfig":{"type":"object","description":"Role to be assigned to the shared agent in the sub-organization.","required":["displayName","audience"],"properties":{"displayName":{"type":"string","description":"Human-readable name of the role.","example":"Org Admin"},"audience":{"type":"object","required":["display","type"],"properties":{"display":{"type":"string","description":"Display name of the audience (organization or application).","example":"My Org 1"},"type":{"type":"string","description":"Type of the role audience:\n- `organization`\n- `application`","example":"organization"}}}}},"Link":{"type":"object","properties":{"href":{"type":"string","example":"/o/api/server/v1/agents/7a1b7d63-8cfc-4dc9-9332-3f84641b72d8/share?limit=10&after=MTA="},"rel":{"type":"string","example":"next"}}},"SharingMode":{"type":"object","description":"Represents whether an agent is shared using a future-sharing policy. The policy is always a future policy,\nand the associated role assignments are mapped accordingly.","required":["policy","roleAssignment"],"properties":{"policy":{"type":"string","description":"Effective sharing policy. Values depend on context:\n- `ALL_EXISTING_AND_FUTURE_ORGS`."},"roleAssignment":{"$ref":"#/components/schemas/RoleAssignment"}}},"AgentSharedOrganization":{"type":"object","description":"Represents a single organization where the agent has shared access,\nincluding organization metadata and effective roles.","properties":{"orgId":{"type":"string","description":"ID of the child organization."},"orgName":{"type":"string","description":"Name of the child organization."},"orgHandle":{"type":"string","description":"Unique, human-readable handle of the organization.","example":"sampleOrg"},"orgStatus":{"type":"string","description":"Current status of the organization.","example":"ACTIVE"},"orgRef":{"type":"string","description":"API reference of the organization resource.","example":"/t/wso2.com/api/server/v1/organizations/b4526d91-a8bf-43d2-8b14-c548cf73065b"},"hasChildren":{"type":"boolean","description":"Indicates whether the organization has child organizations."},"depthFromRoot":{"type":"integer","description":"Depth of the organization in the hierarchy, where root is 0.","example":1},"parentOrgId":{"type":"string","nullable":true,"description":"ID of the parent organization (if applicable)."},"parentAgentId":{"type":"string","description":"ID of the original agent in the home organization."},"sharedAgentId":{"type":"string","description":"ID of the **shared agent object** in the target organization (if applicable)."},"sharedType":{"type":"string","description":"Shared type of the agent. Example values: `SHARED`.","example":"SHARED"},"sharingMode":{"$ref":"#/components/schemas/SharingMode"},"roles":{"type":"array","description":"Effective roles assigned to this agent in this organization via agent sharing.","items":{"$ref":"#/components/schemas/RoleShareConfig"}}}},"AgentSharedOrganizationsResponse":{"type":"object","description":"Response listing organizations where an agent has shared access,\nincluding sharing modes and role assignments.","properties":{"links":{"type":"array","items":{"$ref":"#/components/schemas/Link"}},"sharingMode":{"$ref":"#/components/schemas/SharingMode"},"organizations":{"type":"array","items":{"$ref":"#/components/schemas/AgentSharedOrganization"}}}},"ProcessSuccessResponse":{"type":"object","description":"Indicates that a sharing / unsharing / patch process has been triggered.","properties":{"status":{"type":"string","example":"Processing"},"details":{"type":"string","example":"Agent sharing process triggered successfully."}}},"Error":{"type":"object","description":"Error response model with a code, message, description, and trace ID.\n","required":["code","message","traceId"],"properties":{"code":{"type":"string","example":"ASM-00000"},"message":{"type":"string","example":"Some error message."},"description":{"type":"string","example":"Some error description."},"traceId":{"type":"string","example":"e0fbcfeb-7fc2-4b62-8b82-72d3c5fbcdeb"}}}}}}