-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There is no way to list items in the drive #67
Comments
Hi @augbed We're tracking this and that issue in the conversion library that generates the OpenAPI description. When they are addressed and the newer version of the library is released, the additional fluent API paths should show up. Lastly, we're aware the SDK fails silently at the moment whenever an error is returned, this is something we're tracking in our list of known issues to resolve before GA I hope this helps, let us know if you have further questions. I'll leave the issue open until the path items show up. |
Hi, could you please elaborate on how to do this?
My naive attempt does not work: import (
"fmt"
azidentity "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
a "github.com/microsoft/kiota/authentication/go/azure"
sdk "github.com/microsoftgraph/msgraph-sdk-go"
drive "github.com/microsoftgraph/msgraph-sdk-go/shares/item/driveitem"
"github.com/spf13/viper"
)
func Dump() {
cred, err := azidentity.NewClientSecretCredential(
viper.GetString("auth.tenant_id"),
viper.GetString("auth.client_id"),
viper.GetString("auth.client_secret"),
&azidentity.ClientSecretCredentialOptions{},
)
if err != nil {
fmt.Printf("Error creating credentials: %v\n", err)
}
auth, err := a.NewAzureIdentityAuthenticationProvider(cred)
if err != nil {
fmt.Printf("Error authenticating: %v\n", err)
return
}
adapter, err := sdk.NewGraphRequestAdapter(auth)
if err != nil {
fmt.Printf("Error creating adapter: %v\n", err)
return
}
targetUrl := "https://graph.microsoft.com/v1.0/me/drive/root"
client := drive.NewDriveItemRequestBuilder(targetUrl, adapter)
if err != nil {
fmt.Printf("Error creating client: %v\n", err)
return
}
result, err := client.Get(nil)
if err != nil {
fmt.Printf("Error retrieving resource: %v\n", err)
}
fmt.Printf("result = %+v\n", result)
} Results in:
Thanks! |
Your code is correct, there seems to be a bug in the generation process however.
should be -m.pathParameters = pathParameters;
+m.pathParameters = urlTplParams; The code generating this is here https://github.com/microsoft/kiota/blob/4a4750ca8e03a57e094197e36937630fee3a103c/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs#L254 and should be -writer.WriteLine($"m.{property.Name.ToFirstCharacterLowerCase()} = {parameter.Name};");
+writer.WriteLine($"m.{property.Name.ToFirstCharacterLowerCase()} = {variableName};"); Submitting a PR shortly. |
I just put together this PR, but after digging into it further it doesn't look like that's the root of the issue, looking further into this. |
After further investigations it looks like the request builder constructor, and the CreateGetRequestInformation method are doing the right thing (able to get the raw URL when calling get URI). However when the request adapter calls GetUri, it's not getting the right value. It seems like dereferencing the request information in the Get method might be what's causing the issue, but further investigations are needed. (since the SetUri method is defined on a pointer receiver, not on the struct)
|
It seems that GetUri is getting called twice. The first time everything looks good:
..then it runs a second time, apparently after acquiring a token and losing the RequestInformation data along the way somewhere.
|
Thanks for that precious additional information. Here is what happens at a high level:
I'll update my pull request to account for all of that. |
Ah, tricky. Thanks for the analysis. |
You're welcome! I just update the initial PR to fix that. |
Update: kiota PR was merged, the reference update PR in core as well, now all that's required is a generation here. It will happen by next Tuesday. Thanks for your patience. |
update, the ability to use request builders with raw urls has been fixed, to update: go get -u github.com/microsoftgraph/msgraph-sdk-go@v0.13.0 Some of the additional path segments are also present now thanks to leveraging the newer metadata |
Great, thanks!
I guess I need to pass some code to process the response. Is there an example of what that would look like somewhere? |
this is strange as those factories are registered by default with the client. msgraph-sdk-go/graph_service_client.go Line 275 in 61b2ee3
would you mind sharing your client initialization code please? |
It is the code posted above. |
Here's the code as a single main package: package main
import (
"fmt"
azidentity "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
a "github.com/microsoft/kiota/authentication/go/azure"
sdk "github.com/microsoftgraph/msgraph-sdk-go"
drive "github.com/microsoftgraph/msgraph-sdk-go/shares/item/driveitem"
)
func main() {
tenant_id := "***"
client_id := "***"
client_secret := "***"
cred, err := azidentity.NewClientSecretCredential(
tenant_id,
client_id,
client_secret,
&azidentity.ClientSecretCredentialOptions{},
)
if err != nil {
fmt.Printf("Error creating credentials: %v\n", err)
}
auth, err := a.NewAzureIdentityAuthenticationProvider(cred)
if err != nil {
fmt.Printf("Error authenticating: %v\n", err)
return
}
adapter, err := sdk.NewGraphRequestAdapter(auth)
if err != nil {
fmt.Printf("Error creating adapter: %v\n", err)
return
}
targetUrl := "https://graph.microsoft.com/v1.0/me/drive/root"
client := drive.NewDriveItemRequestBuilder(targetUrl, adapter)
if err != nil {
fmt.Printf("Error creating client: %v\n", err)
return
}
result, err := client.Get(nil)
if err != nil {
fmt.Printf("Error retrieving resource: %v\n", err)
}
fmt.Printf("result = %+v\n", result)
} My go.mod looks like:
|
aaah thanks for sharing this, can you try replacing this? + client := msgraphsdk.NewGraphServiceClient(adapter)
+ drive, err := client.Me().Drive().Get(nil)
+ if err != nil {
+ fmt.Printf("Error getting the drive: %v\n", err)
+ return
+ }
- targetUrl := "https://graph.microsoft.com/v1.0/me/drive/root"
- client := drive.NewDriveItemRequestBuilder(targetUrl, adapter)
- if err != nil {
- fmt.Printf("Error creating client: %v\n", err)
- return
- }
- result, err := client.Get(nil)
+ result, err := client.DrivesById(*drive.GetId()).Root().Get(nil)
if err != nil {
fmt.Printf("Error retrieving resource: %v\n", err)
}
fmt.Printf("result = %+v\n", result) |
This gets: |
which is expected since your app is using app only and the /me endpoints require a delegated context. see the extended answer I provided on another issue |
Ah, right:
|
I'm still interested in getting a working query with a raw url though. |
I'm curious to why would you rather do that than using the chained style API? The code you posted earlier should work, you just need to new up the client before executing the request to register the default providers. If you don't intend on using the service client and Go complains about an unused variable, you can alternatively register the default serializers yourself, see this answer |
I don't have any pressing need at this point, just curious.
Ok. Thanks, I'll try it out. |
Quick update on this, I thought I had provided one but apparently I forgot. For the drives (and things that live under a drive) there's a canonical path and there are additional paths to access the same information. Effectively If you want to access data under those, and your application context doesn't have all the ids (drive id + drive item id...), the best thing is to:
If you want to perform a single request because your application context has all the ids it needs, you can either use the chained methods on the canonical path, or use a request builder with a raw URL (see my previous answers). I hope this clarifies the situation. |
It seems like there's currently no way of actually listing drive items.
Requests like:
GET /me/drive/root/children
orGET /drives/{drive-id}/items/{item-id}/children
are not possible using this sdk it seems.I would expect to be able to do something like
client.Me().Drive().Root().Children().Get(nil)
Am I missing something or is this just not possible? Also it seems that it's possible to construct invalid requests as in doing
GET /drive/items
and it just fails silently.The text was updated successfully, but these errors were encountered: