Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jacky_Liu
Product and Topic Expert
Product and Topic Expert
1,627
In the blog SAP Print Service, markus.berg has introduce BTP SAP Print Service. In my following 2 blogs, I will introduce how to configure, how to test, and how to use it in UI5 . There is mission Add Printing Label to Your User Experience for SAP S/4HANA Cloud.in which a S4Hana Cloud side by side extension for label printing has been introduced in detail.  Configure printing service is big part of it . You can find detailed information in the mission also .

Prerequisite:


You have installed postman on your computer .

Step 1, Check entitlement in BTP cockpit in your sub-account, the following 3 printing service plans should be listed .


To do this, the role Subaccount Admin should be assigned to your user . If you can not find the following 3 print service plans , please contact your BTP customer success manager .



Step 2, Onboarding.


In this step you will create service instances for plan sender and receiver.Service keys for plan sender and receiver will be created .To take out this step you can use Booster from BTP cockpit in global account. Plan sender is used to upload document and create printing task. Plan receiver will be used by cloud printing manager to connect.



 

Step 3, Create subscription for print service plan standard configure authorization


You can following the document to create print service subscription .

For authorization configuration , you can follow the following documents :

Defining and Bundling Roles

Assigning Role Collections to Users

Configuring Role Collection

 

Step 3, Create printQ .






 

Step 4, Note down service key information of service instance of plan sender .



Note down the information in the red frame .



Step 5, Save postman collection content as a  json file.


