Transform_response works with blob but not file

Hi I am trying to transform api response using tyk.
Below is the code
“transform_response”: [{
“path”: “Student/{id}”,
“method”: “GET”,
“template_data”: {
“template_mode”: “file”,
“template_source”: “./templates/student_response.tmpl”,
“input_type”: “json”
}
}
],

If i do the same code using blob template mode it works fine but not with file.

I have student_response.tmpl file with below contents


in templates folder located in root directory.
{
“id”: “{{.ver}}”
}

Just tried it now and it works fine for me. What version of gateway are you using and also what was the result?

Additionally could you share the gateway debug log of the call. Considering you are using docker, I assume you have mapped your volumes.

I am using tyk-gateway:v3.2.1
and response is coming as it is as from api its not getting transformed. No error is logged here.

templates folder i have placed in root folder. Is it fine or should be moved to a specific location?

@Saloni_Parekh I am checking this. My guess is there is something wrong/missing in the API definition as. I have 2 relatively similar API def and it’s working for one and not the other

I am still trying to figure out what property is causing the issue. In the meantime, can you try using the API definition below as is and testing if it works on your gateway version

{
    "active": true,
    "api_id": "8eb436d773734dff573b277fe30961c9",
    "auth_configs": {
        "authToken": {
            "auth_header_name": "Authorization"
        }
    },
		"custom_middleware_bundle": "test-bundle",
    "definition": {
        "key": "x-api-version",
        "location": "header"
    },
		"enable_context_vars": true,
    "name": "Demo Transform",
    "org_id": "1",
    "proxy": {
        "listen_path": "/transform/",
        "strip_listen_path": true,
        "target_url": "http://httpbin.org/anything"
    },
		"response_processors": [
        {
            "name": "response_body_transform",
            "options": {
            }
        }
    ],
    "slug": "demo-transform",
		"use_keyless": true,
    "version_data": {
        "default_version": "",
        "not_versioned": true,
        "versions": {
            "Default": {
                "expires": "",
                "extended_paths": {
                    "transform_response": [
                        {
                            "method": "GET",
                            "path": "blob01",
                            "template_data": {
                                "enable_session": false,
                                "input_type": "json",
                                "template_mode": "blob",
                                "template_source": "ewogICAgInN0cmluZyI6ICJUaGlzIGlzIGEganNvbiBzdHJpbmchIiwKICAgICJpbnQiOiAxMgp9"
                            }
                        },
                        {
                            "method": "GET",
                            "path": "blob02",
                            "template_data": {
                                "enable_session": false,
                                "input_type": "json",
                                "template_mode": "blob",
                                "template_source": "ewogICJpZCI6ICJ7ey52ZXJ9fSIKfQ=="
                            }
                        },
												{
                            "method": "GET",
                            "path": "file",
                            "template_data": {
                                "enable_session": false,
                                "input_type": "json",
                                "template_mode": "file",
                                "template_source": "./templates/transform_test.tmpl"
                            }
                        }
                    ]
                },
                "global_headers": {
									"X-Real-IP": "$tyk_context.headers_X-Real-IP",
									"X-Tyk-Real-IP": "$tyk_context.remote_addr",
									"X-Tyk-X-Forwarded-For": "$tyk_context.headers_X_Forwarded_For"
								},
                "global_headers_remove": [
                ],
                "global_response_headers": {
                },
                "global_response_headers_remove": [
                ],
                "global_size_limit": 0,
                "ignore_endpoint_case": false,
                "name": "Default",
                "override_target": "",
                "paths": {
                    "black_list": [
                    ],
                    "ignored": [
                    ],
                    "white_list": [
                    ]
                },
                "use_extended_paths": true
            }
        }
    }
}

I tried this exact same api but it dint transform the response. Also GET method work just fine with blob. But for POST methods also transform_response isnt working with blob as well as file

Could you check your config file and ensure the template_path is correct. The value should be something like this

"template_path": "./templates",

I asked a colleague to confirm as well. We both can get file mode and post for blob mode to work. If you are still facing challenges, could you try to isolate a test case for each method. If it helps I will share my full API definition.

