Create api token error

I’m useing tyk-gateway_2.3 now。

I have some error when i create token

error_log

time=“Jan 5 18:36:13” level=error msg=“Key creation failed.” err=“invalid character ‘"’ after object key:value pair” status=fail

create api commadn

curl -H “x-tyk-authorization: 352d20ee67be67f6340b4c0605b044b7” -s -H “Content-Type: application/json” -X POST -d ‘{
“name”: “Test API”,
“slug”: “test-api”,
“api_id”: “1”,
“org_id”: “1”,
“auth”: {
“use_param”: false,
“param_name”: “”,
“use_cookie”: false,
“cookie_name”: “”,
“auth_header_name”: “”
},
“definition”: {
“location”: “header”,
“key”: “x-api-version”
},
“version_data”: {
“not_versioned”: true,
“versions”: {
“Default”: {
“name”: “Default”,
“use_extended_paths”: true
}
}
},
“auth_provider”: {
“name”: “”,
“storage_engine”: “”,
“meta”: {}
},
“proxy”: {
“listen_path”: “/test-api/”,
“target_url”: “http://test.com/”,
“strip_listen_path”: true
},
“active”: true
}’ http://10.15.207.132:8080/tyk/apis/ | python -mjson.tool

create api token command

curl -X POST -H “x-tyk-authorization: 352d20ee67be67f6340b4c0605b044b7” -s -H “Content-Type: application/json” -X POST -d ‘{
“allowance”: 1000,
“rate”: 1000,
“per”: 60,
“expires”: -1,
“quota_max”: -1,
“quota_renews”: 1406121006,
“quota_remaining”: 0,
“quota_renewal_rate”: 60,
“access_rights”: {
“1”: {
“api_name”: “Test API”,
“api_id”: “1”,
“versions”: [“Default”]
}
},
“org_id”: “1”,
“meta_data”: {},
“oauth_client_id”: “”
“oauth_keys”
“basic_auth_data”: {
“password”: “”,
“hash_type”: “”
},
“jwt_data”: {
“secret”: “”
},
“hmac_enabled”: false,
“hmac_string”: “”,
“is_inactive”: false,
“apply_policy_id”: “”
“monitor”: {
“trigger_limits”:
},
“tags”:
}’ http://10.15.207.132:8080/tyk/keys/create | python -mjson.tool

after api token command

{
“status”: “system error, please contact administrator”
}

How can I solve this problem?

Hi steelhorn,

we suggest to put your data into a file and use -d @filename.json syntax for including data.
Also make sure you lint your JSON object, you may use JSONLint.

Thanks,
Kos @ Tyk Support Team

HI Kos,

Thank you for your reply

.

I used the way of the file and execute the command.

curl -X POST -H “x-tyk-authorization: 352d20ee67be67f6340b4c0605b044b7” -s -H “Content-Type: application/json” -X POST -d ‘@1.jsonhttp://10.15.207.132:8080/tyk/keys/create | python -mjson.tool

Returned the error message:
No JSON object could be decoded

tyk stderr

