Chilkat Online Tools

Node.js / Postman API / Merge a Fork

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    var http = new chilkat.Http();
    var success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "strategy": "deleteSource",
    //   "source": "{{source_collection_uid}}",
    //   "destination": "{{destination_collection_uid}}"
    // }

    var json = new chilkat.JsonObject();
    json.UpdateString("strategy","deleteSource");
    json.UpdateString("source","{{source_collection_uid}}");
    json.UpdateString("destination","{{destination_collection_uid}}");

    http.SetRequestHeader("Content-Type","application/json");
    http.SetRequestHeader("X-API-Key","{{postman_api_key}}");

    // resp: HttpResponse
    var resp = http.PostJson3("https://api.getpostman.com/collections/merge","application/json",json);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X POST
	-H "X-API-Key: {{postman_api_key}}"
	-H "Content-Type: application/json"
	-d '{
    "strategy": "deleteSource",
    "source": "{{source_collection_uid}}",
    "destination": "{{destination_collection_uid}}"
}'
https://api.getpostman.com/collections/merge

Postman Collection Item JSON

{
  "name": "Merge a Fork",
  "request": {
    "method": "POST",
    "header": [
      {
        "name": "Content-Type",
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"strategy\": \"deleteSource\",\n    \"source\": \"{{source_collection_uid}}\",\n    \"destination\": \"{{destination_collection_uid}}\"\n}"
    },
    "url": {
      "raw": "https://api.getpostman.com/collections/merge",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "collections",
        "merge"
      ]
    },
    "description": "This endpoint allows you to merge a forked collection back to its destination collection.\n\nOn successful creation of the collection, the response returns the collection `name`, `id` and `uid`.\n\nYou need to specify the fork UID (as `source`) and destination collection UID (as `destination`) in the request body.\n\nOptionally, you can also specify the merge strategy as either `deleteSource` or `updateSourceWithDestination`. Following is an explanation of the merge strategies\n\n| Merge Strategy | Behaviour |\n| --- | --- |\n| deleteSource | Forked collection is deleted after merging |\n| updateSourceWithDestination | Forked collection is up to date with changes in destination collection |\n\nIf the collections cannot be merged (due to conflicts), appropriate error messages will be returned.\n\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
  },
  "response": [
  ]
}