SAP API Business Hub - ERP Q&A https://www.erpqna.com Trending SAP Career News and Guidelines Fri, 24 Nov 2023 11:53:55 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.3 https://www.erpqna.com/wp-content/uploads/2021/11/cropped-erpqna-32x32.png SAP API Business Hub - ERP Q&A https://www.erpqna.com 32 32 Test BTP SAP Print Service With Postman https://www.erpqna.com/test-btp-sap-print-service-with-postman/?utm_source=rss&utm_medium=rss&utm_campaign=test-btp-sap-print-service-with-postman Sun, 25 Dec 2022 09:04:20 +0000 https://www.erpqna.com/?p=71272 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 […]

The post Test BTP SAP Print Service With Postman first appeared on ERP Q&A.

]]>
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"
					}
				}
			],
			"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.collectionVariables.get(\"dmId\");"
						],
						"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-be85-4b6f-b2345|print-app!b46384",
			"type": "default"
		},
		{
			"key": "printclientsecret",
			"value": "Dwsj8LMo=",
			"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.

only maintain the variables in the red frame.

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

Note: In step 3, please 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.

Rating: 0 / 5 (0 votes)

The post Test BTP SAP Print Service With Postman first appeared on ERP Q&A.

]]>
Explore SAP BTP DMS Rest APIs https://www.erpqna.com/explore-sap-btp-dms-rest-apis/?utm_source=rss&utm_medium=rss&utm_campaign=explore-sap-btp-dms-rest-apis Sat, 11 Jun 2022 10:15:44 +0000 https://www.erpqna.com/?p=63977 Introduction The Document Management Service helps you in the management of your business’s documents. It’s based on the OASIS (Organization for the Advancement of Structured Information Standards) industry standard CMIS (Content Management Interoperability Services) and includes features like versioning, hierarchies, access control, and document management SAP Document Management Service on Business Technology Platform, is recently […]

The post Explore SAP BTP DMS Rest APIs first appeared on ERP Q&A.

]]>

Introduction

The Document Management Service helps you in the management of your business’s documents. It’s based on the OASIS (Organization for the Advancement of Structured Information Standards) industry standard CMIS (Content Management Interoperability Services) and includes features like versioning, hierarchies, access control, and document management

SAP Document Management Service on Business Technology Platform, is recently released by SAP and comes in two flavors

Document Management Service, Application Option, which is the standalone SaaS offering (ready-to-use web application that provides document management capabilities for your enterprise content)

Document Management Service, Integration Option lets you build document management capabilities for your business applications using the integration component(APIs) or the easy-to-use, reusable UI component

Business Scenario

Recently, I have been working for an unique requirement where we need to replicate documents from different SAP SaaS applications(for ex: SAP SuccessFactors EC) to SAP BTP Document Management Service. As there is no native integration exists in between these two applications, we need to place a custom solution using SAP BTP Cloud Integration as an iPaaS.

The complete process of extracting the documents from SAP SaaS application and uploading it into SAP BTP DMS can be automated if using a middleware(for example SAP BTP Cloud Integration)

Pre-requisites

  1. SAP Business Technology Platform Document Management Service, Integration option setup (Create a subaccount, space, service instance and key).
  2. Setup SAP BTP DMS repository

Scope of this document

The scope of this document covers the below scenarios

  • Generate a JSON Web Token
  • Create Folder in DMS
  • Access Control for Folder
  • Create document in DMS
  • Access Control for documents
  • How to do Version management(Check In & Check Out) for the documents
  • Deletion of a document
  • Deletion of a folder

We will use Postman client in this blog to explore and understand different SAP BTP DMS APIs call.

Generate a JSON Web Token

JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA

DMS API calls

We can generate two types of JWT from DMS Authorization server, depending upon the specific use case, admin or user specific JWT can be generated.

Admin JWT

Admin JWT
  1. URL: https://<< Oauth Token URL >>/oauth/token?grant_type=client_credentials
  2. Authentication: Client id and client secret from BTP DMS Service key
  3. Response body: JWT Token
  4. HTTP response code: 200

