3

How can we import talend collection to postman? I found a way to import postman into talend but not the other way round. Is there any script or tool to do the migration?

best wishes
  • 5,789
  • 1
  • 34
  • 59

1 Answers1

0

As the json exported from talend api tester cannot be directly imported into postman, you could write a converter to change its format so it can be accepted by postman's importer (I hope this will be supported officially in github as it's an open issue.).

An example converter in Python is here:

import json

# Open and read the Talend API Tester collection JSON file
with open('export_file.json', 'r') as f:
    talend_data = json.load(f)["entities"]

# Create new Postman collection objects
for folder in talend_data:
    folder_name = folder["entity"]["name"]
    postman_collection = {
        "info": {
            "name": folder_name,
            "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
        },
        "item": [] # all subfolders
    }

    # Loop through the requests in the Talend collection and add them to the Postman collection
    for subfolder in folder["children"]:
        postman_subfolder = {
            "name": subfolder["entity"]["name"],
            "item": []
        }

        for request in subfolder["children"]:
            request = request["entity"]
            name = request["name"]
            method = request["method"]["name"]
            protocol = request["uri"]["scheme"]["name"]
            uri = protocol + "://" + request["uri"]["host"] + request["uri"]["path"]
            headers = []
            for header in request["headers"]:
                header_key = header["name"]
                header_value = header["value"]
                headers.append({
                    "key": header_key,
                    "value" : header_value,
                    "type": "text"
                })


            postman_request = {
                "name": name,
                "protocolProfileBehavior": {
                    "disableBodyPruning": "true"
                },
                "request": {
                    "method": method,
                    "header": headers,
                    "body": {
                        "mode": "formdata",
                        "formdata": []
                    },
                    "url": {
                        "raw": str(uri),
                        "protocol": protocol
                    }
                },
                "response": []
            }
            postman_subfolder["item"].append(postman_request)

        postman_collection["item"].append(postman_subfolder)


    # Write the Postman collection JSON to a file
    with open(str(folder_name) + '.json', 'w') as f:
        json.dump(postman_collection, f)