03-12-2020 04:29 AM
Hello Community,
Is it possible to publish data into the content via code?
Is there a sample or documentation somewhere?
And if not, are there alternatives?
Kind regards
Elodie
Solved! Go to Solution.
03-12-2020 07:04 AM - edited 03-12-2020 07:11 AM
Hi Elodie,
The Studio API is not documented at the moment, at least not publicly AFAIK. However, if you have a DB connection present in M.App Studio, it should be pretty easy to read the network traffic. E.g. when creating a new cached vector data you require POST like this + provide the token:
The geometry type numbering should be possible to guess from existing content.
[{ "connectionId": "d60ab4f5-c919-48f9-cc84-ee3f4599aba9", "import": { "dimension": 2, "srid": 26918, "tableName": "airports", "columnName": "geometry", "geometryType": 4 }, "isCached": true, "name": "airports", "srid": 26918 } ]
03-15-2020 10:43 AM
Hi Elodie,
you can see the list of methods provided by Studio API using the swagger documentation (you cannot currently test the methods directly in there since it does not support authentication):
https://YOURSERVER/swagger/ui/index
Here is a sample code to publish an imagery into Studio content:
// registers a new Imagery into Studio content and sends it to a Map panel function setImagery(imageName) { var studiouser = 'Admin'; var studiopwd = 'Admin'; var requestData= { name: imageName.split('.')[0], physicalPath: "\\\\UNCPATH\\" + imageName, minScale: null, maxScale: null, isEcwp: false, isWmts: false, isWms: true }; var token = login(studiouser,studiopwd,'Studio').done(function (result) { var headers = {'Tenant': queryDict.tenant, 'Authorization': 'Bearer ' + token.responseJSON.access_token}; $.ajax({ url: '/api/v1/studio/content/imagery', type: 'POST', headers: headers, data: requestData, success: function(data,statusText, resObject){ // sends message to the Map panel to show the registered imagery using the Apollo Core default service gsp.m_app.messages.send( "WKE.AddLegendItem", { componentName: "map", definitionName: "WMS", url: "/erdas-iws/ogc/wms/" + TENANTNAME + "?", layerName: imageName, name: imageName, // bbox may be got from the WMS getCapabilities bbox: [-81.97123374329497, 28.886115030959626, -81.95452507901035, 28.898817009870736], bboxCrs: "EPSG:4326", supportedCrses: ["EPSG:4326","EPSG:3857"] } ); }, error: function(errMsg) { alert('error'); console.log(errMsg); } }) }); }
HTH,
Stefano