Repository Id

User specific JWT
  1. URL: https://<< Oauth Token URL >>/oauth/token?grant_type=password&username=<<User email id>>&password=<<User password>>
  2. URL parameters: User email id and User password
  3. Authentication: Client id and client secret from BTP DMS Service key
  4. Response body: JWT Token
  5. HTTP response code: 200

Create Folder in DMS

DMS provides below API and supported parameters to create folders inside the repository

Folder creation
  1. URL: https://<<ECM Service URL>>/browser/<<Repository Id>>/root/
  2. Repository Id: DMS repository Id
  3. Body parameters
  4. Response body: Folder object id
  5. HTTP response code: 201
  • cmisaction: createFolder (In order to perform this particular operation in DMS repository, cmisaction in an HTTP POST must be createFolder)
  • propertyId[0]: cmisname
  • propertyValue[0]: Test_AG1 (folder name)
  • propertyId[1]: cmis:objectTypeId
  • propertyId[1]: cmis:folder
  • succinct: true (Acts as a query parameter)

Result in DMS application

Below is the created folder in DMS

DMS folder

Access Control for Folder

Access control is very important to regulate the unauthorized access, DMS provides below API and supported parameters to assign Access control for folders inside the repository

Folder ACL
  1. URL: https://<<ECM Service URL>>/browser/<<Repository Id>>/root
  2. Repository Id: DMS repository Id
  3. Body parameters
  4. Response body: Folder ACL response
  5. HTTP response code: 201
  • cmisaction: applyACL
  • objectId: Folder objectId
  • ACLPropagation: propagate (this property will propagate the access for all tree structure inside the folder)
  • addACEPrincipal[0]: AmanGupta@test.com (user email id on which the access to be granted)
  • addACEPermission[0][0]: cmis:all (read or all access for the user)

Result in DMS application

Below is the assigned Folder ACL result with the user email id

DMS folder ACL

Create document in DMS

DMS repository supports many different types of document upload, DMS provides below API and supported parameters to create documents inside the repository

Document creation
  1. URL: https://<<ECM Service URL>>/browser/<<Repository Id>>/root/Test_AG1
  2. Repository Id: DMS repository Id
  3. Folder name
  4. Body parameters
  5. HTTP response code: 201
  • cmisaction: createDocument (In order to perform this particular operation in DMS repository, cmisaction in an HTTP POST must be createDocument)
  • filename: AG.pdf
  • _charset: UTF-8
  • propertyId[0]: cmisname
  • propertyValue[0]: AG.pdf
  • propertyId[1]: cmis:objectTypeId
  • propertyId[1]: cmis:document
  • succinct: true (Acts as a query parameter)
  • includeAllowableActions: true (If true, then the Repository must return the available actions for each object in the result set)
  • media: file content(binary)

Result in DMS application

Below is the created document under the folder in DMS

DMS document

Access Control for documents

Access control is very important to regulate the unauthorized access, DMS provides below API and supported parameters to assign Access control for documents inside the folder

Document ACL
  1. URL: https://<<ECM Service URL>>/browser/<<Repository Id>>/root/
  2. Repository Id: DMS repository Id
  3. Body parameters
  4. Response body: Document ACL response
  5. HTTP response code: 201
  • cmisaction: applyACL
  • objectId: Document objectId
  • addACEPrincipal[0]: AmanGupta@test.com (user email id for whom access to be granted)
  • addACEPermission[0][0]: cmis:all (read or all access for the user)

Result in DMS application

Below is the Access Control applied for the document in DMS

DMS document ACL

Version management

Version management or version control allows the management of changes in requirements over time. It allows a complete retrace of all versions in each document, with the restore version capability.

Version management in SAP BTP DMS can be done by following the Check out and Check in procedure as stated below

Get object id

First of all, we need to get object id for the document where the versioning needs to be maintained

Folder object list
  1. URL: https://<<ECM Service URL>>/browser/<<Repository Id>>/root/Test_AG1
  2. Repository Id: DMS repository Id
  3. Folder name
  4. Response body: Document object id
  5. HTTP response code: 200

