# Can we hit Cumulocity APIs with bootstrap credentials of microservice

**URL:** <https://community.cumulocity.com/t/can-we-hit-cumulocity-apis-with-bootstrap-credentials-of-microservice/2501>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [August 2, 2023, 7:02am UTC](https://community.cumulocity.com/t/can-we-hit-cumulocity-apis-with-bootstrap-credentials-of-microservice/2501 "2023-08-02T07:02:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam123](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/sam123/32/14460_2.png) [@Sam123](https://community.cumulocity.com/u/Sam123)\
**Post date:** [August 2, 2023, 7:02am UTC](https://community.cumulocity.com/t/can-we-hit-cumulocity-apis-with-bootstrap-credentials-of-microservice/2501/1 "2023-08-02T07:02:29Z")

</div>

#### _ **Product/components** used and **version/fix** level:_

Cumulocity Production

#### _Detailed explanation of the problem:_

Hi,

1. Is it possible to access the Cumulocity APIs with the bootstrap credentials of my microservice?
2. In SDK, we pass bootstrap credentials so How do you access the APIs with these credentials since they dont work directly?

Thanks,  
Samanyu

---

<div class="post-metadata">

**Author:** ![Korbinian\_Butz](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/korbinian_butz/32/10473_2.png) [@Korbinian\_Butz](https://community.cumulocity.com/u/Korbinian_Butz)\
**Post date:** [August 2, 2023, 7:12am UTC](https://community.cumulocity.com/t/can-we-hit-cumulocity-apis-with-bootstrap-credentials-of-microservice/2501/2 "2023-08-02T07:12:05Z")

</div>

Hi,

see Stefans Response to your previous thread [here](https://community.cumulocity.com/t/getting-error-when-adding-microserviceapplication-in-spring-boot-project/7077/19):

> The bootstrapuser is just for retrieving the service user for each tenant. I think I made this clear now multiple times. You should not use that in any other API Call of your microservice (even when it is working). The service user permissions are defined in your manifest file.

---

<div class="post-metadata">

**Author:** ![Sam123](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/sam123/32/14460_2.png) [@Sam123](https://community.cumulocity.com/u/Sam123)\
**Post date:** [August 2, 2023, 7:27am UTC](https://community.cumulocity.com/t/can-we-hit-cumulocity-apis-with-bootstrap-credentials-of-microservice/2501/3 "2023-08-02T07:27:10Z")

</div>

Hi Korbinian,

That is fine but I need to understand the process here. Can’t we expose the “service user” credentials and use rest api call internally?

---

<div class="post-metadata">

**Author:** ![Stefan\_Witschel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/stefan_witschel/32/31955_2.png) [@Stefan\_Witschel](https://community.cumulocity.com/u/Stefan_Witschel)\
**Post date:** [August 2, 2023, 8:19am UTC](https://community.cumulocity.com/t/can-we-hit-cumulocity-apis-with-bootstrap-credentials-of-microservice/2501/4 "2023-08-02T08:19:57Z")

</div>

Everything is well documented here:

[https://cumulocity.com/guides/microservice-sdk/concept/#microservice-bootstrap](https://cumulocity.com/guides/microservice-sdk/concept/#microservice-bootstrap)

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/b/a/ba52c241d551c114163473f6455ac241ab014aa0.png)

What is missing from your perspective? For what purpose do you want to expose the service user credentials outside of the microservice context? Of course you can do that but security-wise it is still a high risk because the service user has all the rights which are defined in the microservice manifest…

---

<div class="post-metadata">

**Author:** ![Sam123](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/sam123/32/14460_2.png) [@Sam123](https://community.cumulocity.com/u/Sam123)\
**Post date:** [August 2, 2023, 9:55am UTC](https://community.cumulocity.com/t/can-we-hit-cumulocity-apis-with-bootstrap-credentials-of-microservice/2501/5 "2023-08-02T09:55:29Z")

</div>

Hi Stefan,

When we provide a value to the required interval field, a availability fragment is created for that specific M.O. Now when we are trying to send update the fragment it is not working because of that “header” in SDK. So, if we get the user credentials, we can do a rest API call and send an empty put call which will make sure that the request is coming from a device as you suggested in different post.

Thanks,  
Samanyu

---

<div class="post-metadata">

**Author:** ![Stefan\_Witschel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/stefan_witschel/32/31955_2.png) [@Stefan\_Witschel](https://community.cumulocity.com/u/Stefan_Witschel)\
**Post date:** [August 2, 2023, 10:39am UTC](https://community.cumulocity.com/t/can-we-hit-cumulocity-apis-with-bootstrap-credentials-of-microservice/2501/6 "2023-08-02T10:39:27Z")

</div>

Uhhh this is way too complicated for what you wanted to achieve. It’s much easier.  
See here for an example using restTemplate:

> [@Microservice SDK (java) best way to call unsupperted but available REST endpoints](https://community.cumulocity.com/t/microservice-sdk-java-best-way-to-call-unsupperted-but-available-rest-endpoints/7747/7):
>
> I have implemented it using restTemplates: Created two pojos EventBinary and BinaryInfo: @Data public class BinaryInfo { /\*\* \* Name of the binary object. \*/ private String name; /\*\* \* Media type of the file. \*/ private String type; } @Data public class EventBinary { /\*\* \* Name of the attachment. If it is not provided in the request, it will be set as the event ID. \*/ private String name; /\*\* \* A URL linking to this resource. \*/ private String self; /\*\* \* Unique …

Just adapt that to the inventory API and you can freely define which headers are sent or not also you get the required credentials via the context service which can be autowired into your service:

```auto
@Autowired
private ContextService<MicroserviceCredentials> contextService;

headers.set("Authorization", contextService.getContext().toCumulocityCredentials().getAuthenticationString());

```

---

<div class="post-metadata">

**Author:** ![Sam123](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/sam123/32/14460_2.png) [@Sam123](https://community.cumulocity.com/u/Sam123)\
**Post date:** [August 10, 2023, 7:42am UTC](https://community.cumulocity.com/t/can-we-hit-cumulocity-apis-with-bootstrap-credentials-of-microservice/2501/7 "2023-08-10T07:42:24Z")

</div>

Hi Stefan,

We have implemented what you said and it worked in local but after deployment we are getting errors. It is not able to pull the image and the service is unhealthy. Could you please help how we can resolve this issue? If any extra roles required for this "context service\*.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [February 6, 2024, 7:42am UTC](https://community.cumulocity.com/t/can-we-hit-cumulocity-apis-with-bootstrap-credentials-of-microservice/2501/8 "2024-02-06T07:42:25Z")

</div>

Closed on February 6, 2024, 7:42am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
