Not able to get delta results using a timestamp
Trying to achieve this using the sdk.
Sample Code:
func getDelta(ctx context.Context, client *msgraphsdkgo.GraphServiceClient, driveID, itemID string) error {
reqHeaders := abstractions.NewRequestHeaders()
reqHeaders.TryAdd("Prefer", "hierarchicalsharing, deltashowremovedasdeleted, deltatraversepermissiongaps, deltashowsharingchanges")
timestamptoken := time.Now().UTC().Format(time.RFC3339)
deltaResp, err := client.Drives().ByDriveId(driveID).Items().ByDriveItemId(itemID).DeltaWithToken(×tamptoken).GetAsDeltaWithTokenGetResponse(ctx, &drives.ItemItemsItemDeltaWithTokenRequestBuilderGetRequestConfiguration{
QueryParameters: &drives.ItemItemsItemDeltaWithTokenRequestBuilderGetQueryParameters{
Select:[]string{"id", "name", "webUrl", "lastModifiedDateTime", "createdDateTime", "createdBy", "lastModifiedBy", "file", "size", "parentReference", "deleted", "shared"},
},
Headers: reqHeaders,
})
if err != nil {
return err
}
fmt.Printf("deltaResp: %+v", deltaResp)
return nil
}
But getting following error:
(400)[invalidRequest] Provided sync token is malformed, target:
I have tried following values for timestamptoken other than one mentioned in sample code:
1. url.QueryEscape(time.Now().UTC().Format(time.RFC3339))
2. "2021-09-29T20:00:00Z"
This curl works
curl --location 'https://graph.microsoft.com/v1.0/drives/:driveID/items/:itemID/delta()?token=2024-06-19T20%3A19%3A17Z&%24select=id%2Cname%2CwebUrl%2ClastModifiedDateTime%2CcreatedDateTime%2CcreatedBy%2ClastModifiedBy%2Cfile%2Csize%2CparentReference%2Cdeleted%2Cshared' \
--header 'Prefer: hierarchicalsharing, deltashowremovedasdeleted, deltatraversepermissiongaps, deltashowsharingchanges'
This doesn't
curl --location 'https://graph.microsoft.com/v1.0/drives/:driveID/items/:itemID/delta(token='\''2024-06-19T20%3A19%3A17Z'\'')?%24select=id%2Cname%2CwebUrl%2ClastModifiedDateTime%2CcreatedDateTime%2CcreatedBy%2ClastModifiedBy%2Cfile%2Csize%2CparentReference%2Cdeleted%2Cshared' \
--header 'Prefer: hierarchicalsharing, deltashowremovedasdeleted, deltatraversepermissiongaps, deltashowsharingchanges'
Decided to not use the sdk DeltaWithToken api for this use case.
Using the Delta().WithUrl(url) instead with url that has the token query parameter injected independently of the sdk.
deltaReq, err := client.Drives().ByDriveId(driveID).Items().ByDriveItemId(itemID).Delta().ToGetRequestInformation(ctx, &drives.ItemItemsItemDeltaRequestBuilderGetRequestConfiguration{
QueryParameters: &drives.ItemItemsItemDeltaRequestBuilderGetQueryParameters{
Select: fieldsForGetDelta,
},
})
if err != nil {
return err
}
rawReq, err := client.RequestAdapter.ConvertToNativeRequest(ctx, deltaReq)
if err != nil {
return err
}
httpReq, ok := rawReq.(*http.Request)
if !ok {
return err
}
url := httpReq.URL
q := url.Query()
timestamptoken := lastUpdatedAt.Format(time.RFC3339)
q.Set("token", timestamptoken)
url.RawQuery = q.Encode()
deltaReq, err := client.Drives().ByDriveId(driveID).Items().ByDriveItemId(itemID).Delta().WithUrl(url.String()).GetAsDeltaGetResponse(ctx, &drives.ItemItemsItemDeltaRequestBuilderGetRequestConfiguration{
QueryParameters: &drives.ItemItemsItemDeltaRequestBuilderGetQueryParameters{
Select: fieldsForGetDelta,
},
})
if err != nil {
return err
}
return nil
Hi @coderavels, Thanks for using the SDK. this looks like an issue with the metadata that's used to generate the sdk. As you have noted, the error is with the position of the token variable in the URL. The correct url is delta()?token=2024-06-19 as opposed to /delta(token='\''2024-06-19T20%3A19%3A17Z'\'') I have created an issue to track fixes
It would be beneficial to have the SDK updated for this use case.