msgraph-sdk-java
msgraph-sdk-java copied to clipboard
How to use $deltatoken=latest with version 6?
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?
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);