{
    "name": "Demo Transform Response",
    "slug": "demo-transform",
    "listen_port": 0,
    "protocol": "",
    "enable_proxy_protocol": false,
    "api_id": "transform-response",
    "org_id": "default",
    "use_keyless": true,
    "use_oauth2": false,
    "use_openid": false,
    "openid_options": {
        "providers": null,
        "segregate_by_client": false
    },
    "oauth_meta": {
        "allowed_access_types": null,
        "allowed_authorize_types": null,
        "auth_login_redirect": ""
    },
    "auth": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": "",
        "use_certificate": false,
        "validate_signature": false,
        "signature": {
            "algorithm": "",
            "header": "",
            "secret": "",
            "allowed_clock_skew": 0,
            "error_code": 0,
            "error_message": ""
        }
    },
    "auth_configs": {
        "authToken": {
            "use_param": false,
            "param_name": "",
            "use_cookie": false,
            "cookie_name": "",
            "auth_header_name": "Authorization",
            "use_certificate": false,
            "validate_signature": false,
            "signature": {
                "algorithm": "",
                "header": "",
                "secret": "",
                "allowed_clock_skew": 0,
                "error_code": 0,
                "error_message": ""
            }
        }
    },
    "use_basic_auth": false,
    "basic_auth": {
        "disable_caching": false,
        "cache_ttl": 0,
        "extract_from_body": false,
        "body_user_regexp": "",
        "body_password_regexp": ""
    },
    "use_mutual_tls_auth": false,
    "client_certificates": null,
    "upstream_certificates": null,
    "pinned_public_keys": null,
    "enable_jwt": false,
    "use_standard_auth": false,
    "use_go_plugin_auth": false,
    "enable_coprocess_auth": false,
    "jwt_signing_method": "",
    "jwt_source": "",
    "jwt_identity_base_field": "",
    "jwt_client_base_field": "",
    "jwt_policy_field_name": "",
    "jwt_default_policies": null,
    "jwt_issued_at_validation_skew": 0,
    "jwt_expires_at_validation_skew": 0,
    "jwt_not_before_validation_skew": 0,
    "jwt_skip_kid": false,
    "jwt_scope_to_policy_mapping": null,
    "jwt_scope_claim_name": "",
    "notifications": {
        "shared_secret": "",
        "oauth_on_keychange_url": ""
    },
    "enable_signature_checking": false,
    "hmac_allowed_clock_skew": 0,
    "hmac_allowed_algorithms": null,
    "request_signing": {
        "is_enabled": false,
        "secret": "",
        "key_id": "",
        "algorithm": "",
        "header_list": null,
        "certificate_id": "",
        "signature_header": ""
    },
    "base_identity_provided_by": "",
    "definition": {
        "location": "header",
        "key": "x-api-version",
        "strip_path": false
    },
    "version_data": {
        "not_versioned": true,
        "default_version": "",
        "versions": {
            "Default": {
                "name": "Default",
                "expires": "",
                "paths": {
                    "ignored": [],
                    "white_list": [],
                    "black_list": []
                },
                "use_extended_paths": true,
                "extended_paths": {
                    "transform_response": [
                        {
                            "template_data": {
                                "input_type": "json",
                                "template_mode": "blob",
                                "enable_session": false,
                                "template_source": "ew0KICAgICJibG9iLWdldCI6ICJUaGlzIGlzIGEgdHJhbnNmb3JtIHJlc3BvbnNlIGJsb2IgZ2V0Ig0KfQ=="
                            },
                            "path": "blob-get",
                            "method": "GET"
                        },
                        {
                            "template_data": {
                                "input_type": "json",
                                "template_mode": "blob",
                                "enable_session": false,
                                "template_source": "ewogICAgImJsb2ItcG9zdCI6ICJUaGlzIGlzIGEgdHJhbnNmb3JtIHJlc3BvbnNlIGJsb2IgcG9zdCIKfQ=="
                            },
                            "path": "blob-post",
                            "method": "POST"
                        },
                        {
                            "template_data": {
                                "input_type": "json",
                                "template_mode": "file",
                                "enable_session": false,
                                "template_source": "./templates/transform_response_get.tmpl"
                            },
                            "path": "file-get",
                            "method": "GET"
                        },
                        {
                            "template_data": {
                                "input_type": "json",
                                "template_mode": "file",
                                "enable_session": false,
                                "template_source": "./templates/transform_response_post.tmpl"
                            },
                            "path": "file-post",
                            "method": "POST"
                        }
                    ]
                },
                "global_headers": {},
                "global_headers_remove": [],
                "global_response_headers": {},
                "global_response_headers_remove": [],
                "ignore_endpoint_case": false,
                "global_size_limit": 0,
                "override_target": ""
            }
        }
    },
    "uptime_tests": {
        "check_list": null,
        "config": {
            "expire_utime_after": 0,
            "service_discovery": {
                "use_discovery_service": false,
                "query_endpoint": "",
                "use_nested_query": false,
                "parent_data_path": "",
                "data_path": "",
                "port_data_path": "",
                "target_path": "",
                "use_target_list": false,
                "cache_timeout": 0,
                "endpoint_returns_list": false
            },
            "recheck_wait": 0
        }
    },
    "proxy": {
        "preserve_host_header": false,
        "listen_path": "/transform-response/",
        "target_url": "http://httpbin.org/anything",
        "disable_strip_slash": true,
        "strip_listen_path": true,
        "enable_load_balancing": false,
        "target_list": null,
        "check_host_against_uptime_tests": false,
        "service_discovery": {
            "use_discovery_service": false,
            "query_endpoint": "",
            "use_nested_query": false,
            "parent_data_path": "",
            "data_path": "",
            "port_data_path": "",
            "target_path": "",
            "use_target_list": false,
            "cache_timeout": 0,
            "endpoint_returns_list": false
        },
        "transport": {
            "ssl_insecure_skip_verify": false,
            "ssl_ciphers": null,
            "ssl_min_version": 0,
            "ssl_max_version": 0,
            "ssl_force_common_name_check": false,
            "proxy_url": ""
        }
    },
    "disable_rate_limit": false,
    "disable_quota": false,
    "custom_middleware": {
        "pre": null,
        "post": null,
        "post_key_auth": null,
        "auth_check": {
            "name": "",
            "path": "",
            "require_session": false,
            "raw_body_only": false
        },
        "response": null,
        "driver": "",
        "id_extractor": {
            "extract_from": "",
            "extract_with": "",
            "extractor_config": null
        }
    },
    "custom_middleware_bundle": "",
    "cache_options": {
        "cache_timeout": 0,
        "enable_cache": false,
        "cache_all_safe_requests": false,
        "cache_response_codes": null,
        "enable_upstream_cache_control": false,
        "cache_control_ttl_header": "",
        "cache_by_headers": null
    },
    "session_lifetime": 0,
    "active": true,
    "internal": false,
    "auth_provider": {
        "name": "",
        "storage_engine": "",
        "meta": null
    },
    "session_provider": {
        "name": "",
        "storage_engine": "",
        "meta": null
    },
    "event_handlers": {
        "events": null
    },
    "enable_batch_request_support": false,
    "enable_ip_whitelisting": false,
    "allowed_ips": null,
    "enable_ip_blacklisting": false,
    "blacklisted_ips": null,
    "dont_set_quota_on_create": false,
    "expire_analytics_after": 0,
    "response_processors": [
        {
            "name": "response_body_transform",
            "options": {}
        }
    ],
    "CORS": {
        "enable": false,
        "allowed_origins": null,
        "allowed_methods": null,
        "allowed_headers": null,
        "exposed_headers": null,
        "allow_credentials": false,
        "max_age": 0,
        "options_passthrough": false,
        "debug": false
    },
    "domain": "",
    "certificates": null,
    "do_not_track": false,
    "tags": null,
    "enable_context_vars": false,
    "config_data": null,
    "tag_headers": null,
    "global_rate_limit": {
        "rate": 0,
        "per": 0
    },
    "strip_auth_data": false,
    "enable_detailed_recording": false,
    "graphql": {
        "enabled": false,
        "execution_mode": "",
        "version": "",
        "schema": "",
        "type_field_configurations": null,
        "playground": {
            "enabled": false,
            "path": ""
        },
        "engine": {
            "field_configs": null,
            "data_sources": null
        }
    }
}