Hexagon Geospatial
MENU

M.App Enterprise

Discuss topics with other M.App Enterprise Product pioneers and experts to get the most out of it.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Valued Contributor
Posts: 535
Registered: ‎10-27-2015

Testing the back-end API using swagger

Dear all,

we are trying to test the M.App Enterprise back end, using Swagger. I have generated an API key, in studio, but where we can define the tenant?

We are able to test the API using Postman (setting the tenant, the token, etc, in the headers of the request) but not using the M.App Enterprise Swagger UI.

Is there a possibilty to test the API using only swagger? For example publishing a new image as WMS. We need it for demos.

 

thank you

Regards

Technical Evangelist
Posts: 178
Registered: ‎03-03-2016

Re: Testing the back-end API using swagger

Do you want to demonstrate the secured WMS service or what is the use case here?

Valued Contributor
Posts: 535
Registered: ‎10-27-2015

Re: Testing the back-end API using swagger

Hi tpaul, thank you for the reply. 


This is the test case:
- publish a raster file as WMS;

  • publish a vector data as WFS;

using the API

 

 

Technical Evangelist
Posts: 178
Registered: ‎03-03-2016

Re: Testing the back-end API using swagger

If you don't assign a API key for the WMS then you should be able to also use Swagger --> The geoservices are not secured by a token by default.

 

For secured WMS services please use PostMan.

Valued Contributor
Posts: 535
Registered: ‎10-27-2015

Re: Testing the back-end API using swagger

- I create the APIkey in studio then I go in swagger of my server and copy it (above on the right), then I click on the explore button;

 

If I try publish a raster I have Response Code = 401.

In Swagger the same POST request works.

Technical Evangelist
Posts: 178
Registered: ‎03-03-2016

Re: Testing the back-end API using swagger

The Swagger UI is not linked to M.App Enterprise security model.

So when you are testing a secured Endpoint (with token or API Key) it does not work.

 

However ... if you don't use an API key for your WMS service (which is the default option) then it works also in swagger. (see attached image)

 

swagger.png

 

 

Occasional Contributor
Posts: 19
Registered: ‎04-21-2017

Re: Testing the back-end API using swagger

[ Edited ]

Hi,

 

I'll try to clarify @gmaldera 's problem.

 

We are accessing the Swagger webpage, and trying the POST /api/v1/studio/content/imagery endpoint, which helps you uploading imagery in order to make it available through a WMS service, unfortunately getting a 401 Unatuthorized as server response.

 

As "The Swagger UI is not linked to M.App Enterprise security model", my understanding is that this can only be achieved through Postman.

 

In this case, it is necessary to get an <access token> through the /api/v1/oauth2/token endpoint and then use it for any other request setting the Authorization: Bearer <access_token> header.

Moreover, each request (including the one to get the access token) has to come with a Tenant: <tenant_name> header as well.

 

Do you confirm this or there is something we are missing?

 

Thanks

 

 

 

Staff
Posts: 1,033
Registered: ‎10-18-2015

Re: Testing the back-end API using swagger

here is a piece of JS code to publish a new imagery within content and send it to a Map panel as WMS:

 

// 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);
            } 
    })
  });
}
Stefano Turcato
Presale Engineer
Hexagon Geospatial
Do you need immediate support?
If you encounter a critical issue and need immediate assistance please submit a Development Ticket through our Development Ticket Portal.