Merge Snapshot into Branch
POST {{apiPath}}/snapshot/{{branchName}}/merge
The POST /snapshot/{{branchName}}/merge merges the snapshot file provided in the request into the branch specified in the request URL.
When you merge a snapshot, if both the snapshot and the existing system define different versions of the same attribute or entity, conflicts will arise. To resolve these conflicts, you must include a conflict-resolutions parameter. This parameter contains a list of instructions that tell the system which version to keep for each conflict. For more information, refer to Conflict resolution data model.
The first sample response demonstrates a successful merge operation without any conflicts.
The second sample response demonstrates a merge conflict created by the example-attribute attribute. Details of this conflict are provided in the conflicts array. Based on this conflict, the conflict-resolutions form in the third request tells the system:
-
There is a conflict for the entity with the ID
9a93b78f-245a-4de4-b030-1ba963ebf2a5. -
The entity creating the conflict is an attribute.
-
To resolve the conflict, take the version of the attribute from the incoming snapshot (
TAKE_SNAPSHOT).
Example Request
-
cURL
-
C#
-
Go
-
HTTP
-
Java
-
jQuery
-
NodeJS
-
Python
-
PHP
-
Ruby
-
Swift
curl --location --globoff '{{apiPath}}/snapshot/{{branchName}}/merge' \
--header 'x-user-id: {{userId}}' \
--form 'snapshot-file=@"24wssF4Eo/example-import-add-resolver.snapshot"' \
--form 'conflict-resolutions="[{\"id\":\"9a93b78f-245a-4de4-b030-1ba963ebf2a5\",\"type\":\"ATTRIBUTE\",\"resolution\":\"TAKE_SNAPSHOT\"}]"'
var options = new RestClientOptions("{{apiPath}}/snapshot/{{branchName}}/merge")
{
MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("", Method.Post);
request.AddHeader("x-user-id", "{{userId}}");
request.AlwaysMultipartFormData = true;
request.AddFile("snapshot-file", "24wssF4Eo/example-import-add-resolver.snapshot");
request.AddParameter("conflict-resolutions", "[{\"id\":\"9a93b78f-245a-4de4-b030-1ba963ebf2a5\",\"type\":\"ATTRIBUTE\",\"resolution\":\"TAKE_SNAPSHOT\"}]");
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
package main
import (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"net/http"
"io"
)
func main() {
url := "{{apiPath}}/snapshot/{{branchName}}/merge"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
file, errFile1 := os.Open("24wssF4Eo/example-import-add-resolver.snapshot")
defer file.Close()
part1,
errFile1 := writer.CreateFormFile("snapshot-file",filepath.Base("24wssF4Eo/example-import-add-resolver.snapshot"))
_, errFile1 = io.Copy(part1, file)
if errFile1 != nil {
fmt.Println(errFile1)
return
}
_ = writer.WriteField("conflict-resolutions", "[{\"id\":\"9a93b78f-245a-4de4-b030-1ba963ebf2a5\",\"type\":\"ATTRIBUTE\",\"resolution\":\"TAKE_SNAPSHOT\"}]")
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("x-user-id", "{{userId}}")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
POST /snapshot/{{branchName}}/merge HTTP/1.1
Host: {{apiPath}}
x-user-id: {{userId}}
Content-Length: 429
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="snapshot-file"; filename="example-import-add-resolver.snapshot"
Content-Type: <Content-Type header here>
(data)
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="conflict-resolutions"
[{"id":"9a93b78f-245a-4de4-b030-1ba963ebf2a5","type":"ATTRIBUTE","resolution":"TAKE_SNAPSHOT"}]
------WebKitFormBoundary7MA4YWxkTrZu0gW--
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("snapshot-file","example-import-add-resolver.snapshot",
RequestBody.create(MediaType.parse("application/octet-stream"),
new File("24wssF4Eo/example-import-add-resolver.snapshot")))
.addFormDataPart("conflict-resolutions","[{\"id\":\"9a93b78f-245a-4de4-b030-1ba963ebf2a5\",\"type\":\"ATTRIBUTE\",\"resolution\":\"TAKE_SNAPSHOT\"}]")
.build();
Request request = new Request.Builder()
.url("{{apiPath}}/snapshot/{{branchName}}/merge")
.method("POST", body)
.addHeader("x-user-id", "{{userId}}")
.addHeader("Content-Length", "")
.build();
Response response = client.newCall(request).execute();
var form = new FormData();
form.append("snapshot-file", fileInput.files[0], "example-import-add-resolver.snapshot");
form.append("conflict-resolutions", "[{\"id\":\"9a93b78f-245a-4de4-b030-1ba963ebf2a5\",\"type\":\"ATTRIBUTE\",\"resolution\":\"TAKE_SNAPSHOT\"}]");
var settings = {
"url": "{{apiPath}}/snapshot/{{branchName}}/merge",
"method": "POST",
"timeout": 0,
"headers": {
"x-user-id": "{{userId}}",
"Content-Length": ""
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});
var request = require('request');
var fs = require('fs');
var options = {
'method': 'POST',
'url': '{{apiPath}}/snapshot/{{branchName}}/merge',
'headers': {
'x-user-id': '{{userId}}',
'Content-Length': ''
},
formData: {
'snapshot-file': {
'value': fs.createReadStream('24wssF4Eo/example-import-add-resolver.snapshot'),
'options': {
'filename': 'example-import-add-resolver.snapshot',
'contentType': null
}
},
'conflict-resolutions': '[{"id":"9a93b78f-245a-4de4-b030-1ba963ebf2a5","type":"ATTRIBUTE","resolution":"TAKE_SNAPSHOT"}]'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
url = "{{apiPath}}/snapshot/{{branchName}}/merge"
payload = {'conflict-resolutions': '[{"id":"9a93b78f-245a-4de4-b030-1ba963ebf2a5","type":"ATTRIBUTE","resolution":"TAKE_SNAPSHOT"}]'}
files=[
('snapshot-file',('example-import-add-resolver.snapshot',open('24wssF4Eo/example-import-add-resolver.snapshot','rb'),'application/octet-stream'))
]
headers = {
'x-user-id': '{{userId}}',
'Content-Length': ''
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('{{apiPath}}/snapshot/{{branchName}}/merge');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'x-user-id' => '{{userId}}',
'Content-Length' => ''
));
$request->addPostParameter(array(
'conflict-resolutions' => '[{"id":"9a93b78f-245a-4de4-b030-1ba963ebf2a5","type":"ATTRIBUTE","resolution":"TAKE_SNAPSHOT"}]'
));
$request->addUpload('snapshot-file', '24wssF4Eo/example-import-add-resolver.snapshot', 'example-import-add-resolver.snapshot', '<Content-Type Header>');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
require "uri"
require "net/http"
url = URI("{{apiPath}}/snapshot/{{branchName}}/merge")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["x-user-id"] = "{{userId}}"
request["Content-Length"] = ""
form_data = [['snapshot-file', File.open('24wssF4Eo/example-import-add-resolver.snapshot')],['conflict-resolutions', '[{"id":"9a93b78f-245a-4de4-b030-1ba963ebf2a5","type":"ATTRIBUTE","resolution":"TAKE_SNAPSHOT"}]']]
request.set_form form_data, 'multipart/form-data'
response = http.request(request)
puts response.read_body
let parameters = [
[
"key": "snapshot-file",
"src": "24wssF4Eo/example-import-add-resolver.snapshot",
"type": "file"
],
[
"key": "conflict-resolutions",
"value": "[{\"id\":\"9a93b78f-245a-4de4-b030-1ba963ebf2a5\",\"type\":\"ATTRIBUTE\",\"resolution\":\"TAKE_SNAPSHOT\"}]",
"type": "text"
]] as [[String: Any]]
let boundary = "Boundary-\(UUID().uuidString)"
var body = Data()
var error: Error? = nil
for param in parameters {
if param["disabled"] != nil { continue }
let paramName = param["key"]!
body += Data("--\(boundary)\r\n".utf8)
body += Data("Content-Disposition:form-data; name=\"\(paramName)\"".utf8)
if param["contentType"] != nil {
body += Data("\r\nContent-Type: \(param["contentType"] as! String)".utf8)
}
let paramType = param["type"] as! String
if paramType == "text" {
let paramValue = param["value"] as! String
body += Data("\r\n\r\n\(paramValue)\r\n".utf8)
} else {
let paramSrc = param["src"] as! String
let fileURL = URL(fileURLWithPath: paramSrc)
if let fileContent = try? Data(contentsOf: fileURL) {
body += Data("; filename=\"\(paramSrc)\"\r\n".utf8)
body += Data("Content-Type: \"content-type header\"\r\n".utf8)
body += Data("\r\n".utf8)
body += fileContent
body += Data("\r\n".utf8)
}
}
}
body += Data("--\(boundary)--\r\n".utf8);
let postData = body
var request = URLRequest(url: URL(string: "{{apiPath}}/snapshot/{{branchName}}/merge")!,timeoutInterval: Double.infinity)
request.addValue("{{userId}}", forHTTPHeaderField: "x-user-id")
request.addValue("", forHTTPHeaderField: "Content-Length")
request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
Example Response
200 OK
{
"branch": {
"id": "939d595f-2807-4aa4-8c5c-629ca391eaa1",
"name": "example-snapshot-import",
"head": "bb23e640-86e0-4373-ab95-64aaf86b4e9a",
"tip": {
"id": "e26f26b8-e388-4220-b699-185fc93e5f19",
"parentId": "bb23e640-86e0-4373-ab95-64aaf86b4e9a",
"state": "UNCOMMITTED",
"commitDetails": {
"userId": null,
"dateTime": null,
"message": null
},
"approvals": [],
"branchId": "939d595f-2807-4aa4-8c5c-629ca391eaa1"
},
"parentId": "62c53d22-f1e1-4507-a208-a983ec5f3e12"
},
"conflicts": [],
"summary": {
"updated": 0,
"inserted": 148,
"skipped": 0,
"conflicts": 0
}
}
Example Response
409 Conflict
{
"branch": {
"id": "0533180c-f7ff-4f4b-a6ed-fc6956a7c91e",
"name": "example-import",
"head": "28768ab7-79d3-4da4-9a09-9ab30c7b0c7a",
"tip": {
"id": "5890fa83-c47f-4ad5-accb-b8f54ead7090",
"parentId": "28768ab7-79d3-4da4-9a09-9ab30c7b0c7a",
"state": "UNCOMMITTED",
"commitDetails": {
"userId": null,
"dateTime": null,
"message": null
},
"approvals": [],
"branchId": "0533180c-f7ff-4f4b-a6ed-fc6956a7c91e"
},
"parentId": "62c53d22-f1e1-4507-a208-a983ec5f3e12"
},
"conflicts": [
{
"id": "9a93b78f-245a-4de4-b030-1ba963ebf2a5",
"type": "ATTRIBUTE",
"name": "example-attribute",
"conflicts": [
"COLLISION"
]
}
],
"summary": {
"updated": 0,
"inserted": 0,
"skipped": 2,
"conflicts": 1
}
}
Example Response
200 OK
{
"branch": {
"id": "0533180c-f7ff-4f4b-a6ed-fc6956a7c91e",
"name": "example-import",
"head": "28768ab7-79d3-4da4-9a09-9ab30c7b0c7a",
"tip": {
"id": "5890fa83-c47f-4ad5-accb-b8f54ead7090",
"parentId": "28768ab7-79d3-4da4-9a09-9ab30c7b0c7a",
"state": "UNCOMMITTED",
"commitDetails": {
"userId": null,
"dateTime": null,
"message": null
},
"approvals": [],
"branchId": "0533180c-f7ff-4f4b-a6ed-fc6956a7c91e"
},
"parentId": "62c53d22-f1e1-4507-a208-a983ec5f3e12"
},
"conflicts": [],
"summary": {
"updated": 1,
"inserted": 0,
"skipped": 2,
"conflicts": 0
}
}