Document Check Out

Based on the unique object id retrieved in the last step, below DMS API call is needed to check out the document

Document check out
  1. URL: https://<<ECM Service URL>>/browser/<>/root/Test_AG1
  2. Repository Id: DMS repository Id
  3. Folder name
  4. Response body: New document object id
  5. HTTP response code: 201
  • cmisaction: checkOut (In order to perform this particular operation in DMS repository, cmisaction in an HTTP POST must be checkOut)
  • objectId: Document object id
  • succinct: true (Acts as a query parameter)
  • includeAllowableActions: true (If true, then the Repository must return the available actions for each object in the result set)

Result in DMS application

Below is the result in DMS with document marked in check out state

DMS document check out

Document Check In

Based on the new unique object id for the document check out retrieved in the last step, below DMS API call is needed to check in the document with the updated document content and comment for the new version

Document check in
  1. URL: https://<<ECM Service URL>>/browser/<<Repository Id>>/root/Test_AG1
  2. Repository Id: DMS repository Id
  3. Folder name
  4. Response body: New document object id
  5. HTTP response code: 201
  • cmisaction: checkIn (In order to perform this particular operation in DMS repository, cmisaction in an HTTP POST must be checkIn)
  • objectId: Checked out document object id
  • filename: AG.pdf
  • _charset: UTF-8
  • succinct: true (Acts as a query parameter)
  • includeAllowableActions: true (If true, then the Repository must return the available actions for each object in the result set)
  • media: file content(binary)
  • checkInComment: Updated content in the file
  • major: false

Result in DMS application

Below is the result in DMS with document versioning after checking in, all the previous versions can still be downloaded and restored

DMS document versions

Deletion of a document

In order to delete a document, DMS provides below API. It deletes the specified object and all of it’s properties present in a repository

Delete document
  1. URL: https://<<ECM Service URL>>/browser/<<Repository Id>>/root/Test_AG1
  2. Repository Id: DMS repository Id
  3. Folder name
  4. Body parameters
  5. HTTP response code: 200
  • cmisaction: delete
  • objectId: Document objectId

Deletion of a folder

In order to delete a folder, DMS provides below API. It deletes the specified folder and all the descendant-objects of the folder. A repository may attempt to delete child- and descendant-objects of the specified folder in any order. Any child- or descendant-object that the repository cannot delete must persist in a valid state in the CMIS domain model.

Delete folder
  1. URL: https://<<ECM Service URL>>/browser/<<Repository Id>>/root/
  2. Repository Id: DMS repository Id
  3. Body parameters
  4. HTTP response code: 200
  • cmisaction: deleteTree
  • objectId: Folder objectId
  • continueOnFailure: true (If true, then the repository should continue attempting to perform this operation even if deletion of a child- or descendant-object in the specified folder cannot be deleted)
Rating: 0 / 5 (0 votes)

The post Explore SAP BTP DMS Rest APIs first appeared on ERP Q&A.

]]>
Create Purchase Orders in S/4HANA by enabling a public API from a S/4HANA On-Premise System using SAP API Management and Cloud Connector https://www.erpqna.com/create-purchase-orders-in-s-4hana-by-enabling-a-public-api-from-a-s-4hana-on-premise-system-using-sap-api-management-and-cloud-connector/?utm_source=rss&utm_medium=rss&utm_campaign=create-purchase-orders-in-s-4hana-by-enabling-a-public-api-from-a-s-4hana-on-premise-system-using-sap-api-management-and-cloud-connector Tue, 10 May 2022 13:02:07 +0000 https://www.erpqna.com/?p=62893 The use case I wanted to set up was to expose an API from a S/4HANA on-premise system to consume it in a custom application developed in SAP Business Technology Platform, which its purpose is to create a Purchase Orders in the S/4HANA system. Prerequisites: Important note: Make sure your Cloud Connector is running otherwise […]

