Skip to content

Create an embedded mapping rule

POST
/models/{modelId}/origin-mapping/rules
curl --request POST \
--url https://api.modeldesk.io/models/2489E9AD-2EE2-8E00-8EC9-32D5F69181C0/origin-mapping/rules \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "rule": { "type": "ElementMappingRule", "id": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "name": "example", "description": "example", "nestedRules": [], "targetOwnerId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "targetType": "example", "targetTraits": [ "example" ], "sourcePath": "example", "sourceElementIds": [ "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0" ], "root": false, "targetOwnedRelation": "example", "originModelId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0" }, "parentRuleId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "insertAfterRuleId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0" }'

Create embedded mapping rule

modelId
required
string format: uuid
Media typeapplication/json
object
rule
required

A mapping rule, discriminated by its own type.

One of: discriminator: type
ElementMappingRule
object
type
required

The type of mapping rule (discriminator for polymorphism).

string
Allowed values: ElementMappingRule AttributeMappingRule RelationMappingRule
id

Unique identifier for this rule. Can be client-provided or server-generated.

string format: uuid
name

The rule’s name, where it has one. A stored mapping names its rules; a rule it writes without one is stored under what it produces.

string
description

The author’s note on this rule. Stored as the rule element’s description; a blank note is stored as no note, so saving a rule with the text cleared leaves it without one.

string
nestedRules
Array<object> recursive
targetOwnerId

Optional reference to an existing element to attach this rule’s output to.

string format: uuid
type
required
string
Allowed value: ElementMappingRule
targetType
required

The target element type to create for each matched source element.

string
>= 1 characters
targetTraits

The traits each created element carries beside targetType. Where an owned relation holds the element, the relation decides its form: its default trait is added where the element carries no member of the default’s exclusive group, and replaces a member the relation refuses. Absent when the rule names none.

Array<string>
sourcePath

Path expression to select source elements. Mutually exclusive with sourceElementIds.

string
sourceElementIds

Explicit source element IDs to map. Mutually exclusive with sourcePath.

Array<string>
root

Whether the mapped elements are root elements in the target model.

boolean
targetOwnedRelation

Target owned relation name for nested element mappings. Required when nested under another element mapping.

string
originModelId
required

Reference to the origin model from which source elements are selected.

string format: uuid
parentRuleId

The ID of the parent rule under which this rule should be nested. When null, the rule is created as a top-level rule.

string format: uuid
insertAfterRuleId

The ID of the rule after which this new rule should be inserted. Null = insert at beginning, absent = append to end.

string format: uuid

Created

Media typeapplication/json

A mapping rule, discriminated by its own type.

One of: discriminator: type
ElementMappingRule
object
type
required

The type of mapping rule (discriminator for polymorphism).

string
Allowed values: ElementMappingRule AttributeMappingRule RelationMappingRule
id

Unique identifier for this rule. Can be client-provided or server-generated.

string format: uuid
name

The rule’s name, where it has one. A stored mapping names its rules; a rule it writes without one is stored under what it produces.

string
description

The author’s note on this rule. Stored as the rule element’s description; a blank note is stored as no note, so saving a rule with the text cleared leaves it without one.

string
nestedRules
Array<object> recursive
targetOwnerId

Optional reference to an existing element to attach this rule’s output to.

string format: uuid
type
required
string
Allowed value: ElementMappingRule
targetType
required

The target element type to create for each matched source element.

string
>= 1 characters
targetTraits

The traits each created element carries beside targetType. Where an owned relation holds the element, the relation decides its form: its default trait is added where the element carries no member of the default’s exclusive group, and replaces a member the relation refuses. Absent when the rule names none.

Array<string>
sourcePath

Path expression to select source elements. Mutually exclusive with sourceElementIds.

string
sourceElementIds

Explicit source element IDs to map. Mutually exclusive with sourcePath.

Array<string>
root

Whether the mapped elements are root elements in the target model.

boolean
targetOwnedRelation

Target owned relation name for nested element mappings. Required when nested under another element mapping.

string
originModelId
required

Reference to the origin model from which source elements are selected.

string format: uuid

Example

{
"type": "ElementMappingRule",
"root": false
}

Bad request

Media typeapplication/problem+json

An RFC 9457 problem document, always sent as application/problem+json.

object
type

Present only on a typed refusal, whose own schema requires it and fixes its value. An untyped problem omits it, which RFC 9457 defines as about:blank: the status and title are all there is to branch on.

string format: uri
title
required
string
status
required
integer
detail
required
string
instance

The path of the request that was refused. Absent when the request was refused before it reached the application’s handlers: a 401 for a missing or unusable access token, and a 403 for a service account whose scopes do not reach the route.

string
violations

Present on a 400 raised by request-body validation, and on a 422 that refuses named fields (a malformed slug or namespace prefix). Each entry names the rejected property, so a client can attach the message to the field that caused it rather than showing one error for the whole form.

Array<object>
object
property
required
string
message
required
string

Example generated

{
"type": "https://example.com",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"violations": [
{
"property": "example",
"message": "example"
}
]
}

Not found

Media typeapplication/problem+json

An RFC 9457 problem document, always sent as application/problem+json.

object
type

Present only on a typed refusal, whose own schema requires it and fixes its value. An untyped problem omits it, which RFC 9457 defines as about:blank: the status and title are all there is to branch on.

string format: uri
title
required
string
status
required
integer
detail
required
string
instance

The path of the request that was refused. Absent when the request was refused before it reached the application’s handlers: a 401 for a missing or unusable access token, and a 403 for a service account whose scopes do not reach the route.

string
violations

Present on a 400 raised by request-body validation, and on a 422 that refuses named fields (a malformed slug or namespace prefix). Each entry names the rejected property, so a client can attach the message to the field that caused it rather than showing one error for the whole form.

Array<object>
object
property
required
string
message
required
string

Example generated

{
"type": "https://example.com",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"violations": [
{
"property": "example",
"message": "example"
}
]
}

Error

Media typeapplication/problem+json

An RFC 9457 problem document, always sent as application/problem+json.

object
type

Present only on a typed refusal, whose own schema requires it and fixes its value. An untyped problem omits it, which RFC 9457 defines as about:blank: the status and title are all there is to branch on.

string format: uri
title
required
string
status
required
integer
detail
required
string
instance

The path of the request that was refused. Absent when the request was refused before it reached the application’s handlers: a 401 for a missing or unusable access token, and a 403 for a service account whose scopes do not reach the route.

string
violations

Present on a 400 raised by request-body validation, and on a 422 that refuses named fields (a malformed slug or namespace prefix). Each entry names the rejected property, so a client can attach the message to the field that caused it rather than showing one error for the whole form.

Array<object>
object
property
required
string
message
required
string

Example generated

{
"type": "https://example.com",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"violations": [
{
"property": "example",
"message": "example"
}
]
}