Hi, I am using Cumulocity IoT Production and in that I have a management tenant and I have subscribed 1 tenant on that. When i am trying to get series measurements from this tenant on my postman, i am able to see the data. But when i am trying to hit the same url from my microservice which is deployed on management tenant and subscribed by my sub tenant, the same endpoint is returning empty object of values. What do you think the issue could be?
Hard to say but maybe the way you’ve implemented the microservice. Do you use multi_tenant
isolation or per_tenant
?
I also don’t really get it when you receive data and when you don’t. What is meant with “But when i am trying to hit the same url from my microservice” ?Maybe you can post an example?
Adding to what @Stefan_Witschel said, I would assume you are fetching the data in the service scope of the management tenant and not using the service scope on the actual tenant or the user scope. The differences are explained in this article:
Hi Stefan/Harald,
I will explain more in detail. First to answer Harald question, I am using a user which is created by my tenant administrator. I am using that user to call cumulocity APIs in my microservice which is deployed on all of the sub tenants.
Just to inform you guys, this issue is fixed now the problem was that I was passing tenantId in the authentication but that tenantId was being passed as “management” instead of its actual tenant id. so the auth string was like
management/user:pass because of which we were getting issues.
Now the thing is i am trying to fetch a particular user from cumulocity using this api
{{baseUrl}}/user/tenantId/users/samanyu@gmail.com
Now the question is how to get this tenant id? Is there any method from SDK
What i tried is that i am hitting this api {{baseUrl}}/user
and from the response I am just getting couple of urls. From that i am just extracting the tenantId from self url.
Hi,
you can fetch the current tenant from this endpoint:
Cumulocity - OpenAPI.
I am using a user which is created by my tenant administrator. I am using that user to call cumulocity APIs in my microservice which is deployed on all of the sub tenants.
The recommended way is to use the service bootstrap user instead of a manually created user and use that to fetch the subscriptions on the subscribed tenants. This avoids manual work and you having to store the credentials somewhere. This is also explained in the article I linked above.
Ah okay so by running the method subscriptionservice.runForeachtenant. understood thanks
It’s not a good idea to use a manual created technical user within any microservice implementation for the reasons you just explained.
You need to maintain the credentials including tenantID, user and password within the microservice code which could be a security issue in the end. Also the user might change and the microservice stop working.
Like Harald already pointied out, please consider using the service user of each tenant you want to access. It’s actually even less code you need because you just need to call the subscruptionsService. No need of managing any user or authenticate agains any endpoints.
subscriptionsService.runForEachTenant(() -> {
//This will be called for each subscribed tenant, you can directly access the API like
measurementApi.getMeasurements();
});
If the API-Beans does not work for you, you can also use RestConnector within the same context.
Sure Stefan, will implement it. Thank you