Skip to content
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

Not able to get delta results using a timestamp #733

Open
coderavels opened this issue Jun 19, 2024 · 3 comments
Open

Not able to get delta results using a timestamp #733

coderavels opened this issue Jun 19, 2024 · 3 comments
Assignees

Comments

@coderavels
Copy link

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(&timestamptoken).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"
@coderavels coderavels changed the title Not able to get delta token with timestamp Not able to get delta results using a timestamp Jun 19, 2024
@coderavels
Copy link
Author

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'

@coderavels
Copy link
Author

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

@rkodev rkodev self-assigned this Jul 10, 2024
@rkodev
Copy link
Contributor

rkodev commented Jul 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants