Here, I will explain, how to create an API through API Publisher.
This request is to obtain the consumer key/ secret key pair.
curl -X POST -H "Authorization: Basic < BASE64 username:password >" -H "Content-Type: application/json" -d '{"callbackUrl": "www.google.lk","clientName": "rest_api_publisher","tokenScope": "Production","owner": "username","grantType": "password refresh_token","saasApp": true}' https://api.cloud.wso2.com/client-registration/v0.11/register
Note:
The <user name> should be email@organization_key. For example, if the e-mail is john@gmail.com, the <user name> should be john@gmail.com@organization_key. You can find the organization_key on the Manage page of the cloud.
Sample Request:
curl -X POST -H "Authorization: Basic dml2ZWthbmFudGhhbxxxxxxxxxxxxxx=" -H "Content-Type: application/json" -d '{"callbackUrl": "www.google.lk","clientName": "rest_api_publisher","tokenScope": "Production","owner": "vivekananthan@wso2.com@vives123","grantType": "password refresh_token","saasApp": true}' https://api.cloud.wso2.com/client-registration/v0.11/register
Sample Response:
{"clientId":"EDggZNfNTyZaxxxxxxxxxxxxx","clientName":"vivekananthan-AT-wso2.com_rest_api_publisher","callBackURL":"www.google.lk",
"clientSecret":"nXQfYY90sVgUGiYT3xxxxxxxxxx","isSaasApplication":true,
"appOwner":"vivekananthan@wso2.com@vives123","jsonString":"{\"grant_types\":\"password refresh_token\",\"redirect_uris\":\"www.google.lk\",\"client_name\":\"vivekananthan-AT-wso2.com_rest_api_publisher\"}"}
The next API call is to obtain the Access token, to get a token you have to use clientId and clientSecret which are obtained from a previous API call.
curl -k -d 'grant_type=password&username=username&password=password&scope=apim:api_create' -H "Authorization: Basic < BASE64 clientId:clientSecret>" https://gateway.api.cloud.wso2.com/token
Note:
The Client Id and Client Secret must be Base64 encoded in the format clientId:clientSecret, before using the cURL command. Set the scope as api_create.
Sample Request:
curl -k -d 'grant_type=password&username=vivekananthan@wso2.com@vives123&password=xxxxxxxxx&
scope=apim:api_create' -H "Authorization: Basic RURnZ1pOZk5UeVphWEhSNmxxxxxxxxxxxxxxxxxx" https://gateway.api.cloud.wso2.com/token
Sample Response:
{"access_token":"a604abea-5e2xxxxxxxxxx,"refresh_token":"49df0035-060xxxxxxxx","scope":"apim:api_create","token_type":"Bearer","expires_in":3600}
Once you get the access token, you can create an API. Here we need to set the 'provider' as username. use "https://api.cloud.wso2.com/api/am/publisher/v0.11/apis" endpoint to create API.
E.g "provider": "vivekananthan@wso2.com@vives123"

Comments
Post a Comment