call API method SoftLayer_Virtual_Guest/setTags.js

2019-08-16 02:46发布

问题:

When I post https://api.softlayer.com/rest/v3.1/SoftLayer_Virtual_Guest/{vmid}/setTags.json

with params: {"parameters":["id: 899a9411-a08b-4d31-8dc6-cb2712c608dc, index: 0, job: redis-master, name: redis-master/899a9411-a08b-4d31-8dc6-cb2712c608dc, cpi-tag: redis-deployment, created_at: 2017-11-09T07:19:43Z, deployment: my-redis-deployment, director: ed-demo-director"]}

API return error with '{"error":"Invalid value provided for 'tags'. Invalid tag names: name: redis-master/899a9411-a08b-4d31-8dc6-cb2712c608dc.","code":"SoftLayer_Exception_InvalidValue"}'. As the error said, 'name' is not valid tag name. I don't know why it is invalid. And where can we set the invalid tag name list.

And did more test, I found it is due to the character '/'.

回答1:

The reason why it is invalid is because some characters like you´ve found '/', are not allowed trough the SoftLayer_Virtual_Guest::setTags method, the characters permitted are A-Z, 0-9, whitespace, _ (underscore), - (hypen), . (period), and : (colon), therefor I am afraid you won't be able to use tag names with other characters than the permitted.

Try the following REST request to make the method work, the '/' has been replaced by a hyphen '-' as it is an allowed character:

https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Virtual_Guest/35747489/setTags
method (POST)
Body (json):
{"parameters":["id: 899a9411-a08b-4d31-8dc6-cb2712c608dc,index: 0,job: redis-master,name: redis-master-899a9411-a08b-4d31-8dc6-cb2712c608dc,cpi-tag: redis-deployment,created_at: 2017-11-09T07:19:43Z,deployment: my-redis-deployment,director: ed-demo-director"]}

For more information you may see below:

https://sldn.softlayer.com/reference/services/SoftLayer_Tag/setTags

Softlayer : tagging device