Error when editing API in Cloud Admin app

Hi,

I’m trying to add CORS support for an example API (just learning Tyk) but when I add Allowed Methods I get an error in the Admin Console saying “Couldn’t unmarshal API data”. The request/response is given below:

Request URL:https://admin.cloud.tyk.io/api/apis/5a1763eb8fdd780001c92a27
Request Method:PUT
Status Code:500 Internal Server Error
Remote Address:54.210.238.84:443

Request:
{“api_definition”:{“api_id”:“97644fc2e68844154c4152f62a0a4411”,“upstream_certificates”:{},“use_keyless”:false,“enable_coprocess_auth”: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”:{}}},“disable_quota”:false,“custom_middleware_bundle”:“”,“cache_options”:{“enable_cache”:false,“enable_upstream_cache_control”:false,“cache_timeout”:60,“cache_response_codes”:[],“cache_all_safe_requests”:false},“tag_headers”:[],“domain”:“”,“openid_options”:{“providers”:[],“segregate_by_client”:false},“active”:true,“config_data”:{},“notifications”:{“oauth_on_keychange_url”:“”,“shared_secret”:“”},“auth”:{“auth_header_name”:“Authorization”,“use_param”:true,“param_name”:“authorization”,“use_certificate”:false,“cookie_name”:“”},“check_host_against_uptime_tests”:false,“hmac_allowed_clock_skew”:-1,“uptime_tests”:{“check_list”:[],“config”:{“service_discovery”:{“use_discovery_service”:false,“query_endpoint”:“”,“use_nested_query”:false,“parent_data_path”:“”,“data_path”:“”,“cache_timeout”:60}}},“enable_jwt”:false,“name”:“weather”,“slug”:“weather”,“oauth_meta”:{“allowed_access_types”:[],“allowed_authorize_types”:[],“auth_login_redirect”:“”},“CORS”:{“enable”:true,“max_age”:24,“allow_credentials”:false,“exposed_headers”:[],“allowed_headers”:[],“options_passthrough”:false,“debug”:false,“allowed_origins”:[““],“allowed_methods”:[{“id”:“get”,“name”:“GET”},{“id”:“options”,“name”:“OPTIONS”}]},“event_handlers”:{“events”:{}},“proxy”:{“enable_load_balancing”:false,“listen_path”:”/97644fc2e68844154c4152f62a0a4411/“,“strip_listen_path”:true,“preserve_host_header”:false,“target_list”:[],“target_url”:“https://query.yahooapis.com/v1/public/yql",“service_discovery”:{“cache_timeout”:0,“parent_data_path”:“”,“query_endpoint”:“”,“use_discovery_service”:false,“_sd_show_port_path”:false,“target_path”:“”,“use_nested_query”:false,“data_path”:“”,“port_data_path”:“”},“check_host_against_uptime_tests”:false},“client_certificates”:[],“use_basic_auth”:false,“version_data”:{“not_versioned”:true,“versions”:{“Default”:{“name”:“Default”,“expires”:“”,“override_target”:“”,“extended_paths”:{“url_rewrites”:[{“method”:“GET”,“timeout”:0,“path”:“weather/{city}”,“add_headers”:{},“samples”:100,“rewrite_to”:“?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D\”$1\")&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys”,“template_data”:{“input_type”:”“,“template_mode”:”“,“enable_session”:false,“template_source”:”“},“function_source_uri”:”“,“threshold_percent”:0.1,“delete_headers”:[],“response_function_name”:“myVirtualHandler”,”_lists":[],“match_pattern”:"weather/(.)”,“function_source_type”:“blob”,“return_to_service_after”:60,“size_limit”:0,“use_session”:false,“method_actions”:{}},{“method”:“GET”,“timeout”:0,“path”:“wind/{city}”,“add_headers”:{},“samples”:100,“rewrite_to”:“?q=select%20wind%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22$1%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys”,“template_data”:{“input_type”:“”,“template_mode”:“”,“enable_session”:false,“template_source”:“”},“function_source_uri”:“”,“threshold_percent”:0.1,“delete_headers”:[],“response_function_name”:“myVirtualHandler”,“_lists”:[],“match_pattern”:“wind/(.*)”,“function_source_type”:“blob”,“return_to_service_after”:60,“size_limit”:0,“use_session”:false,“method_actions”:{}}]},“global_headers”:{},“global_headers_remove”:[],“global_size_limit”:0,“use_extended_paths”:true}}},“use_standard_auth”:true,“disable_rate_limit”:false,“definition”:{“key”:“x-api-version”,“location”:“header”},“use_oauth2”:false,“allowed_ips”:[],“org_id”:“5a17549cc72adf00015ee738”,“enable_ip_whitelisting”:false,“global_rate_limit”:{“rate”:0,“per”:0},“enable_context_vars”:false,“tags”:[],“strip_auth_data”:false,“id”:“5a1763eb8fdd780001c92a27”,“enable_signature_checking”:false,“use_openid”:false,“enable_batch_request_support”:false,“response_processors”:[],“use_mutual_tls_auth”:false,“auth_provider”:{“name”:“”,“storage_engine”:“”,“meta”:{}},“do_not_track”:false,“dont_set_quota_on_create”:false,“expire_analytics_after”:0,“session_lifetime”:0},“hook_references”:[],“is_site”:false,“sort_by”:0}

Response:
{“Status”:“Error”,“Message”:“Couldn’t unmarshal API data”,“Meta”:null}

Regards,
Scott

Looks like the JSON is invalid - have you run it through a linter like jsonlint?

It gives a ‘<value> expected. Unexpected end of file’ error. I can’t do much about it though as it’s the Tyk web admin console generating the JSON (i.e. it seems to be an issue with the Tyk web app).

Right - thanks for the heads up, I’ve eacalated to our interface team.

Ok thanks. It seems to work when I save without any allowed methods, but once I nominate one it gives that error. I tried re-logging in from a Chrome incognito browser and IE but got the same result.

Hello!

I can confrim that it is an UI issue, and going to be fixed asap.

In the meantime you can use API to update your definitions. Format of the allowed methods field is just a string array:

"CORS": {
   "allowed_methods": ["GET", "POST"]
   ...
},
1 Like

I can confirm that bug was fixed on our cloud.

Thank you!

1 Like

I face this error “Couldn’t unmarshal API data” in local installation (on premises). Do I need to update to get the fix? Which version? Thanks!

It should be fixed on Dashboard 1.4.2 and Gateway 2.4.2

Thanks! Upgraded Dashboard and able to add the allowed CORS POST method to API.
However, the following error trace occurs, when API called:

time=“Jan 4 18:48:14” level=error msg=“[PROXY] [SERVICE DISCOVERY] Failed target lookup: Get : unsupported protocol scheme ""”
2018/01/04 18:48:14 http: panic serving xxx.xxx.xxx.xxx:58688: runtime error: invalid memory address or nil pointer dereference
goroutine 724374 [running]:
net/http.(*conn).serve.func1(0xc420d9e3c0)
/usr/local/go/src/net/http/server.go:1721 +0xd0
panic(0xcf77a0, 0x13e3830)
/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/TykTechnologies/tyk/apidef.(*HostList).GetIndex(0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/src/github.com/TykTechnologies/tyk/apidef/host_list.go:40 +0xdd
main.nextTarget(0x0, 0xc4201dfc00, 0x2, 0x2, 0x0, 0x1)
/src/github.com/TykTechnologies/tyk/reverse_proxy.go:138 +0x416
main.TykNewSingleHostReverseProxy.func2(0xc420c7ae00)
/src/github.com/TykTechnologies/tyk/reverse_proxy.go:201 +0x8c
main.(*ReverseProxy).WrappedServeHTTP(0xc4203d85f0, 0x1330ee0, 0xc420314c40, 0xc420c7a400, 0x5a4e5a01, 0x0)
/src/github.com/TykTechnologies/tyk/reverse_proxy.go:485 +0x45d
main.(*ReverseProxy).ServeHTTP(0xc4203d85f0, 0x1330ee0, 0xc420314c40, 0xc420c7a400, 0x0)
/src/github.com/TykTechnologies/tyk/reverse_proxy.go:349 +0x60

Hat looks like an invalid api definition causing the target to be malformed. Can you sharethe Api Definition?

{
    "id": "5a26f47c7e4fdd2bfdd20574",
    "name": "Account Sync",
    "slug": "account-sync",
    "api_id": "f1a7bfb4c3d647d16e58038c4263c15a",
    "org_id": "5a187e6a7e4fdd05d97cacff",
    "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_certificate": false
    },
    "use_basic_auth": false,
    "use_mutual_tls_auth": false,
    "client_certificates": [],
    "upstream_certificates": {},
    "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": "header",
        "key": "x-api-version"
    },
    "version_data": {
        "not_versioned": true,
        "versions": {
            "Default": {
                "name": "Default",
                "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": "/account-sync/",
        "target_url": "http://hel-boomi-dev.domain-name.com:9090/ws/rest/EBSCustomerEndpoint/AccountSync/",
        "strip_listen_path": true,
        "enable_load_balancing": false,
        "target_list": [],
        "check_host_against_uptime_tests": false,
        "service_discovery": {
            "use_discovery_service": true,
            "query_endpoint": "",
            "use_nested_query": true,
            "parent_data_path": "node.value",
            "data_path": "hostname",
            "port_data_path": "port",
            "target_path": "/api-slug",
            "use_target_list": false,
            "cache_timeout": 60,
            "endpoint_returns_list": true
        }
    },
    "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": {}
    },
    "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": [],
        "allowed_methods": [
            "POST"
        ],
        "allowed_headers": [],
        "exposed_headers": [],
        "allow_credentials": false,
        "max_age": 24,
        "options_passthrough": false,
        "debug": false
    },
    "domain": "",
    "do_not_track": false,
    "tags": [],
    "enable_context_vars": false,
    "config_data": {},
    "tag_headers": [],
    "global_rate_limit": {
        "rate": -1,
        "per": -1
    },
    "strip_auth_data": true
},

Is that the full object yo retrieved form the dashboard? The Dashboard endpoint takes the api definition as a wrapped single object:

{ 
    "api_definition": {
        "id": "5a26f47c7e4fdd2bfdd20574",
        "name": "Account Sync",
        "slug": "account-sync",
        "api_id": "f1a7bfb4c3d647d16e58038c4263c15a",
...

This could be what’s causing the problem?