c# - Azure REST API - Create, through programming, a database within an elasticPoll -
i need create, through programming, database in elasticpoll.
to this, i'm using api version 2014-04-01, indicated in "azure rest apis > sql database > databases > create or update".
i create new httpwebrequest object , launch .create() method
httpwebrequest request = (httpwebrequest)httpwebrequest.create(string.format("https://management.azure.com/subscriptions/{0}/resourcegroups/{1}/providers/microsoft.sql/servers/{2}/databases/{3}?api-version={4}", variabiliglobali.subscriptionid, variabiliglobali.resourcegroup, variabiliglobali.sqlservername, databasename, variabiliglobali.apiversion));
and compile properties:
request.headers["authorization"] = "bearer" + token; request.contenttype = "application/json; charset = utf-8"; request.method = "put"
i create new streamwriter object
using (var streamwriter = new streamwriter(request.getrequeststream())) { streamwriter.write(json); streamwriter.flush(); //streamwriter.close(); }
and .write() mothod parameter, assign complete json code of model shown in "databases - create or update" example below.
string json = "{" + "\"parameters\": {" + "\"subscriptionid\": \"" + variabiliglobali.subscriptionid + "\"," + "\"resourcegroupname\": \"" + variabiliglobali.resourcegroup + "\"," + "\"servername\": \"" + variabiliglobali.sqlservername + "\"," + "\"databasename\": \"" + databasename + "\"," + "\"api-version\": \"" + variabiliglobali.apiversion + "\"," + "\"parameters\": {" + "\"properties\": {" + "\"elasticpoolname\": \"" + elasticpoolname + "\"" + "}," + "\"location\": \"west europe\"" + "}" + "}," + "\"responses\": {" + "\"200\": {" + "\"body\": {" + "\"id\": \"/subscriptions/" + variabiliglobali.subscriptionid + "/resourcegroups/" + variabiliglobali.resourcegroup + "/providers/microsoft.sql/servers/" + variabiliglobali.sqlservername + "/databases/" + databasename + "\"," + "\"name\": \"" + databasename + "\"," + "\"type\": \"microsoft.sql/servers/databases\"," + "\"location\": \"west europe\"," + "\"kind\": \"v12.0,user\"," + "\"properties\": {" + "\"edition\": \"standard\"," + "\"status\": \"online\"," + "\"servicelevelobjective\": \"s0\"," + "\"collation\": \"sql_latin1_general_cp1_ci_as\"," + "\"creationdate\": \"2017-02-24t22:39:46.547z\"," + "\"maxsizebytes\": \"268435456000\"," + "\"currentserviceobjectiveid\": \"f1173c43-91bd-4aaa-973c-54e79e15235b\"," + "\"requestedserviceobjectiveid\": \"f1173c43-91bd-4aaa-973c-54e79e15235b\"," + "\"requestedserviceobjectivename\": \"s0\"," + "\"samplename\": null," + "\"defaultsecondarylocation\": \"japan west\"," + "\"earliestrestoredate\": \"2017-02-10t01:52:52.923z\"," + "\"elasticpoolname\": null," + "\"containmentstate\": 2," + "\"readscale\": \"disabled\"," + "\"failovergroupid\": null" + "}" + "}" + "}," + "\"201\": {" + "\"body\": {" + "\"id\": \"/subscriptions/" + variabiliglobali.subscriptionid + "/resourcegroups/" + variabiliglobali.resourcegroup + "/providers/microsoft.sql/servers/" + variabiliglobali.sqlservername + "/databases/" + databasename + "\"," + "\"name\": \"" + databasename + "\"," + "\"type\": \"microsoft.sql/servers/databases\"," + "\"location\": \"west europe\"," + "\"kind\": \"v12.0,user\"," + "\"properties\": {" + "\"edition\": \"standard\"," + "\"status\": \"online\"," + "\"servicelevelobjective\": \"s0\"," + "\"collation\": \"sql_latin1_general_cp1_ci_as\"," + "\"creationdate\": \"2017-02-24t22:39:46.547z\"," + "\"maxsizebytes\": \"268435456000\"," + "\"currentserviceobjectiveid\": \"f1173c43-91bd-4aaa-973c-54e79e15235b\"," + "\"requestedserviceobjectiveid\": \"f1173c43-91bd-4aaa-973c-54e79e15235b\"," + "\"requestedserviceobjectivename\": \"s0\"," + "\"samplename\": null," + "\"defaultsecondarylocation\": \"japan west\"," + "\"earliestrestoredate\": \"2017-02-10t01:52:52.923z\"," + "\"elasticpoolname\": null," + "\"containmentstate\": 2," + "\"readscale\": \"disabled\"," + "\"failovergroupid\": null" + "}" + "}" + "}," + "\"202\": { }" + "}" + "}";
launch .getresponse() method of httpwebrequest object
var httpresponse = (httpwebresponse)request.getresponse();
and in response following error:
{'error': {"code": "invalidrequestcontent", "message": "the request content invalid , not deserialized: 'could not find member' parameters on object of type 'resourcedefinition' , line 1, position 14. '. "}}
where wrong?
thanks in advance.
i believe documentation incorrect. correct request payload should be:
{"properties": {"elasticpoolname": "xxxxx"},"location": "west europe"}
Comments
Post a Comment