Forum Discussion
HimanJo
Apr 14, 2021Copper Contributor
Get printerCreateOperation while registering the printer using java msal?
Hello All, I am trying to register a printer in the universal print service using the Java SDK and I have been following this documentation - https://docs.microsoft.com/en-us/graph/api/printer-creat...
baywet
Microsoft
Apr 16, 2021Hi Himan Jo,
Thanks for reaching out.
I'm the main maintainer of the Microsoft Graph Java SDK.
The reason why the SDK is not returning any information as of now is because the create method is described as an action, and actions don't have a return type (search for Parameter Name="bindingParameter" Type="Collection(graph.printer)" in https://graph.microsoft.com/beta/$metadata )
I've let the product team know they should address this issue, either by correcting the documentation and removing the response payload or by using a Function with a return type instead so the code generated in the SDK will have a return type too.
In the meantime and as a workaround, you should be able to use a custom request like this:
final PrinterCreateParameterSet result = new CustomRequest<PrinterCreateParameterSet>("https://graph.microsoft.com/beta/print/printers/create", graphClient, null, PrinterCreateParameterSet.class).post(
PrinterCreateParameterSet
.newBuilder()
.withDisplayName(displayName)
.withManufacturer(manufacturer)
.withModel(model)
.withPhysicalDeviceId(physicalDeviceId)
.withHasPhysicalDevice(hasPhysicalDevice)
.withCertificateSigningRequest(certificateSigningRequest)
.withConnectorId(connectorId)
.build());
Thanks for reaching out.
I'm the main maintainer of the Microsoft Graph Java SDK.
The reason why the SDK is not returning any information as of now is because the create method is described as an action, and actions don't have a return type (search for Parameter Name="bindingParameter" Type="Collection(graph.printer)" in https://graph.microsoft.com/beta/$metadata )
I've let the product team know they should address this issue, either by correcting the documentation and removing the response payload or by using a Function with a return type instead so the code generated in the SDK will have a return type too.
In the meantime and as a workaround, you should be able to use a custom request like this:
final PrinterCreateParameterSet result = new CustomRequest<PrinterCreateParameterSet>("https://graph.microsoft.com/beta/print/printers/create", graphClient, null, PrinterCreateParameterSet.class).post(
PrinterCreateParameterSet
.newBuilder()
.withDisplayName(displayName)
.withManufacturer(manufacturer)
.withModel(model)
.withPhysicalDeviceId(physicalDeviceId)
.withHasPhysicalDevice(hasPhysicalDevice)
.withCertificateSigningRequest(certificateSigningRequest)
.withConnectorId(connectorId)
.build());
- NishantLakhanpalApr 16, 2021
Microsoft
Hi HimanJo,
The printer-create action is a long running operation. Hence, it returns an empty response body and a URL(in 'Operation-Location' header) to track the status of the operation.
Due to limitation in Graph SDK, you can't directly fetch the response headers for POST request that returns empty response body.
There's a workaround for that. You can get request from Graph SDK:
graphClient.print().printers()
.create(PrinterCreateParameterSet
.newBuilder()
.withDisplayName(displayName)
.withManufacturer(manufacturer)
.withModel(model)
.withPhysicalDeviceId(physicalDeviceId)
.withHasPhysicalDevice(hasPhysicalDevice)
.withCertificateSigningRequest(certificateSigningRequest)
.withConnectorId(connectorId)
.build())
.buildRequest().getHttpRequest();
Then you can use native client to get response, similar to this:
https://github.com/microsoftgraph/msgraph-sdk-java-core#3-make-requests-against-the-service
After fetching the operationId from "Operation-Location" header, you can get operation:
PrintOperation printOperation = graphClient.print().operations("{printOperationId}")
.buildRequest()
.get();
This return type is PrintOperation, however, it will return PrinterCreateOperation (which inherits from PrintOperation).
Hence, you can explicitly cast printOperation to PrinterCreateOperation.