The post Create Purchase Orders in S/4HANA by enabling a public API from a S/4HANA On-Premise System using SAP API Management and Cloud Connector first appeared on ERP Q&A.

]]>
The use case I wanted to set up was to expose an API from a S/4HANA on-premise system to consume it in a custom application developed in SAP Business Technology Platform, which its purpose is to create a Purchase Orders in the S/4HANA system.

Prerequisites:

  • Create an SAP Business Technology Platform (BTP) trial account (if case you don’t have one).
  • Enable the Integration Suite service and API Management in SAP BTP. This tutorial can give you through.
  • A S/4HANA system.
  • Install the Cloud Connector in the same network where your S/4HANA system resides: https://tools.hana.ondemand.com/#cloud.

Important note: Make sure your Cloud Connector is running otherwise you won’t be able to access it.

To run it (after you have downloaded and unzip it), double-click on go.bat:

When you have already changed the password, you must define your SAP BTP Subaccount.

Enter your SAP BTP information, at least with this info:

  • Subaccount ID
  • Region
  • User
  • Password

You should see it like this:

Now you can check in your BTP account that indeed the Cloud Connector is connected.

Now, as we want to consume the API from a custom SAP BTP App, we need to configure a Cloud To On-Premise connection.

Go back to your Cloud Connector and click on “Cloud To On-Premise” and add a System Mapping.

The blog post I mentioned above helped a lot to configure my System Mapping.

  • Back-end Type: ABAP System (I used Non-SAP System and worked as well)
  • Protocol: HTTP
  • Internal Host & Port: You can find it while executing a Get request in your SAP Gateway Client, open “Response in Browser” and you’ll see the Internal Host and Port in the “xml:base”, see below the [optional] test (or follow as the blog post mentioned above).
  • Virtual Host: you can provide any name (like: sanbox.company.com)
  • Virtual Port: you can provide any number
  • Principal type: None
  • Host in Request Header: Use Virtual Host
  • Description: anything you want (I left it blank)

Click on Finish. Now, add a resource to your System Mapping. I added /sap/opu/odata with the access policy “Path and All Sub-Paths” and leave the check box “active”. After these steps are done, you should see your system like this:

Now check again in your SAP BTP account, you should be able to see your Back-End system available.

To consume this service, it is not necessary to create a Destination in your SAP BTP account.

Now go to your SAP API Management account.

Create an API Provider.

  • Overview tab: Enter any name you want and description you want.
  • Connection tab:
    • Type: On Premise
    • Host: The Virtual Host you set in the Cloud Connector
    • Port: The Virtual Port you set in the Cloud Connector
  • Catalog Service Settings:
    • Path Prefix: /sap/opu/odata
    • Service Collection URL: /IWFND/CATALOGSERVICE;v=2/ServiceCollection
    • Authentication type: Basic
      • Username: Your S/4HANA username
      • Password: Your S/4HANA user password.

Click Save and Deploy.

[Optional:

If you want, you can test the Service Collection URL directly in your SAP Gateway Client.

1. Go to your SAP Logon, select your S/4HANA system and enter it using your S/4HANA credentials.
2. Enter the TCODE “/N/IWFND/MAINT_SERVICE”. Search in the icon “Catalog Service” and double-click in “Catalog Service Version 2”, so the button SAP Gateway Client gets available to press it.

3. Execute the Get request and click on “Response in Browser” to see the XML response:

]

Now you need to create the API.

Select the API Provider you just created and click on “Discover”.

For this exercise we are going to create Purchase Orders, so let’s search for “Purchase”:

You can find more in the SAP API Business Hub documentation.

Click in your API, Save and Deploy it.

Go to Resources and you’ll be able to see the Path and Payload needed to create Purchase Orders.

Open Postman, and let’s test it first by sending a Get request of the top 1 PO and let’s fetch the access token.

  • URL: your API Proxy URL
  • Authentication: Basic
    • Username: Your S/4HANA username
    • Password: Your S/4HANA user password.
  • Add in Headers:
    • x-csrf-token: Fetch

You can copy/paste this JSON Object as headers for your custom application.

{
    "Accept": "application/json",
    "Content-Type": "application/json",
    "x-csrf-token": "Fetch",
    "Accept-Encoding": "application/json",
    "Connection": "keep-alive",
    "Authorization": "<S/4HANA credentials in Base64>"
}

Now, let’s test the Post request. Of course, it’s important you test it with actual data Supplier, Material, Purchase Org, Company Code, etc. from your S/4HANA system. Remember to pass the x-csrf-token in the header.

I used this Payload as an example, to create a PO with a single material item:

{
    "CompanyCode": "R100",
    "PurchaseOrderType": "NB",
    "PurchasingDocumentDeletionCode": "",
    "PurchasingProcessingStatus": "05",
    "Supplier": "RSU1000000",
    "PurchaseOrderSubtype": "",
    "Language": "EN",
    "PaymentTerms": "0002",
    "CashDiscount1Days": "14",
    "CashDiscount2Days": "30",
    "NetPaymentDays": "0",
    "CashDiscount1Percent": "2.000",
    "CashDiscount2Percent": "0.000",
    "PurchasingOrganization": "R100",
    "PurchasingDocumentOrigin": "9",
    "PurchasingGroup": "WSG",
    "PurchaseOrderDate": "/Date(1492041600000)/",
    "DocumentCurrency": "EUR",
    "ExchangeRate": "1.00000",
    "ExchangeRateIsFixed": false,
    "ValidityStartDate": null,
    "ValidityEndDate": null,
    "SupplierQuotationExternalID": "",
    "SupplierRespSalesPersonName": "",
    "SupplierPhoneNumber": "",
    "SupplyingSupplier": "",
    "SupplyingPlant": "",
    "IncotermsClassification": "FOB",
    "CorrespncExternalReference": "",
    "CorrespncInternalReference": "4100000004",
    "InvoicingParty": "",
    "ReleaseIsNotCompleted": false,
    "PurchasingCompletenessStatus": false,
    "IncotermsVersion": "",
    "IncotermsLocation1": "Free on Board",
    "IncotermsLocation2": "",
    "ManualSupplierAddressID": "",
    "IsEndOfPurposeBlocked": "",
    "AddressCityName": "Bremen",
    "AddressFaxNumber": "",
    "AddressHouseNumber": "9C",
    "AddressName": "Joghurt Lieferant",
    "AddressPostalCode": "28217",
    "AddressStreetName": "Konsul-Smidt-Straße",
    "AddressPhoneNumber": "(0421)3889512",
    "AddressRegion": "HB",
    "AddressCountry": "DE",
    "AddressCorrespondenceLanguage": "EN",
    "to_PurchaseOrderItem": {
        "results": [
            {
                "PurchaseOrderItem": "10",
                "PurchasingDocumentDeletionCode": "",
                "PurchaseOrderItemText": "Roma Tomato Organic",
                "Plant": "R163",
                "StorageLocation": "R10A",
                "MaterialGroup": "RS11910",
                "PurchasingInfoRecord": "",
                "SupplierMaterialNumber": "",
                "OrderQuantity": "1",
                "PurchaseOrderQuantityUnit": "PC",
                "OrderPriceUnit": "PC",
                "OrderPriceUnitToOrderUnitNmrtr": "1",
                "OrdPriceUnitToOrderUnitDnmntr": "1",
                "DocumentCurrency": "EUR",
                "NetPriceAmount": "0.00",
                "NetPriceQuantity": "1",
                "TaxCode": "",
                "TaxDeterminationDate": null,
                "TaxCountry": "",
                "PriceIsToBePrinted": true,
                "OverdelivTolrtdLmtRatioInPct": "0.0",
                "UnlimitedOverdeliveryIsAllowed": false,
                "UnderdelivTolrtdLmtRatioInPct": "0.0",
                "ValuationType": "",
                "IsCompletelyDelivered": false,
                "IsFinallyInvoiced": false,
                "PurchaseOrderItemCategory": "0",
                "AccountAssignmentCategory": "",
                "MultipleAcctAssgmtDistribution": "",
                "PartialInvoiceDistribution": "",
                "GoodsReceiptIsExpected": false,
                "GoodsReceiptIsNonValuated": false,
                "InvoiceIsExpected": false,
                "InvoiceIsGoodsReceiptBased": false,
                "PurchaseContract": "",
                "PurchaseContractItem": "0",
                "Customer": "",
                "Subcontractor": "",
                "SupplierIsSubcontractor": false,
                "ItemNetWeight": "0",
                "ItemWeightUnit": "LB",
                "TaxJurisdiction": "",
                "PricingDateControl": "",
                "ItemVolume": "0.000",
                "ItemVolumeUnit": "",
                "SupplierConfirmationControlKey": "",
                "IncotermsClassification": "",
                "IncotermsTransferLocation": "",
                "EvaldRcptSettlmtIsAllowed": false,
                "PurchaseRequisition": "",
                "PurchaseRequisitionItem": "0",
                "IsReturnsItem": false,
                "RequisitionerName": "",
                "ServicePackage": "0",
                "EarmarkedFunds": "",
                "EarmarkedFundsDocument": "",
                "EarmarkedFundsItem": "0",
                "EarmarkedFundsDocumentItem": "0",
                "IncotermsLocation1": "",
                "IncotermsLocation2": "",
                "Material": "4909",
                "InternationalArticleNumber": "",
                "ManufacturerMaterial": "4909",
                "ServicePerformer": "",
                "ProductType": "1",
                "ExpectedOverallLimitAmount": "0.00",
                "OverallLimitAmount": "0.00",
                "PurContractForOverallLimit": "",
                "ReferenceDeliveryAddressID": "",
                "DeliveryAddressID": "",
                "DeliveryAddressName": "Berlin Store",
                "DeliveryAddressName2": "",
                "DeliveryAddressFullName": "Berlin Store",
                "DeliveryAddressStreetName": "St. Wolfgang-Str",
                "DeliveryAddressHouseNumber": "13",
                "DeliveryAddressCityName": "Berlin",
                "DeliveryAddressPostalCode": "10178",
                "DeliveryAddressRegion": "11",
                "DeliveryAddressCountry": "DE",
                "DownPaymentType": "",
                "DownPaymentPercentageOfTotAmt": "0.00",
                "DownPaymentAmount": "0.00",
                "DownPaymentDueDate": null,
                "BR_MaterialUsage": "",
                "BR_MaterialOrigin": "",
                "BR_CFOPCategory": "",
                "BR_IsProducedInHouse": false,
                "ConsumptionTaxCtrlCode": "",
                "ProductSeasonYear": "",
                "ProductSeason": "",
                "ProductCollection": "",
                "ProductTheme": "",
                "SeasonCompletenessStatus": "",
                "ProductCharacteristic1": "",
                "ProductCharacteristic2": "",
                "ProductCharacteristic3": "",
                "PurchasingParentItem": "0",
                "SubItemCategory": "",
                "CrossPlantConfigurableProduct": "",
                "DiversionStatus": "",
                "ReferenceDocumentNumber": "",
                "ReferenceDocumentItem": "0",
                "PurchaseOrderReferenceType": "",
                "ReferenceDocumentScheduleLine": "0",
                "ArticleCategory": "00",
                "ItemHasValueAddedService": "",
                "ValAddedSrvcParentItmNumber": "0",
                "StockSegment": "",
                "RequirementSegment": ""
            }
        ]
    }
}

In conclusion, you can benefit from SAP API Management to expose all APIs from your on premise back-end systems, in this example S/4HANA. You can leverage this blog post to prototype custom applications to create Purchase Orders in S/4HANA, even go further and integrate it with SAP Workflow Management for instance, to request first the approval of these Purchase Orders before creating them. SAP Business Technology Platform offers you flexibility to keep extending functionality to your different IT systems/applications (and integrating them).

Rating: 0 / 5 (0 votes)

The post Create Purchase Orders in S/4HANA by enabling a public API from a S/4HANA On-Premise System using SAP API Management and Cloud Connector first appeared on ERP Q&A.

]]>