[This question was originally posted on Microsoft Q&A]
Following the documentation, I tried to add an owner for an application and a service principal as follows:
val referenceCreate= ReferenceCreate()
referenceCreate.odataId = "https://graph.microsoft.com/v1.0/directoryObjects/$owner"
graphClient.applications().byApplicationId(application.id.toString()).owners().ref().post(referenceCreate)
graphClient.servicePrincipals().byServicePrincipalId(servicePrincipal.id.toString()).owners().ref().post(referenceCreate)
This code leads to an Exception like:
com.microsoft.graph.models.odataerrors.ODataError: An unexpected 'EndOfInput' node was found when reading from the JSON reader. A 'StartObject' node was expected.
at com.microsoft.graph.models.odataerrors.ODataError.createFromDiscriminatorValue(ODataError.java:36)
at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:210)
at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:672)
at com.microsoft.kiota.ApiExceptionBuilder.<init>(ApiExceptionBuilder.java:26)
at com.microsoft.kiota.http.OkHttpRequestAdapter.throwIfFailedResponse(OkHttpRequestAdapter.java:671)
at com.microsoft.kiota.http.OkHttpRequestAdapter.sendPrimitive(OkHttpRequestAdapter.java:341)
at com.microsoft.graph.serviceprincipals.item.owners.ref.RefRequestBuilder.post(RefRequestBuilder.java:105)
at com.microsoft.graph.serviceprincipals.item.owners.ref.RefRequestBuilder.post(RefRequestBuilder.java:91)
at xx.xxx.xxx.xxxxx.service.TestAppRegistrationService.create(TestAppRegistrationService.kt:52)
...
I can avoid this problem by creating two instances of ReferenceCreate:
val applicationOwnerReference = ReferenceCreate()
val servicePrincipalOwnerReference = ReferenceCreate()
applicationOwnerReference.odataId = "https://graph.microsoft.com/v1.0/directoryObjects/$owner"
servicePrincipalOwnerReference.odataId = "https://graph.microsoft.com/v1.0/directoryObjects/$owner"
graphClient.applications().byApplicationId(application.id.toString()).owners().ref().post(applicationOwnerReference)
graphClient.servicePrincipals().byServicePrincipalId(servicePrincipal.id.toString()).owners().ref().post(applicationOwnerReference)
Can someone explain why this is happening? Is this behavior intended?
Regards, Michael
[This question was originally posted on Microsoft Q&A]
Following the documentation, I tried to add an owner for an application and a service principal as follows:
This code leads to an Exception like:
I can avoid this problem by creating two instances of ReferenceCreate:
Can someone explain why this is happening? Is this behavior intended?
Regards, Michael