How to setup versioning?

Hi,
I want to setup a /v1 version on the API but i’m kind of lost as to how to do this on the dashboard?

What value should I pass in this field? “Override target host”

This wasn’t straight forward to understand from the docs.

Any help is appreciated, thank you.

Hi Pavan,

the “Override Target Host” is optional.

Thanks,
Kos @ Tyk Support Team

So, I just set the version as “v1” and i don’t know why it’s not working:

If I query the URL as http://<url>/v1/api-slug I get a nginx 404 not found
But if I query it as http://<url>/api-slug/v1 I see “Access to this API has been disallowed”

What am I doing wrong?

Can you share your API definition ?

Thanks,
Kos @ Tyk Support Team

Hi Kos,

Here’s the relevant part:

"definition": {
    "location": "url",
    "key": "x-api-version"
},
"version_data": {
    "not_versioned": false,
    "versions": {
        "v1": {
            "name": "v1",
            "expires": "",
            "paths": {
                "ignored": [],
                "white_list": [],
                "black_list": []
            },
            "use_extended_paths": true,
            "extended_paths": {},
            "global_headers": {},
            "global_headers_remove": [],
            "global_size_limit": 0,
            "override_target": ""
        }
    }
},

Do you want me to share the entire API definition?

Hi Pavan,

yes that would be more useful.

Thanks,
Kos @ Tyk support team

Hi Pavan,

your versioned API should be accessible via http://<url>/api-slug/v1/.
The error you mentioned is about authorization, so it comes from a Policy or a Token.

Thanks,
Kos @ Tyk Support Team

Hi,
I tried changing the default policy to have the new ‘v1’ access right and for some reason, I now get
Cannot GET /v1/
error message back if I try with the new URL http://<url>/api-slug/v1/.

For reference, here’s the API export:

 {
"id": "595e5d0e08e9470001d408b5",
"name": "test",
"slug": "test",
"api_id": "ff8dacf41a0e4e2769350f6e72f798dc",
"org_id": "595bcd331cbfd800013b226e",
"use_keyless": false,
"use_oauth2": false,
"use_openid": false,
"openid_options": {
    "providers": [],
    "segregate_by_client": false
},
"oauth_meta": {
    "allowed_access_types": [],
    "allowed_authorize_types": [],
    "auth_login_redirect": ""
},
"auth": {
    "use_param": false,
    "param_name": "",
    "use_cookie": false,
    "cookie_name": "",
    "auth_header_name": "Authorization"
},
"use_basic_auth": false,
"enable_jwt": false,
"use_standard_auth": true,
"enable_coprocess_auth": false,
"jwt_signing_method": "",
"jwt_source": "",
"jwt_identity_base_field": "",
"jwt_client_base_field": "",
"jwt_policy_field_name": "",
"notifications": {
    "shared_secret": "",
    "oauth_on_keychange_url": ""
},
"enable_signature_checking": false,
"hmac_allowed_clock_skew": -1,
"base_identity_provided_by": "",
"definition": {
    "location": "url",
    "key": "x-api-version"
},
"version_data": {
    "not_versioned": false,
    "versions": {
        "v1": {
            "name": "v1",
            "expires": "",
            "paths": {
                "ignored": [],
                "white_list": [],
                "black_list": []
            },
            "use_extended_paths": true,
            "extended_paths": {},
            "global_headers": {},
            "global_headers_remove": [],
            "global_size_limit": 0,
            "override_target": ""
        }
    }
},
"uptime_tests": {
    "check_list": [],
    "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": 60,
            "endpoint_returns_list": false
        },
        "recheck_wait": 0
    }
},
"proxy": {
    "preserve_host_header": false,
    "listen_path": "/ff8dacf41a0e4e2769350f6e72f798dc/",
    "target_url": "http://<URL>",
    "strip_listen_path": true,
    "enable_load_balancing": false,
    "target_list": [],
    "check_host_against_uptime_tests": false,
    "service_discovery": {
        "use_discovery_service": false,
        "query_endpoint": "",
        "use_nested_query": false,
        "parent_data_path": "",
        "data_path": "hostname",
        "port_data_path": "port",
        "target_path": "/api-slug",
        "use_target_list": false,
        "cache_timeout": 60,
        "endpoint_returns_list": false
    }
},
"disable_rate_limit": false,
"disable_quota": false,
"custom_middleware": {
    "pre": [],
    "post": [],
    "post_key_auth": [],
    "auth_check": {
        "name": "",
        "path": "",
        "require_session": false
    },
    "response": [],
    "driver": "",
    "id_extractor": {
        "extract_from": "",
        "extract_with": "",
        "extractor_config": {}
    }
},
"custom_middleware_bundle": "",
"cache_options": {
    "cache_timeout": 60,
    "enable_cache": true,
    "cache_all_safe_requests": false,
    "cache_response_codes": [],
    "enable_upstream_cache_control": false
},
"session_lifetime": 0,
"active": true,
"auth_provider": {
    "name": "",
    "storage_engine": "",
    "meta": {}
},
"session_provider": {
    "name": "",
    "storage_engine": "",
    "meta": null
},
"event_handlers": {
    "events": {}
},
"enable_batch_request_support": false,
"enable_ip_whitelisting": false,
"allowed_ips": [],
"dont_set_quota_on_create": false,
"expire_analytics_after": 0,
"response_processors": [],
"CORS": {
    "enable": true,
    "allowed_origins": [
        "http://localhost"
    ],
    "allowed_methods": [
        "GET",
        "OPTIONS"
    ],
    "allowed_headers": [],
    "exposed_headers": [],
    "allow_credentials": false,
    "max_age": 24,
    "options_passthrough": true,
    "debug": false
},
"domain": "",
"do_not_track": false,
"tags": [],
"enable_context_vars": false
}

Hi Pavan,

the config looks good.
What is the cURL command you’ve tried ?
Can you try curl -v -H 'authorization: xxxx' https://xxx.cloud.tyk.io/ff8dacf41a0e4e2769350f6e72f798dc/v1/ ?
/ff8dacf41a0e4e2769350f6e72f798dc/ is your listen_path.

Thanks,
Kos @ Tyk Support Team

Hi,
Thanks Kos.
Here’s the output of the curl command:

<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.9.0</center>
</body>
</html>
1 Like

Should be:

curl -v -H 'authorization: xxxx' https://xxx.cloud.tyk.io/test/v1/{whatever}

You are in Tyk Cloud, so you must use the slug, the listen path is an internal ID used by our routing layer.

The correct URL should be displayed i the API Designer when you edit the API.