msgraph-sdk-java icon indicating copy to clipboard operation
msgraph-sdk-java copied to clipboard

How to use $deltatoken=latest with version 6?

Open wimdeblauwe opened this issue 4 months ago • 1 comments

According to https://learn.microsoft.com/en-us/graph/delta-query-overview, you can use $deltatoken=latest to start tracking changes from "now". How do I do this with the SDK version 6.54.0?

wimdeblauwe avatar Oct 16 '25 07:10 wimdeblauwe

It does not seem like the SDK currently support this, but I managed to write this workaround.

First create a subclass of DeltaRequestBuilder in order to be able to set urlTemplate:

import com.microsoft.graph.users.delta.DeltaRequestBuilder;
import com.microsoft.kiota.RequestAdapter;
import java.util.HashMap;

public class MyDeltaRequestBuilder extends DeltaRequestBuilder {

  public MyDeltaRequestBuilder(
      HashMap<String, Object> pathParameters,
      RequestAdapter requestAdapter) {
    super(pathParameters, requestAdapter);
  }

  public void setUrlTemplate(String urlTemplate) {
    this.urlTemplate = urlTemplate;
  }
}

Then you can do this to the delta of the Entra Id users starting from "now":

      MyDeltaRequestBuilder delta = new MyDeltaRequestBuilder(new HashMap<>(), graphClient.getRequestAdapter());
      delta.setUrlTemplate("{+baseurl}/users/delta()?$deltaToken=latest");
      RequestInformation getRequestInformation = delta.toGetRequestInformation();
      DeltaGetResponse deltaGetResponse = graphClient.getRequestAdapter()
          .send(getRequestInformation, null, DeltaGetResponse::createFromDiscriminatorValue);

wimdeblauwe avatar Oct 17 '25 12:10 wimdeblauwe