{
"info": {
"_postman_id": "43b9377d-9355-4e0b-bd4f-044c9deb6d9d",
"name": "print",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Step1 Get Token",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.collectionVariables.set(\"bearToken\",\"Bearer \".concat(pm.response.json().access_token))"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "{{printclientsecret}}",
"type": "string"
},
{
"key": "username",
"value": "{{printclientkey}}",
"type": "string"
}
]
},
"method": "POST",
"header": [],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "grant_type",
"value": "client_credentials",
"type": "default"
}
]
},
"url": {
"raw": "{{printtokenurl}}",
"host": [
"{{printtokenurl}}"
]
}
},
"response": []
},
{
"name": "Step2 Get PrintQ",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.collectionVariables.set(\"printQ\",pm.response.json()[0].qname)"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"pm.request.addHeader(\"Authorization\",pm.collectionVariables.get(\"bearToken\"));"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "oauth2",
"oauth2": [
{
"key": "clientId",
"value": "{{printclientkey}}",
"type": "string"
},
{
"key": "accessTokenUrl",
"value": "{{printtokenurl}}",
"type": "string"
},
{
"key": "grant_type",
"value": "client_credentials",
"type": "string"
},
{
"key": "clientSecret",
"value": "{{printclientsecret}}",
"type": "string"
},
{
"key": "tokenName",
"value": "printkey",
"type": "string"
},
{
"key": "addTokenTo",
"value": "header",
"type": "string"
},
{
"key": "scope",
"value": "",
"type": "string"
},
{
"key": "tokenType",
"value": "Bearer",
"type": "string"
},
{
"key": "client_authentication",
"value": "header",
"type": "string"
},
{
"key": "password",
"value": "Guoq07@5",
"type": "string"
},
{
"key": "username",
"value": "jacky.liu02@sap.com",
"type": "string"
},
{
"key": "headerPrefix",
"value": "Bearer",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"url": {
"raw": "{{printserviceurl}}/qm/api/v1/rest/queues",
"host": [
"{{printserviceurl}}"
],
"path": [
"qm",
"api",
"v1",
"rest",
"queues"
]
}
},
"response": []
},
{
"name": "Step3 Upload Document",
"event": [
{
"listen": "test",
"script": {
"exec": [
"if(pm.response.to.have.status(201)){",
" pm.collectionVariables.set(\"dmId\",pm.response.text());",
" pm.collectionVariables.set(\"fileName\",pm.request.body.formdata.all()[0].src.split(\"/\").last());",
"}",
" "
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"pm.request.addHeader(\"Authorization\",pm.collectionVariables.get(\"bearToken\"));"
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disabledSystemHeaders": {
"accept-encoding": true,
"connection": true,
"accept": true
}
},
"request": {
"auth": {
"type": "oauth2",
"oauth2": [
{
"key": "grant_type",
"value": "client_credentials",
"type": "string"
},
{
"key": "client_authentication",
"value": "header",
"type": "string"
},
{
"key": "clientId",
"value": "{{printclientkey}}",
"type": "string"
},
{
"key": "accessTokenUrl",
"value": "{{printtokenurl}}",
"type": "string"
},
{
"key": "clientSecret",
"value": "{{printclientsecret}}",
"type": "string"
},
{
"key": "tokenName",
"value": "printkey",
"type": "string"
},
{
"key": "addTokenTo",
"value": "header",
"type": "string"
},
{
"key": "scope",
"value": "",
"type": "string"
},
{
"key": "tokenType",
"value": "Bearer",
"type": "string"
},
{
"key": "password",
"value": "Guoq07@5",
"type": "string"
},
{
"key": "username",
"value": "jacky.liu02@sap.com",
"type": "string"
},
{
"key": "headerPrefix",
"value": "Bearer",
"type": "string"
}
]
},
"method": "POST",
"header": [
{
"key": "If-None-Match",
"value": "*",
"type": "default"
},
{
"key": "scan",
"value": "true",
"type": "default"
},
{
"key": "Accept",
"value": "application/json",
"type": "default"
},
{
"key": "DataServiceVersion",
"value": "2.0",
"type": "default"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/Users/I501000/Downloads/q4.jpg"
}
]
},
"url": {
"raw": "{{printserviceurl}}/dm/api/v1/rest/print-documents",
"host": [
"{{printserviceurl}}"
],
"path": [
"dm",
"api",
"v1",
"rest",
"print-documents"
]
}
},
"response": []
},
{
"name": "Step4 Create Print Task",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"pm.request.addHeader(\"Authorization\",pm.collectionVariables.get(\"bearToken\"));"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "oauth2",
"oauth2": [
{
"key": "grant_type",
"value": "client_credentials",
"type": "string"
},
{
"key": "client_authentication",
"value": "header",
"type": "string"
},
{
"key": "clientId",
"value": "{{printclientkey}}",
"type": "string"
},
{
"key": "accessTokenUrl",
"value": "{{printtokenurl}}",
"type": "string"
},
{
"key": "clientSecret",
"value": "{{printclientsecret}}",
"type": "string"
},
{
"key": "tokenName",
"value": "printkey",
"type": "string"
},
{
"key": "addTokenTo",
"value": "header",
"type": "string"
},
{
"key": "scope",
"value": "",
"type": "string"
},
{
"key": "tokenType",
"value": "Bearer",
"type": "string"
},
{
"key": "password",
"value": "Guoq07@5",
"type": "string"
},
{
"key": "username",
"value": "jacky.liu02@sap.com",
"type": "string"
},
{
"key": "headerPrefix",
"value": "Bearer",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "If-None-Match",
"value": "*",
"type": "default"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"numberOfCopies\": 1,\n \"username\": \"test user\",\n \"qname\": \"{{printQ}}\",\n \"metadata\": {\n \"business_metadata\": {\n \"business_user\": \"user1\",\n \"object_node_type\": \"object_node_1\"\n },\n \"version\": 1.2\n },\n \"printContents\": [\n {\n \"objectKey\": \"{{dmId}}\",\n \"documentName\": \"{{fileName}}\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{printserviceurl}}/qm/api/v1/rest/print-tasks/{{dmId}}",
"host": [
"{{printserviceurl}}"
],
"path": [
"qm",
"api",
"v1",
"rest",
"print-tasks",
"{{dmId}}"
],
"query": [
{
"key": "itemId",
"value": "2349add8-d48e-46ee-91d6-e7bb98cfdbff",
"disabled": true
}
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "printtokenurl",
"value": "https://apjcoe-x66183k9.authentication.eu10.hana.ondemand.com/oauth/token",
"type": "default"
},
{
"key": "printclientkey",
"value": "sb-6aa6869e-be8|print-app!b46384",
"type": "default"
},
{
"key": "printclientsecret",
"value": "Dw8LMo=",
"type": "default"
},
{
"key": "printserviceurl",
"value": "https://api.eu10.print.services.sap",
"type": "default"
},
{
"key": "dmId",
"value": "",
"type": "default"
},
{
"key": "fileName",
"value": ""
},
{
"key": "printQ",
"value": ""
},
{
"key": "bearToken",
"value": ""
}
]
}

Step 6, Import collection from step 5's json file in postman.




Step 7, Maintain collection variable base on service key information from step 4.


Maintain the variables in the red frame.



Step 8, Execute the request steps from step 1 to step 4 sequently in postman.


Note: The collection transfer variant between steps. Only in step 3, you need to select a picture or a pdf document in request body.




Step 9, Check the result in print Q


We can find the created print task in the following screenshot .


 

The print task shown in the print Queue. After you have installed cloud print manager and connected your cloud print manager to the print queue, the cloud print manager will send the print task to a local printer .

 

Thanks for your time!

Best Regards!

Jacky Liu