I'm trying to create a microservice in Scala using the Cumulocity Java SDK but I can't authenticated it using the C8Y_BASEURL, C8Y_PASSWORD, C8Y_USER environment variables.
Here is simple code:
val C8Y_USER = sys.env.getOrElse("C8Y_USER", "no value for C8Y_USER")
val C8Y_PASSWORD = sys.env.getOrElse("C8Y_PASSWORD", "no value for C8Y_PASSWORD")
val C8Y_BASEURL = sys.env.getOrElse("C8Y_BASEURL", "no value for C8Y_BASEURL")
val platform = new PlatformImpl(C8Y_BASEURL, new CumulocityCredentials(C8Y_USER, C8Y_PASSWORD))
val alarmsRepresentation = platform.getAlarmApi.getAlarmsByFilter(new AlarmFilter().byStatus(CumulocityAlarmStatuses.ACKNOWLEDGED)).get(2000)
The code outcome is :
{error="security/Unauthorized",message="Invalid credentials!",info="https://www.cumulocity.com/guides/reference-guide/#error_reporting",details="null"}
The weird thing is that if I use that same user and password with the complete tenant url the microservice works. Ex:
val C8Y_USER = sys.env.getOrElse("C8Y_USER", "no value for C8Y_USER")
val C8Y_PASSWORD = sys.env.getOrElse("C8Y_PASSWORD", "no value for C8Y_PASSWORD")
val C8Y_TENANT = sys.env("C8Y_TENANT")
val C8Y_BASEURL = "https://" + C8Y_TENANT + ".myparenttenant.com"
So at the end the only different is the C8Y_BASEURL, Using the default C8Y_BASEURL the value is http://cumulocity:8111 which doesn't work and my own builded value is : https://subtenant.myparenttenant.com which works just fine!
Any help?
I am guessing http://cumulocity:8111 "resolves" to http://myparenttent.com so Cumulocity doesn't know which tenant your user belongs to.
Try importing C8Y_TENANT and use it when creating your credential in your first example.