Namespace: microsoft.graph
Important
APIs under the /beta
version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Create an upload session that allows an app to iteratively upload ranges of a binary file linked to the print document.
As part of the response, this action returns an upload URL that can be used in subsequent sequential PUT
queries. Request headers for each PUT
operation can be used to specify the exact range of bytes to be uploaded. This allows transfer to be resumed, in case the network connection is dropped during upload.
Note: Creating an upload session using application permissions will only succeed if there is a printTask in a processing
state on the associated print job, started by a trigger that the requesting app created. For details about how to register a task trigger, see Extending Universal Print to support pull printing.
This API is available in the following national cloud deployments.
Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
✅ |
✅ |
✅ |
❌ |
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
Permission type |
Least privileged permissions |
Higher privileged permissions |
Delegated (work or school account) |
PrintJob.Create |
PrintJob.ReadWrite, PrintJob.ReadWrite.All |
Delegated (personal Microsoft account) |
Not supported. |
Not supported. |
Application |
PrintJob.ReadWrite.All |
Not available. |
HTTP request
To create an upload session using printer:
POST /print/printers/{id}/jobs/{id}/documents/{id}/createUploadSession
To create an upload session using printerShare (supported with delegated permissions only):
POST /print/shares/{id}/jobs/{id}/documents/{id}/createUploadSession
Request body
In the request body, provide a JSON object with the following parameters.
The value of the contentType property in the request body should be supported by the printer/printerShare. You can get the supported content types by getting printerCapabilities of the printer/printerShare.
For OXPS to PDF conversion, you need to pass application/oxps
as contentType for printer/printerShare that supports application/pdf
.
Universal Print converts OXPS to PDF, when all the following conditions are met:
- The printer/printer share supports
application/pdf
in printerCapabilities.
- The printer/printer share does NOT support
application/oxps
in printerCapabilities.
- The value for the contentType property in the request body is
application/oxps
.
Response
If successful, this method returns a 200 OK
response code and a new uploadSession object in the response body.
Note: The uploadUrl property returned as part of the uploadSession response object is an opaque URL for subsequent PUT
queries to upload byte ranges of the file. It contains the appropriate auth token for subsequent PUT
queries that expire by expirationDateTime. Do not change this URL.
Examples
The following example shows how to create an upload session that you can use in subsequent file upload operations to the specified printDocument.
Request
POST https://graph.microsoft.com/beta/print/shares/1c879027-5120-4aaf-954a-ebfd509a3bcc/jobs/46207/documents/9001bcd9-e36a-4f51-bfc6-140c3ad7f9f7/createUploadSession
Content-type: application/json
{
"properties": {
"documentName": "TestFile.pdf",
"contentType": "application/pdf",
"size": 4533322
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Print.Shares.Item.Jobs.Item.Documents.Item.CreateUploadSession;
using Microsoft.Graph.Beta.Models;
var requestBody = new CreateUploadSessionPostRequestBody
{
Properties = new PrintDocumentUploadProperties
{
DocumentName = "TestFile.pdf",
ContentType = "application/pdf",
Size = 4533322L,
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Print.Shares["{printerShare-id}"].Jobs["{printJob-id}"].Documents["{printDocument-id}"].CreateUploadSession.PostAsync(requestBody);
mgc-beta print shares jobs documents create-upload-session post --printer-share-id {printerShare-id} --print-job-id {printJob-id} --print-document-id {printDocument-id} --body '{\
"properties": {\
"documentName": "TestFile.pdf",\
"contentType": "application/pdf", \
"size": 4533322\
}\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphprint "github.com/microsoftgraph/msgraph-beta-sdk-go/print"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphprint.NewCreateUploadSessionPostRequestBody()
properties := graphmodels.NewPrintDocumentUploadProperties()
documentName := "TestFile.pdf"
properties.SetDocumentName(&documentName)
contentType := "application/pdf"
properties.SetContentType(&contentType)
size := int64(4533322)
properties.SetSize(&size)
requestBody.SetProperties(properties)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
createUploadSession, err := graphClient.Print().Shares().ByPrinterShareId("printerShare-id").Jobs().ByPrintJobId("printJob-id").Documents().ByPrintDocumentId("printDocument-id").CreateUploadSession().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.print.shares.item.jobs.item.documents.item.createuploadsession.CreateUploadSessionPostRequestBody createUploadSessionPostRequestBody = new com.microsoft.graph.beta.print.shares.item.jobs.item.documents.item.createuploadsession.CreateUploadSessionPostRequestBody();
PrintDocumentUploadProperties properties = new PrintDocumentUploadProperties();
properties.setDocumentName("TestFile.pdf");
properties.setContentType("application/pdf");
properties.setSize(4533322L);
createUploadSessionPostRequestBody.setProperties(properties);
var result = graphClient.print().shares().byPrinterShareId("{printerShare-id}").jobs().byPrintJobId("{printJob-id}").documents().byPrintDocumentId("{printDocument-id}").createUploadSession().post(createUploadSessionPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const uploadSession = {
properties: {
documentName: 'TestFile.pdf',
contentType: 'application/pdf',
size: 4533322
}
};
await client.api('/print/shares/1c879027-5120-4aaf-954a-ebfd509a3bcc/jobs/46207/documents/9001bcd9-e36a-4f51-bfc6-140c3ad7f9f7/createUploadSession')
.version('beta')
.post(uploadSession);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Print\Shares\Item\Jobs\Item\Documents\Item\CreateUploadSession\CreateUploadSessionPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\PrintDocumentUploadProperties;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CreateUploadSessionPostRequestBody();
$properties = new PrintDocumentUploadProperties();
$properties->setDocumentName('TestFile.pdf');
$properties->setContentType('application/pdf');
$properties->setSize(4533322);
$requestBody->setProperties($properties);
$result = $graphServiceClient->escapedPrint()->shares()->byPrinterShareId('printerShare-id')->jobs()->byPrintJobId('printJob-id')->documents()->byPrintDocumentId('printDocument-id')->createUploadSession()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Devices.CloudPrint
$params = @{
properties = @{
documentName = "TestFile.pdf"
contentType = "application/pdf"
size = 4533322
}
}
New-MgBetaPrintShareJobDocumentUploadSession -PrinterShareId $printerShareId -PrintJobId $printJobId -PrintDocumentId $printDocumentId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.print.shares.item.jobs.item.documents.item.create_upload_session.create_upload_session_post_request_body import CreateUploadSessionPostRequestBody
from msgraph_beta.generated.models.print_document_upload_properties import PrintDocumentUploadProperties
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = CreateUploadSessionPostRequestBody(
properties = PrintDocumentUploadProperties(
document_name = "TestFile.pdf",
content_type = "application/pdf",
size = 4533322,
),
)
result = await graph_client.print.shares.by_printer_share_id('printerShare-id').jobs.by_print_job_id('printJob-id').documents.by_print_document_id('printDocument-id').create_upload_session.post(request_body)
Response
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#microsoft.graph.uploadSession",
"uploadUrl": "https://print.print.microsoft.com/uploadSessions/5400be13-5a4e-4c20-be70-90c85bfe5d6e?tempauthtoken={token}",
"expirationDateTime": "2020-10-25T02:19:38.1694207Z",
"nextExpectedRanges": [
"0-4533321"
]
}