Closed junejorgensen4101 closed 3 years ago
Hi @junejorgensen4101
Thanks for reaching out.
No, this is normal, all oData functions and actions are prefixed with the namespace they belong to in the URL.
microsoft.graph.wipe
is identical to wipe
, in fact wipe is just a shorthand to the fully qualified name the service will resolve to the full name.
The error you are experiencing is not caused by how the SDK builds URLs
@baywet
I've done a few more testing. For the same deviceid, the wipe function fail with 400 error, but the retire function works. The following are the code I have.
SDK version: public void wipe(String deviceId, boolean keepUserData) { List
public void retire(String deviceId) { List
For wipe, I have error: SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: BadRequest Error message: { "_version": 3, "Message": "An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: 5606ef05-63ab-4b7a-b084-c82bdcd09e7f - Url: https://fef.amsub0102.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices%28%27d0036e3d-144c-401f-b394-a65dcc5acfad%27%29/microsoft.management.services.api.wipe?api-version=2021-04-07", "CustomApiErrorPhrase": "", "RetryAfter": null, "ErrorSourceService": "", "HttpHeaders": "{}" }
POST https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/d0036e3d-144c-401f-b394-a65dcc5acfad/microsoft.graph.wipe SdkVersion : graph-java/v3.2.0 [...]
400 : Bad Request
I also tried to use apache httpClient to call graph REST API directly with the same url, that works too.
httpclient version:
public void wipe() throws Exception {
getToken();
//burner-iPhone-DX3WTSMUHG6W
String url = graphBase + "/deviceManagement/managedDevices/d0036e3d-144c-401f-b394-a65dcc5acfad/microsoft.graph.wipe";
List
From my point of view, I don't see any parameter I passed wrong. Could you advise what else could be wrong in my function call ?
Thanks for the additional information. If in Graph Explorer you run this does it work? (I'm trying to understand whether it's an issue with the SDK itself or the service).
POST https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/d0036e3d-144c-401f-b394-a65dcc5acfad/microsoft.graph.wipe
{
"keepUserData": false,
"keepEnrollmentData": true,
"macOsUnlockCode": ""
}
The graph REST service with the same parameter worked, that is what I tested with httpclient code. I suspect something wrong with the SDK.
thanks for the additional information.
If you run final String result = graphClient.getSerializer().serializeObject(parameters);
before the request, what do you get in the resulting string?
The output string is: {"keepEnrollmentData":true,"keepUserData":false,"macOsUnlockCode":""}
I've set logging level to DEBUG, I didn't get any more debug log output though.
Jun 13, 2021 11:50:34 AM com.microsoft.graph.logger.DefaultLogger setLoggingLevel INFO: Setting logging level to DEBUG {"keepEnrollmentData":true,"keepUserData":false,"macOsUnlockCode":""} Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386Graph service exception Error code: BadRequest Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386Error message: {
Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386 "_version": 3,
Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386 "Message": "An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: fffb6c56-d2c2-4af5-aa63-fe916785f270 - Url: https://fef.amsub0102.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices%28%27d0036e3d-144c-401f-b394-a65dcc5acfad%27%29/microsoft.management.services.api.wipe?api-version=2021-04-07",
Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386 "CustomApiErrorPhrase": "",
Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386 "RetryAfter": null,
Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386 "ErrorSourceService": "",
Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386 "HttpHeaders": "{}"
Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386} Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386 Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386POST https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/d0036e3d-144c-401f-b394-a65dcc5acfad/microsoft.graph.wipe Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386SdkVersion : graph-java/v3.2.0 Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386[...] Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386 Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386400 : Bad Request Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386[...] Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386 Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: CoreHttpProvider[sendRequestInternal] - 386[Some information was truncated for brevity, enable debug logging for more details] Jun 13, 2021 11:50:37 AM com.microsoft.graph.logger.DefaultLogger logError SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: BadRequest Error message: { "_version": 3, "Message": "An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: fffb6c56-d2c2-4af5-aa63-fe916785f270 - Url: https://fef.amsub0102.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices%28%27d0036e3d-144c-401f-b394-a65dcc5acfad%27%29/microsoft.management.services.api.wipe?api-version=2021-04-07", "CustomApiErrorPhrase": "", "RetryAfter": null, "ErrorSourceService": "", "HttpHeaders": "{}" }
POST https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/d0036e3d-144c-401f-b394-a65dcc5acfad/microsoft.graph.wipe SdkVersion : graph-java/v3.2.0 [...]
400 : Bad Request [...]
[Some information was truncated for brevity, enable debug logging for more details]
At this point we've established the SDK is building the right URL and sending the right request body to the service.
The only other thing I can think of would be authentication where the application you're building doesn't have the right permissions.
Please double check the access token contains one of the correct scope. You can "crack open" the token at https://jwt.ms, and you can get a token like the one the SDK is about to use just by calling final String token = authenticationTokenProvider.getToken(new URL("https://graph.microsoft.com")).get();
where the authentication provider is the objects you passed to build the graph client.
The following is the result from http;//jwt.ms. I see our app id has all required permission, as I used the same graph client to do all other calls such as retire, delete, reset password and they all work. Wipe is the only one that I see error. The only difference is that wipe passes parameters while all other calls I use do not pass parameter. I wonder whether the problem resides in how the SDK passes the parameter in post call. Because when I bypass SDK and use normal httpClient to send post request with the same parameter, I can directly connect with graph REST API and retire the device.
{ "typ": "JWT", "nonce": "gMFhU7V69szD_FRRIf94iQajGAT9mKuarWYW79GjKyc", "alg": "RS256", "x5t": "nOo3ZDrODXEK1jKWhXslHR_KXEg", "kid": "nOo3ZDrODXEK1jKWhXslHR_KXEg" }.{ "aud": "https://graph.microsoft.com", "iss": "https://sts.windows.net/03beb921-c16c-4a69-a0df-0c9b1fb22415/", "iat": 1623757256, "nbf": 1623757256, "exp": 1623759356, "aio": "E2ZgYLAuyFWdu47FXYEjYfZ/NqP3AA==", "app_displayname": "azd_68670_dev_Intprv_app", "appid": "64510c28-5dfe-461b-9574-ac0f56fadde1", "appidacr": "1", "idp": "https://sts.windows.net/03beb921-c16c-4a69-a0df-0c9b1fb22415/", "idtyp": "app", "oid": "e56c645d-7816-44c9-87a5-0a230159d753", "rh": "0.AXMAIbm-A2zBaUqg3wybH7IkFSgMUWT-XRtGlXSsD1b63eFzAAA.", "roles": [ "DeviceManagementServiceConfig.ReadWrite.All", "DeviceManagementManagedDevices.ReadWrite.All", "DeviceManagementConfiguration.ReadWrite.All", "DeviceManagementManagedDevices.PrivilegedOperations.All", "DeviceManagementApps.ReadWrite.All" ], "sub": "e56c645d-7816-44c9-87a5-0a230159d753", "tenant_region_scope": "EU", "tid": "03beb921-c16c-4a69-a0df-0c9b1fb22415", "uti": "PzkHOeo7r0-UtG-YpNMDAA", "ver": "1.0", "wids": [ "0997a1d0-0d1d-4acb-b408-d5ca73121e90" ], "xms_tcdt": 1499851453 }.[Signature]
Thanks for the additional information. The wipe action is built (generated) the exact same way the sendMail one is. for comparison https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/src/main/java/com/microsoft/graph/requests/UserRequestBuilder.java#L1480 https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/src/main/java/com/microsoft/graph/requests/UserSendMailRequestBuilder.java https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/src/main/java/com/microsoft/graph/requests/UserSendMailRequest.java
https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/src/main/java/com/microsoft/graph/requests/ManagedDeviceRequestBuilder.java#L284 https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/src/main/java/com/microsoft/graph/requests/ManagedDeviceWipeRequestBuilder.java https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/src/main/java/com/microsoft/graph/requests/ManagedDeviceWipeRequest.java
If I don't have access to a dev tenant with the device management capabilities, I ran the unit tests for the sendMail action just to double check (it follows the same generation pattern as the wipe action), and it ran successfully. Now we've established this:
The only other difference I can see is the fact you're passing an empty list for options. Try replacing
graphClient.deviceManagement().managedDevices(deviceId).wipe(parameters).buildRequest(requestOptions).post();
by
graphClient.deviceManagement().managedDevices(deviceId).wipe(parameters).buildRequest().post();
Another thing you can try is to implement a custom request interceptor like this one to log the request/response headers & body. You can then insert this new interceptor by customizing the client
I added LogInterceptor as the following:
class LogInterceptor implements okhttp3.Interceptor { Logger logger = org.slf4j.LoggerFactory.getLogger("LogInterceptor");
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
System.out.println("header:"+request.headers());
System.out.println("body:"+request.body().toString());
Response response = chain.proceed(request);
System.out.println("LogInterceptor:"+response.toString());
return response;
}
};
================ final OkHttpClient httpClient = com.microsoft.graph.httpcore.HttpClients.createDefault(tokenCredAuthProvider) .newBuilder().proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort))) .proxyAuthenticator(proxyAuthenticator) .addNetworkInterceptor(new LogInterceptor()) .build();
In the output II see the following: RequestBody. toString() return this value. com.microsoft.graph.http.CoreHttpProvider$1@136ccbfe, I am not able to find where the parameter is passed in body. Could you advise how to get the body content in string?
header:SdkVersion: graph-java/v3.2.0 Accept: / SdkVersion: graph-java-core/v2.0.0 (featureUsage=0), java/1.8.0_192 client-request-id: 20dc2e57-c93d-428b-ad66-7508aaec20fb Authorization: Bearer Content-Type: application/json Content-Length: 69 Host: graph.microsoft.com Connection: Keep-Alive Accept-Encoding: gzip User-Agent: okhttp/4.9.0
body:com.microsoft.graph.http.CoreHttpProvider$1@136ccbfe
FYI your original message contained an access token. I have edited your message to remove it but it could have been grabbed by a 3rd party, and it still shows in the history. It will expire soon but you should be careful about any operation that might not originate from your app.
As per logging the request body see this stack overflow post
I think I have new discovery. I used the following code to send the same request via okhttpclient 1: using JSON and 2 using form_urlencoded in body. JSON request get 400 error code, form_urlencoded get expected 204. Although https://docs.microsoft.com/en-us/graph/api/intune-devices-manageddevice-wipe?view=graph-rest-beta says the api accept json.
private String graphBase = "https://graph.microsoft.com/v1.0";
public void okhttpwipe() throws Exception {
MediaType JSON
= MediaType.parse("application/json; charset=utf-8");
String url = graphBase + "/deviceManagement/managedDevices/d0036e3d-144c-401f-b394-a65dcc5acfad/microsoft.graph.wipe";
//RequestBody body = new FormBody.Builder()
// .add("keepEnrollmentData","true").add("keepUserData","true").add("macOsUnlockCode","").build();
RequestBody body = RequestBody.create(JSON,"{\"keepEnrollmentData\":true,\"keepUserData\":true,\"macOsUnlockCode\":\"\"}");
Request request = new Request.Builder()
.url(url)
.addHeader("User-Agent", "OkHttp Bot")
.post(body)
.build();
try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
// Get response body
System.out.println(response.body().string());
}
}
json request output: 2021.06.16 14:22:32.702 [main] INFO c.m.m.u.i.d.i.LogInterceptor - Request{method=POST, url=https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/d0036e3d-144c-401f-b394-a65dcc5acfad/microsoft.graph.wipe, headers=[User-Agent:OkHttp Bot, SdkVersion:graph-java-core/v2.0.0 (featureUsage=0), java/1.8.0_192, client-request-id:cf028f15-09e7-4d17-95fd-87a526567f5e, Authorization:Bearer ..., Content-Type:application/json; charset=utf-8, Content-Length:68, Host:graph.microsoft.com, Connection:Keep-Alive, Accept-Encoding:gzip], tags={class com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions=com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions@26f96b85}} 2021.06.16 14:22:32.702 [main] INFO c.m.m.u.i.d.i.LogInterceptor - body={"keepEnrollmentData":true,"keepUserData":true,"macOsUnlockCode":""} 2021.06.16 14:22:33.222 [main] INFO c.m.m.u.i.d.i.LogInterceptor - Response{protocol=http/1.1, code=400, message=Bad Request, url=https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/d0036e3d-144c-401f-b394-a65dcc5acfad/microsoft.graph.wipe}
form request output: 2021.06.16 14:21:09.923 [main] INFO c.m.m.u.i.d.i.LogInterceptor - Request{method=POST, url=https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/d0036e3d-144c-401f-b394-a65dcc5acfad/microsoft.graph.wipe, headers=[User-Agent:OkHttp Bot, SdkVersion:graph-java-core/v2.0.0 (featureUsage=0), java/1.8.0_192, client-request-id:973d540f-e9d6-4210-a405-fa482d767249, Authorization:Bearer ..., Content-Type:application/x-www-form-urlencoded, Content-Length:58, Host:graph.microsoft.com, Connection:Keep-Alive, Accept-Encoding:gzip], tags={class com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions=com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions@78e89bfe}} 2021.06.16 14:21:09.924 [main] INFO c.m.m.u.i.d.i.LogInterceptor - body=keepEnrollmentData=true&keepUserData=true&macOsUnlockCode= 2021.06.16 14:21:10.762 [main] INFO c.m.m.u.i.d.i.LogInterceptor - Response{protocol=http/1.1, code=204, message=No Content, url=https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/d0036e3d-144c-401f-b394-a65dcc5acfad/microsoft.graph.wipe}
Hi @junejorgensen4101 , That's an interesting information indeed. Out of curiosity, do you get the same behavior for both v1.0 and beta?
I just tried /beta instead of /v1.0 in graphBase, the result is the same as v1.0.
alright, thanks for investigating with me. As it seems to be a service issue, there is little we can do on the SDK team. I suggest you either contact support, or post on Microsoft Q&A (see the previous link), or create an issue by using the feedback section from the documentation page.
Any of those options will get routed to the product teams in charge of the service, the support usually being faster. Closing.
Expected behavior
graphClient.deviceManagement().managedDevices(deviceId).wipe(parameters).buildRequest(requestOptions).post(); should send POST https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/4790d027-6a72-4ed5-8ece-c3c27c982c/wipe
Actual behavior
See the following error log: Seems the request URL is not right, it should end with /wipe, not /microsoft.graph.wipe
SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: BadRequest Error message: { "_version": 3, "Message": "An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: cb879d1b-1384-4d82-8617-8cf0bf07b89d - Url: https://fef.amsub0102.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices%28%274790d027-6a72-4ed5-8ece-c3c27c982c%27%29/microsoft.management.services.api.wipe?api-version=2021-04-07", "CustomApiErrorPhrase": "", "RetryAfter": null, "ErrorSourceService": "", "HttpHeaders": "{}" }
POST https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/4790d027-6a72-4ed5-8ece-c3c27c982c/microsoft.graph.wipe SdkVersion : graph-java/v3.2.0 [...]
400 : Bad Request
Steps to reproduce the behavior
public void wipe(String deviceId, boolean keepUserData) { List
AB#9863