addServiceLink via API

So I have read through the API documentation and it seems simple enough:

http://docs.rancher.com/rancher/latest/en/api/api-resources/service/

Also used the curl request generator thing thats part of the API, but that seems to give an error.

curl -u “${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}”
-X POST
-H ‘Accept: application/json’
-H ‘Content-Type: application/json’
-d ‘{“serviceId”:“1s365”}’
https://rancher/v1/projects/1a5/services/1s366/?action=addservicelink

Error:

{“id”:“83c11274-772b-4836-8e74-453764068073”,“type”:“error”,“links”:{},“actions”: {},“status”:422,“code”:“MissingRequired”,“message”:null,“detail”:null,“fieldName”:“serviceLink”}

So I’m pretty sure this means that the serviceLink field is required, so I tried this:

curl -u “${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}”
-X POST
-H ‘Accept: application/json’
-H ‘Content-Type: application/json’
-d ‘{“serviceLink”:“selenium-115/hub”, “serviceId”:“1s365”}’
https://rancher/v1/projects/1a5/services/1s366/?action=addservicelink

Error:

{“id”:“7b0d6df2-f840-4471-a65d-f737e89bc34d”,“type”:“error”,“links”:{},“actions”:{},“status”:422,“code”:“MissingRequired”,“message”:null,“detail”:null,“fieldName”:“serviceId”}

I’m assuming that I’m just inputting the incorrect field types, although it wasn’t clear to me from the documentation what they should be. Any help would be appreciated.

I just sorted this out yesterday, had same problem.

curl -u “${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}”
-X POST
-H ‘Accept: application/json’
-H ‘Content-Type: application/json’
-d ‘{“serviceLink”:{“name”:“appdb”, “serviceId”:“1s136”, “uuid”:“bb470c1d-9f78-43aa-86b0-e5b14a3b184f”}}’
http://rancher/v1/projects/1a5/services/1s137/?action=addservicelink

serviceid and uuid are the IDs of service that you want to link

@Adaikal_Raj Thanks for the response!