You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following the example here I am trying to assing a licence to an user in Azure AD. I created the following dummy script to illustrate my problem:
package main
import (
"context""log""github.com/Azure/azure-sdk-for-go/sdk/azidentity""github.com/google/uuid"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
graphusers "github.com/microsoftgraph/msgraph-sdk-go/users"
)
funcmain() {
// For testing fill the values heretenantID:="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"clientID:="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"clientSecret:="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"userID:="02a83423-br0c-4376-93a8-ed405936e0e6"// I made this up for creating the issuelicenceSKUID:="e8b967fb-3c0c-4ba7-225e-f857999a9d30_f30db741-07e9-47e9-999c-80727f46fr8f"// This as well// Authenticate with Azure AD and create a Graph clientcred, err:=azidentity.NewClientSecretCredential(tenantID, clientID, clientSecret, nil)
iferr!=nil {
log.Fatal(err)
}
graphClient, err:=msgraphsdk.NewGraphServiceClientWithCredentials(
cred,
[]string{"https://graph.microsoft.com/.default"},
)
iferr!=nil {
log.Fatal(err)
}
// Look for the user to make sure the UUID is correctu, err:=graphClient.Users().ByUserIdString(userID).Get(context.Background(), nil)
iferr!=nil {
log.Fatal(err)
}
username:=*u.GetDisplayName()
log.Printf("User %s found", username)
// Look for the license to make sure the UUID is correctl, err:=graphClient.SubscribedSkus().BySubscribedSkuIdString(licenceSKUID).Get(context.Background(), nil)
iferr!=nil {
log.Fatal(err)
}
skuID:=l.GetSkuId()
licenceName:=*l.GetSkuPartNumber()
log.Printf("License %s found", licenceName)
log.Printf("Assigning license %s to user %s", licenceName, username)
// Assign the license to the user according to the documentationrequestBody:=graphusers.NewItemAssignLicensePostRequestBody()
assignedLicense:=graphmodels.NewAssignedLicense()
disabledPlans:= []uuid.UUID{}
assignedLicense.SetDisabledPlans(disabledPlans)
assignedLicense.SetSkuId(skuID)
addLicenses:= []graphmodels.AssignedLicenseable{
assignedLicense,
}
requestBody.SetAddLicenses(addLicenses)
removeLicenses:= []uuid.UUID{}
requestBody.SetRemoveLicenses(removeLicenses)
assignLicense, err:=graphClient.Users().ByUserIdString(userID).AssignLicense().Post(context.Background(), requestBody, nil)
iferr!=nil {
log.Fatal(err)
}
log.Printf("%v", assignLicense.GetAssignedLicenses())
}
So to make sure I only pass existing IDs to the licence assignment code, I use the same graph client to get the objects before. After running it, the logs are:
2023/09/08 16:25:02 User Test User found
2023/09/08 16:25:02 License FLOW_FREE found
2023/09/08 16:25:02 Assigning license FLOW_FREE to user Test User
2023/09/08 16:25:03 error status code received from the API
exit status 1
I made sure the client being used has the appropriate permissions:
Given the very vague error message I can not really debug any further on the issue. I tried to use a debugger to look at the error but the values are strange:
As a side note (maybe it its of importance). I am using the "long" version of the licence ID in the code (<TENANT_ID>_<SKU_ID>) because if I don't then this line
will be the one failing with a similar error (also empty message and status code 0)
I would appreciate some help, because a response code of 0 seems to be me like an indication of something bigger being wrong. It could also be that the documentation is not correct.
Hello!
Following the example here I am trying to assing a licence to an user in Azure AD. I created the following dummy script to illustrate my problem:
So to make sure I only pass existing IDs to the licence assignment code, I use the same graph client to get the objects before. After running it, the logs are:
2023/09/08 16:25:02 User Test User found 2023/09/08 16:25:02 License FLOW_FREE found 2023/09/08 16:25:02 Assigning license FLOW_FREE to user Test User 2023/09/08 16:25:03 error status code received from the API exit status 1
I made sure the client being used has the appropriate permissions:
Given the very vague error message I can not really debug any further on the issue. I tried to use a debugger to look at the error but the values are strange:
As a side note (maybe it its of importance). I am using the "long" version of the licence ID in the code (
<TENANT_ID>_<SKU_ID>
) because if I don't then this linewill be the one failing with a similar error (also empty message and status code 0)
I would appreciate some help, because a response code of 0 seems to be me like an indication of something bigger being wrong. It could also be that the documentation is not correct.
Versions
I am using the following library versions:
The text was updated successfully, but these errors were encountered: