I am trying to create an API in Tyk on Premise Community Edition using Gateway REST API as per the tutorial, but after executing the command
curl -H “x-tyk-authorization: {your-secret}”
-H “Content-Type: application/json”
-X POST
-d ‘{
“name”: “Test API”,
“slug”: “test-api”,
“api_id”: “1”,
“org_id”: “1”,
“auth”: {
“auth_header_name”: “Authorization”
“definition”: {
“location”: “header”,
“key”: “x-api-version”
“version_data”: {
“not_versioned”: true,
“versions”: {
“Default”: {
“name”: “Default”,
“use_extended_paths”: true
“proxy”: {
“listen_path”: “/test-api/”,
“target_url”: “
http://httpbin.org/
”,
“strip_listen_path”: true
“active”: true
}’ https://{your-tyk-host}:{port}/tyk/apis/ | python -mjson.tool
with the required values, I am getting error “No JSON object could be decoded”.
Any idea why this error is coming??
Hi Tanaya,
It’s likely that this error was caused by the format of the cURL request itself. The newline character in particular is often interpreted differently depending on the type of terminal used. It may be worth re-writing the request so that the entire command is on the same line or adding a backslash to the end of each line before sending the request. There are also third-party tools available like
Postman
which can make writing longer cURL requests much simpler.
Hope that helps.
Kind regards,
Jess @ Tyk
Hi Martin,
This is my single line command
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”: { “auth_header_name”: “Authorization”}, “definition”: { “location”: “header”, “key”: “x-api-version” }, “version_data”: { “not_versioned”: true, “versions”: { “Default”: { “name”: “Default”, “use_extended_paths”: true } } }, “proxy”: { “listen_path”: “/test-api/”, “target_url”: “
http://52.44.115.34/e-cart/rest/default/V1/categories
”, “strip_listen_path”: true }, “active”: true }’
https://10.0.0.209:3000/tyk/apis/
| python -mjson.tool
I’ve figured out what the issue was on my end and maybe this helps any of you guys.
We have a corporate proxy server setup (we probably aren’t the only enterprise).
This has always been a pain to me, but hey I’m no sysadmin.
For this we need to set some exports to make sure we can reach
the outside:
export http_proxy=http://user:pass@proxyhost:3128 export https_proxy=http://user:pass@proxyhost:3128
After I was going through the lines of the bootstrap.sh I saw
the return value was both quite big and somewhat familiar.
The system was trying to go through our proxy in order to get to itself (duh! That is what I had configured to be able to retrieve tyk from the internet)
In order for this to not happen for local connections I added
this line to my .bashrc (where I also had the http_proxy settings)
export no_proxy=localhost,127.0.0.0/8,10.31.12.38,10.0.0.0/8,apim.localdomain.nl
After that I ran below command and what do you know…
`[root@apim ~]# /opt/tyk-dashboard/install/bootstrap.sh apim.localdomain.nl
Creating Organisation
ORGID: 58924c7c660450026f755e09
Adding new user
USER AUTH: d4f5b6311c26461156037182ba0e0308
NEW ID: 58924c7cb72e275a92390f1d
Setting password
Login at
http://apim.localdomain.nl:3000/
User:
[email protected]
Pass: test123
[root@apim ~]#`
Not sure about any HTTP proxy on my part, but just trialling this TYK API, and also have come across this snag just now.
Installed without a hitch (my centOs VM)
Attempted the API creation via CMD,
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”: { “auth_header_name”: “Authorization”}, “definition”: { “location”: “header”, “key”: “x-api-version” }, “version_data”: { “not_versioned”: true, “versions”: { “Default”: { “name”: “Default”, “use_extended_paths”: true } } }, “proxy”: { “listen_path”: “/test-api/”, “target_url”: “
http://http
://httpbin.org/”, “strip_listen_path”: true }, “active”: true }’
http://127.0.0.1:8080/tyk/apis/
| python -mjson.tool
Errors out.
No JSON object could be decoded
Looking at logs, not events whatsoever
And im tailing the lot of them via
tail -f /var/log/tyk-*
Tips Pointers appreciated
Hi
@pantsjj
,
My colleague and I have been unable to reproduce this error message. Could you please try running the cURL request without
-s
flag and without the
| python -mjson.tool
at the end? I think the error message you’re currently getting is being produced by Python and all it really tells us is that it was unable to parse a JSON object from the cURL request. If you remove that part of the request, hopefully the error produced will provide more of a clue as to what’s going on.
Kind regards,
i may be getting somewhere.
[root@staging- apps]# 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”: { “auth_header_name”: “Authorization”}, “definition”: { “location”: “header”, “key”: “x-api-version” }, “version_data”: { “not_versioned”: true, “versions”: { “Default”: { “name”: “Default”, “use_extended_paths”: true } } }, “proxy”: { “listen_path”: “
testapi
”, “target_url”: “
http://http
://httpbin.org/”, “strip_listen_path”: true }, “active”: true }’
http://127.0.0.1:8080/tyk/apis/
| python -mjson.tool
time=“Feb 27 13:40:48” level=warning msg=“API Definition with this ID already exists, deleting file…”
( i typed above twice) yes. this works. same copy paste as i mentioned earlier.
I did however reinstalled everything from ground zero. perhaps, some indeed some issue with services, which logging didn’t show.
** “action”: “added”,**
** “key”: “1”,**
** “status”: “ok”**
i can query the api’s (test api not listed, despite earlier OK, but demo/example one is (as from the ./apps/example one.
curl -H “x-tyk-authorization: 352d20ee67be67f6340b4c0605b044b7” “
http://127.0.0.1:8080/tyk/apis/1
” | jq
“name”: “Tyk Test API”,
“slug”: “”,
“api_id”: “1”,
“org_id”: “default”,
---- long story short,
i note that dashboard is not reflecting what the curl is responding with.
As per example above, this information is nowhere to be found in the dashboard. in fact, i have some other API demo example(as, so named) listed there,
ok. This particular topic is then closed.
Moving this to another relevant topic thread.
Basically, dashboard and gateway are talking to two different things.
Gateway, (as per above CLI) is up and running with the json example
But on Dashboard, it isnt showing. furthermore, i am unable to successfully create any further API via dashboard. see my debug below. so. moving to another thread in any case.
Thanks for all the help thus far
time=“Feb 27 16:53:06” level=info msg=“Loading API” api_name=“Tyk Test API”
time=“Feb 27 16:53:06” level=info msg=“Checking security policy: Token” api_name=“Tyk Test API”
time=“Feb 27 16:53:07” level=info msg=“Processed and listening on: /mytest/{rest:.*}”
time=“Feb 27 16:53:07” level=info msg=“Loading uptime tests…”
time=“Feb 27 16:53:07” level=info msg=“Initialised API Definitions”
time=“Feb 27 16:53:07” level=info msg=“API reload complete”
time=“Feb 27 16:53:22” level=error msg=“
Could not add key for this API ID, API doesn’t exist.
” api_id=a320b4a31f244521615bb1524a53472a key=58ad966d8f2f406d4a9758a6testuser org_id=58ad966d8f2f406d4a9758a6 path=-- server_name=system user_id=system user_ip=–
It looks like you are using the gateway api and have the gateway configured to run without the dashboard. So the two are completely disconnected.
If you run CE - there is no dashboard, and that’s what the instructions in the tutorial optimise for.
To use the dashboard it might probably be best to run the setup script again from the dashboard installation and setup guides.