- Legion API
- Entity Relationships
- Batch create entity relationships
Batch create entity relationships
const url = 'https://api.hopper.west.prod.govcloud.legion.picogrid.com/v3/entities/2489E9AD-2EE2-8E00-8EC9-32D5F69181C0/relationships/batch';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"relationships":[]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.hopper.west.prod.govcloud.legion.picogrid.com/v3/entities/2489E9AD-2EE2-8E00-8EC9-32D5F69181C0/relationships/batch \ --header 'Content-Type: application/json' \ --data '{ "relationships": [] }'Creates multiple relationships sharing the same source entity in a single request. The exactly-one-primary invariant is enforced per item in order; later items in the same (source, type) group observe the state produced by earlier items. Any item that violates the invariant rolls back the entire batch. Items whose (source, target, type) already exists as an active relationship are idempotent re-sends: the stored properties are overwritten with the item’s properties, is_primary is ignored (use PUT on the relationship to change the primary), and the existing row is returned. This differs from the single-create endpoint, which rejects duplicates with 409.
Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Request Bodyrequired
Section titled “Request Bodyrequired”object
object
object
Example
{ "relationships": []}Responses
Section titled “Responses”Created
object
object
Example
[]Bad Request
object
object
Example
{ "code": 400, "details": [ { "Field": "organization_id", "Issue": "must be a valid UUID format" } ], "message": "Request cannot be processed due to invalid input", "status": "error", "timestamp": "2026-01-15T14:32:45Z", "trace_id": "req_2J9K8L7M6N5P4Q3R"}Unauthorized
object
object
Example
{ "code": 401, "details": [ { "Field": "authorization_header", "Issue": "Bearer token is expired or malformed" } ], "message": "Authentication credentials are missing or invalid", "status": "error", "timestamp": "2026-01-15T14:32:45Z", "trace_id": "req_2J9K8L7M6N5P4Q3R"}Forbidden
object
object
Example
{ "code": 403, "details": [ { "Field": "required_scope", "Issue": "requires 'orion:settings:write' scope, but token only has 'orion:settings:read'" } ], "message": "Access denied: insufficient permissions for this resource", "status": "error", "timestamp": "2026-01-15T14:32:45Z", "trace_id": "req_2J9K8L7M6N5P4Q3R"}Not Found
object
object
Example
{ "code": 404, "details": [ { "Field": "organization_id", "Issue": "organization with ID 'a1b2c3d4-e5f6-7890-abcd-ef1234567890' not found" } ], "message": "The requested resource could not be found", "status": "error", "timestamp": "2026-01-15T14:32:45Z", "trace_id": "req_2J9K8L7M6N5P4Q3R"}Conflict
object
object
Example
{ "code": 409, "details": [ { "field": "email", "issue": "must be a valid email address" } ], "message": "Request conflicts with current state of the resource", "status": "error", "timestamp": "2026-01-15T14:32:45Z", "trace_id": "req_2J9K8L7M6N5P4Q3R"}Unprocessable Entity
object
object
Example
{ "code": 422, "details": [ { "field": "email", "issue": "must be a valid email address" } ], "message": "Request data is well-formed but violates business rules", "status": "error", "timestamp": "2026-01-15T14:32:45Z", "trace_id": "req_2J9K8L7M6N5P4Q3R"}Internal Server Error
object
The category of the error
The HTTP status code
Additional details about the error
object
The field that caused the error
The specific issue with the field
A human-readable error message
The status of the response, always ‘error’ for error responses
The timestamp when the error occurred
A unique identifier for tracing the error
Example
{ "category": "server_error", "code": 500, "details": [ { "field": "field_name", "issue": "Field validation issue" } ], "message": "Internal Server Error", "status": "error", "timestamp": "2024-03-15T10:30:00Z", "trace_id": "b7c5e4d3-a2b1-4f0e-8d9c-1a2b3c4d5e6f"}Version 3.14.0 · commit 0771262