time=“Jan 6 10:08:25” level=info msg=“Reset quota for key.” inbound-key=“****65e7” key=quota-d7df69d6
2017/01/06 10:08:25 http: panic serving 10.15.207.132:60903: runtime error: invalid memory address or nil pointer dereference
goroutine 1107839 [running]:
net/http.(*conn).serve.func1(0xc420986680)
/usr/local/go/src/net/http/server.go:1491 +0x12a
panic(0xcb24a0, 0xc420010050)
/usr/local/go/src/runtime/panic.go:458 +0x243
main.(*DefaultSessionManager).ResetQuota(0xc420436670, 0xc420903aa0, 0x20, 0x0, 0x408f400000000000, 0x408f400000000000, 0x404e000000000000, 0xffffffffffffffff, 0xffffffffffffffff, 0x53cfb42e, …)
/src/github.com/TykTechnologies/tyk/auth_manager.go:110 +0x452
main.createKeyHandler(0x12541e0, 0xc4207fe680, 0xc4200bf2c0)
/src/github.com/TykTechnologies/tyk/api.go:1332 +0x28cd
main.CheckIsAPIOwner.func1(0x12541e0, 0xc4207fe680, 0xc4200bf2c0)
/src/github.com/TykTechnologies/tyk/middleware_api_security_handler.go:24 +0x2ae
net/http.HandlerFunc.ServeHTTP(0xc4200d17e0, 0x12541e0, 0xc4207fe680, 0xc4200bf2c0)
/usr/local/go/src/net/http/server.go:1726 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc4203bd7c0, 0x12541e0, 0xc4207fe680, 0xc4200bf2c0)
/src/github.com/gorilla/mux/mux.go:114 +0x10d
net/http.(*ServeMux).ServeHTTP(0x1319fa0, 0x12541e0, 0xc4207fe680, 0xc4200bf0e0)
/usr/local/go/src/net/http/server.go:2022 +0x7f
net/http.serverHandler.ServeHTTP(0xc420986100, 0x12541e0, 0xc4207fe680, 0xc4200bf0e0)
/usr/local/go/src/net/http/server.go:2202 +0x7d
net/http.(*conn).serve(0xc420986680, 0x1255120, 0xc4209d0980)
/usr/local/go/src/net/http/server.go:1579 +0x4b7
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2293 +0x44d

How can I solve this problem?

Hi steelhorn,

how is your API configured ?
Could you provide your tyk.conf ?

Thanks,
Kos @ Tyk Support Team

HI Kos,

this is my conf

{
“listen_port”: 8080,
“secret”: “352d20ee67be67f6340b4c0605b044b7”,
“template_path”: “/opt/tyk-gateway/templates”,
“tyk_js_path”: “/opt/tyk-gateway/js/tyk.js”,
“use_db_app_configs”: false,
“app_path”: “/opt/tyk-gateway/apps”,
“middleware_path”: “/opt/tyk-gateway/middleware”,
“storage”: {
“type”: “redis”,
“host”: “10.15.207.132”,
“port”: 6379,
“username”: “”,
“password”: “”,
“database”: 0,
“optimisation_max_idle”: 2000,
“optimisation_max_active”: 4000
},
“enable_analytics”: false,
“analytics_config”: {
“type”: “csv”,
“pool_size”: 100,
“csv_dir”: “/tmp”,
“mongo_url”: “”,
“mongo_db_name”: “”,
“mongo_collection”: “”,
“purge_delay”: -1,
“ignored_ips”: [],
“normalise_urls”: {
“enabled”: true,
“normalise_uuids”: true,
“normalise_numbers”: true,
“custom_patterns”: []
}
},
“health_check”: {
“enable_health_checks”: false,
“health_check_value_timeouts”: 60
},
“optimisations_use_async_session_write”: true,
“allow_master_keys”: false,
“policies”: {
“policy_source”: “file”,
“policy_record_name”: “./policies/policies.json”
},
“hash_keys”: true,
“suppress_redis_signal_reload”: false,
“close_connections”: true,
“enable_non_transactional_rate_limiter”: true,
“enable_sentinel_rate_limiter”: false,
“local_session_cache”: {
“disable_cached_session_state”: false
},
“uptime_tests”: {
“disable”: false,
“config”: {
“enable_uptime_analytics”: false,
“failure_trigger_sample_size”: 3,
“time_wait”: 300,
“checker_pool_size”: 50
}
},
“http_server_options”: {
“enable_websockets”: true
},
“hostname”: “”,
“enable_custom_domains”: true,
“enable_jsvm”: true,
“oauth_redirect_uri_separator”: “;”,
“coprocess_options”: {
“enable_coprocess”: false,
“coprocess_grpc_server”: “”
},
“pid_file_location”: “./tyk-gateway.pid”,
“allow_insecure_configs”: true,
“public_key_path”: “”,
“close_idle_connections”: false,
“allow_remote_config”: false,
“enable_bundle_downloader”: true,
“bundle_base_url”: “”,
“global_session_lifetime”: 100,
“force_global_session_lifetime”: false,
“max_idle_connections_per_host”: 100
}

