Exclude a particular header in MeasurementApi or InventoryApi which creating or updating

Can some body please let me know how can we exclude a particular header while creating or updating measurement using InventoryApi or MeasurementApi classes.

While using restapi’s we have direct control what headers to include but with sdk API’s I could not find any method

Most relevant headers including the X-Cumulocity-Application-Key header are controlled through the context. So in order to change or remove a header you’ll have to create a new context and run your request within it.

The context is managed through com.cumulocity.microservice.context.ContextService<C> I don’t have a concrete example that I can share but here is a basic approach that you can take:

  1. Inject ContextService<MicroserviceCredentials> into your bean
  2. Get the current context from it using the contextService.getContext() method
  3. Clone this context without the application key
  4. Enter this modified cloned context using contextService.runWithinContext()
  5. Execute your desired requests using MeasurementApi or InventoryApi within the supplied Runnable
1 Like

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