Add key manually to Tyk


#1

Imported Google Group message. Original thread at: https://groups.google.com/forum/#!topic/tyk-community-support/BYBeT-xFH7k Import Date: 2016-01-19 21:10:00 +0000.
Sender:Matthieu Nantern.
Date:Saturday, 18 April 2015 10:43:38 UTC+1.

Hi !

I’d like to add a key to tyk manually in order to use my own key generation algorithm but I can’t make it work:

curl -i -X PUT http://localhost:8080/tyk/keys/123 \

–header “x-tyk-authorization: 352d20ee67be67f6341b4c0605b044b7”
–data ‘{
“allowance”: 1000,
“rate”: 1000,
“per”: 60,
“expires”: 1429359466,
“quota_max”: -1,
“quota_renews”: 1404121006,
“quota_remaining”: 0,
“quota_renewal_rate”: 60,
“access_rights”: {
“1”: {
“api_name”: “Tyk Test API”,
“api_id”: “1”,
“versions”: [
“Default”
]
}
},
“org_id”: “”
}’

HTTP/1.1 400 Bad Request
Content-Type: application/json
Date: Sat, 18 Apr 2015 09:41:48 GMT
Content-Length: 46

{“status”:“error”,“error”:“Request malformed”}

Do you have an idea why it’s not working ? It’s working perfectly with /tyk/keys/create

Thank you !


#2

Imported Google Group message.
Sender:Martin Buhr.
Date:Tuesday, 21 April 2015 14:01:39 UTC+1.

Just in case anyone else runs into this - adding --header “Content-Type:application/json” solves it :slight_smile:

Martin

  • show quoted text -

#3

Imported Google Group message.
Sender:Martin Buhr.
Date:Saturday, 18 April 2015 10:56:26 UTC+1.

Hi,

Are you getting any output from the Tyk process? It will spit out a decooding error if there is an issue with the JSON object. I’d also use a POST if you are creating a key.

Cheers,
Martin

  • show quoted text -

#4

Imported Google Group message.
Sender:Martin Buhr.
Date:Saturday, 18 April 2015 11:27:41 UTC+1.

Nothing from the Tyk process except:

ERRO[1028] Couldn’t decode new session object
ERRO[1028] EOF

But I check and my JSON is valid.

According to HTTP verb definition PUT should be used when using a full path (like http://localhost:8080/tyk/keys/123). POST must be used in the other case (http://localhost:8080/tyk/keys/).

I try with a POST and it doesn’t work either :frowning:

  • show quoted text -

#5

Imported Google Group message.
Sender:Matthieu Nantern.
Date:Saturday, 18 April 2015 12:11:18 UTC+1.

Hi,

Yes you’re right, POST should be used in this way against a resource collection (which then provides you with an ID), but in this case since you defining the resource name it applies as a CREATE command and PUT is used to modify that same object. To be honest Tyk doesn’t discriminate here.

The JSON looks valid, but it looks like Tyk can’t decode the body of the request, EOF means it’s not reading the end of the object when decoding. Have you tried with Postman? I just tried the endpoint in my dev environment and it works, so the code is ok, it’s got to be an issue with the input.

Cheers,
Martin

  • show quoted text -

#6

Imported Google Group message.
Sender:Martin Buhr.
Date:Saturday, 18 April 2015 12:32:05 UTC+1.

Do you have an example with curl that works on your dev environment ?

  • show quoted text -

#7

Imported Google Group message.
Sender:Matthieu Nantern.
Date:Saturday, 18 April 2015 12:59:40 UTC+1.

Interestingly it fails with curl but works with postman. How odd.

Will need investigating :-/

M.


#8

Imported Google Group message.
Sender:Martin Buhr.
Date:Tuesday, 21 April 2015 10:25:53 UTC+1.

Do you want me to open an issue ?

  • show quoted text -

#9

Imported Google Group message.
Sender:Matthieu Nantern.
Date:Tuesday, 21 April 2015 14:01:39 UTC+1.

Just in case anyone else runs into this - adding --header “Content-Type:application/json” solves it :slight_smile:

Martin

  • show quoted text -