Thank you for your reply

Hi steelhorn,

That error is because the API ID you are using isn’t the right one.

APIs in the dash have two representations, the ObjectID (DB PK) and the API ID - the API ID is the portable bit, and is what is used everywhere, this is the one that shows up beside the API name in the API list.

The internal object ID is different, and is used by the Dashboard API to view the API (this is the id field or the bit in the browser when you browse to the API).

Thanks,
Kos @ Tyk Support Team

Hi Kos:

I used the command to add the APIS
How can I get API ID without using dashboard?

Hi steelhorn,

there are two ways of getting an API ID:

  1. Since all API definitions are stored in Mongo you can query the DB, or

  2. You could send an HTTP request to the Dashboard API, check this section in our documentation.

Thanks,
Kos @ Tyk Support Team

Hi Kos:

{
“listen_port”: 8080,
“secret”: “352d20ee67be67f6340b4c0605b044b7”,
“template_path”: “/opt/tyk-gateway/templates”,
“tyk_js_path”: “/opt/tyk-gateway/js/tyk.js”,
“use_db_app_configs”: false,
“app_path”: “/opt/tyk-gateway/apps”,
“middleware_path”: “/opt/tyk-gateway/middleware”,
“storage”: {
“type”: “redis”,
“host”: “10.15.207.132”,
“port”: 6379,
“username”: “”,
“password”: “”,
“database”: 0,
“optimisation_max_idle”: 2000,
“optimisation_max_active”: 4000
},
“enable_analytics”: false,
“analytics_config”: {
“type”: “csv”,
“pool_size”: 100,
“csv_dir”: “/tmp”,
“mongo_url”: “mongodb://10.15.207.132/”,
“mongo_db_name”: “tyk_analytics”,
“mongo_collection”: “tyk_analytics”,
“purge_delay”: -1,
“ignored_ips”: [],
“normalise_urls”: {
“enabled”: true,
“normalise_uuids”: true,
“normalise_numbers”: true,
“custom_patterns”: []
}
},
“health_check”: {
“enable_health_checks”: false,
“health_check_value_timeouts”: 60
},
“optimisations_use_async_session_write”: true,
“allow_master_keys”: false,
“policies”: {
“policy_source”: “file”,
“policy_record_name”: “./policies/policies.json”
},
“hash_keys”: true,
“suppress_redis_signal_reload”: false,
“close_connections”: true,
“enable_non_transactional_rate_limiter”: true,
“enable_sentinel_rate_limiter”: false,
“local_session_cache”: {
“disable_cached_session_state”: false
},
“uptime_tests”: {
“disable”: false,
“config”: {
“enable_uptime_analytics”: false,
“failure_trigger_sample_size”: 3,
“time_wait”: 300,
“checker_pool_size”: 50
}
},
“http_server_options”: {
“enable_websockets”: true
},
“hostname”: “”,
“enable_custom_domains”: true,
“enable_jsvm”: true,
“oauth_redirect_uri_separator”: “;”,
“coprocess_options”: {
“enable_coprocess”: false,
“coprocess_grpc_server”: “”
},
“pid_file_location”: “./tyk-gateway.pid”,
“allow_insecure_configs”: true,
“public_key_path”: “”,
“close_idle_connections”: false,
“allow_remote_config”: false,
“enable_bundle_downloader”: true,
“bundle_base_url”: “”,
“global_session_lifetime”: 100,
“force_global_session_lifetime”: false,
“max_idle_connections_per_host”: 100
}

this is my tyk.conf .
I add mongo conf in it
I cannot find anything in mongod

Hi steelhorn,

is your Dashboard working ok ?
Are you able to login ?

Thanks,
Kos @ Tyk Support Team