MERGE_INSERT Metadata Action Tag

MERGE_INSERT Metadata Action Tag
lac52
When accessing data from a remote system that acts as the "system of record" for certain data, you can acquire the data and do the following using the 
MERGE_INSERT
 metadata action tag:
  • (If the remote data is new) Insert new local rows.
  • (If the remote data has already been inserted, but needs to be updated) Update local rows.
This metadata action is also referred to as an upsert. You can use options in the
@metadata
 action tag using the 
SysUtility.restPut
 method. The 
MERGE_INSERT
 metadata action tag is a combination of the 
INSERT
,
UPDATE
, and the 
LOOKUP
 metadata action tags.
Layer7 Live API Creator
 finds records using the de-aliased resource attributes that are selected as the effective primary key for the resource (the
Key
checkbox for the resource attribute is selected). If 
Layer7 Live API Creator
finds a record, it updates the record with the values that you provide. If it does not find a record, it inserts a new record with the values that you provide.
Checksum
is not required and is implicitly override.
For more information:
In this article:
Insert or Update using PUT
Insert or update using id field updated
{
  "@metadata" : {
    "action":"
MERGE_INSERT
",
    "key":"name"
   },
   "name":"David 1",
   "some_val":199
}
Insert or update using id field, name field updated
{
   "@metadata" : {
     "action":"
MERGE_INSERT
",
     "key":"id"
    },
    "id": 10,
    "name":"David 2",
    "some_val":199
}
Insert or update using multiple fields id and name field updated using an array of field names
{
  "@metadata" : {
    "action":"
MERGE_INSERT
",
    "key":["id","name"]
   },
   "id": 10,
   "name":"David 2",
   "some_val":199
}
Insert or update using primary key (id field), name field updated
{
  "@metadata" : {
    "action":"
MERGE_INSERT
"
    },
    "id": 10,
    "name":"David 2",
    "some_val":199
}
{
  "@metadata" : {
    "action":"
MERGE_INSERT
",
    "key":"name"
   },
   "name":"David 2",
   "some_val":200
}
Combine Action LOOKUP and MERGE_INSERT
The following example is from the Demo API sample. This example shows an upsert on the parent and a lookup of the product name in the items using a resource:
PUT: http://localhost:8080/rest/default/demo/v1/OrderLookupParent
Request payload:
    "@metadata": {"action":"
INSERT
"},
    "Customer": {
       "@metadata": { "action":"
MERGE_INSERT
", "key":["Name","credit_limit"]},
       "Name":"Alpha and Son 2",
       "credit_limit": 1000
    },
    "Items":[
           {
           "Product":
           { 
              "@metadata": {"action":"
LOOKUP
", "key":"ProductName"},
              "ProductName":"Hammer"
           },
              "Quantity": 1
           }
     ]
}
See the sample  file.