SAP电商云CCV2 Restful API enablement

74 阅读4分钟

感谢我的同事Zheng Kate的大力帮助。

Attachment 是注册用户的下单流程:

里面用了几个环境变量,你需要设置下, 只是红色部分

使用这个json的前提;

(1) 在hac里面有mobile_android的client, kevin说你知道怎么导入
(2) 在页面上先去注册一个用户 A
(3) 在postman的环境变量里把A的user和password和host的值先设置上

导入json后使用:

(1) 第一步获取token,拷贝下,在postman的环境变量里把client_customer的值设置下
(2) Create cart, 生成的cartID,拷贝下,在postman的环境变量里把cartguid的值设置下
(3) 然后按着顺序运行,运行到第7步下单后会生成一个orderid
(4) 运行第8步需要改下url里面的orderid就可以了

{
	"info": {
		"_postman_id": "6b7f9822-6ca0-4c24-a14f-d00a7e8b73b0",
		"name": "Reg-PlaceOrder",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "1. auth - client_customer",
			"request": {
				"method": "POST",
				"header": [],
				"url": {
					"raw": "https://{{host}}:9002/authorizationserver/oauth/token?client_id=mobile_android&client_secret=secret&grant_type=password&username={{user}}&password={{password}}",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"port": "9002",
					"path": [
						"authorizationserver",
						"oauth",
						"token"
					],
					"query": [
						{
							"key": "client_id",
							"value": "mobile_android"
						},
						{
							"key": "client_secret",
							"value": "secret"
						},
						{
							"key": "grant_type",
							"value": "password"
						},
						{
							"key": "username",
							"value": "{{user}}"
						},
						{
							"key": "password",
							"value": "{{password}}"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "2. CreateCart",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Authorization",
						"value": "{{trust_credential}}",
						"description": "trust_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_credential}}",
						"description": "client_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_customer}}",
						"description": "client_customer",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "{{client_manager}}",
						"description": "client_manager",
						"type": "text",
						"disabled": true
					},
					{
						"key": "",
						"value": "",
						"type": "text",
						"disabled": true
					}
				],
				"url": {
					"raw": "https://{{host}}:9002/rest/v2/electronics/users/{{user}}/carts",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"port": "9002",
					"path": [
						"rest",
						"v2",
						"electronics",
						"users",
						"{{user}}",
						"carts"
					]
				}
			},
			"response": []
		},
		{
			"name": "3. addProduct",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/json",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{trust_credential}}",
						"description": "trust_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_credential}}",
						"description": "client_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_customer}}",
						"description": "client_customer",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "{{client_manager}}",
						"description": "client_manager",
						"type": "text",
						"disabled": true
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n\t\"product\": {\n\t\t\"code\": \"779866\",\n\t\t\"quantity\": 1\n\t}\n}"
				},
				"url": {
					"raw": "https://{{host}}:9002/rest/v2/electronics/users/{{user}}/carts/{{cartguid}}/entries",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"port": "9002",
					"path": [
						"rest",
						"v2",
						"electronics",
						"users",
						"{{user}}",
						"carts",
						"{{cartguid}}",
						"entries"
					]
				}
			},
			"response": []
		},
		{
			"name": "4. CreateAddress",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "{{trust_credential}}",
						"description": "trust_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_credential}}",
						"description": "client_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_customer}}",
						"description": "client_customer",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "{{client_manager}}",
						"description": "client_manager",
						"type": "text",
						"disabled": true
					},
					{
						"key": "",
						"value": "",
						"type": "text",
						"disabled": true
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n   \"country\": {\n      \"isocode\": \"AD\"\n   },\n   \"defaultAddress\": true,\n   \"firstName\": \"terry\",\n   \"id\": \"8796552134679\",\n   \"lastName\": \"tan\",\n   \"line1\": \"tianfu\",\n   \"line2\": \"sdas\",\n   \"postalCode\": \"610000\",\n   \"titleCode\": \"mr\",\n   \"town\": \"city\"\n}\n\n\n"
				},
				"url": {
					"raw": "https://{{host}}:9002/rest/v2/electronics/users/{{user}}/carts/{{cartguid}}/addresses/delivery",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"port": "9002",
					"path": [
						"rest",
						"v2",
						"electronics",
						"users",
						"{{user}}",
						"carts",
						"{{cartguid}}",
						"addresses",
						"delivery"
					]
				}
			},
			"response": []
		},
		{
			"name": "5. deliveryMode",
			"request": {
				"method": "PUT",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/json",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{trust_credential}}",
						"description": "trust_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_credential}}",
						"description": "client_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_customer}}",
						"description": "client_customer",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "{{client_manager}}",
						"description": "client_manager",
						"type": "text",
						"disabled": true
					}
				],
				"body": {
					"mode": "raw",
					"raw": ""
				},
				"url": {
					"raw": "https://{{host}}:9002/rest/v2/electronics/users/{{user}}/carts/{{cartguid}}/deliverymode?deliveryModeId=standard-gross",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"port": "9002",
					"path": [
						"rest",
						"v2",
						"electronics",
						"users",
						"{{user}}",
						"carts",
						"{{cartguid}}",
						"deliverymode"
					],
					"query": [
						{
							"key": "deliveryModeId",
							"value": "standard-gross"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "6. accPaymentDetail",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Authorization",
						"value": "{{trust_credential}}",
						"description": "trust_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_credential}}",
						"description": "client_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_customer}}",
						"description": "client_customer",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "{{client_manager}}",
						"description": "client_manager",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/json",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n  \"accountHolderName\": \"kate\",\n  \"billingAddress\": {\n    \"cellphone\": \"13444444444\",\n    \"companyName\": \"company\",\n    \"country\": {\n      \"isocode\": \"CN\",\n      \"name\": \"string\"\n    },\n    \"defaultAddress\": true,\n    \"district\": \"CN-12-1-1\",\n    \"email\": \"k.zheng@sap.com\",\n    \"firstName\": \"string\",\n    \"formattedAddress\": \"string\",\n    \"lastName\": \"string\",\n    \"line1\": \"string\",\n    \"line2\": \"string\",\n    \"phone\": \"12333333333\",\n    \"postalCode\": \"string\",\n    \"region\": {\n      \"countryIso\": \"CN\",\n      \"isocode\": \"CN-12\",\n      \"isocodeShort\": \"string\",\n      \"name\": \"string\"\n    },\n    \"shippingAddress\": true,\n    \"title\": \"string\",\n    \"titleCode\": \"mrs\",\n    \"town\": \"CN-12-1\",\n    \"visibleInAddressBook\": true\n  },\n  \"cardNumber\": \"1234567890987654\",\n  \"cardType\": {\n    \"code\": \"visa\",\n    \"name\": \"string\"\n  },\n  \"defaultPayment\": true,\n  \"expiryMonth\": \"12\",\n  \"expiryYear\": \"2022\"\n}"
				},
				"url": {
					"raw": "https://{{host}}:9002/rest/v2/electronics/users/{{user}}/carts/{{cartguid}}/paymentdetails",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"port": "9002",
					"path": [
						"rest",
						"v2",
						"electronics",
						"users",
						"{{user}}",
						"carts",
						"{{cartguid}}",
						"paymentdetails"
					]
				}
			},
			"response": []
		},
		{
			"name": "7. accPlaceOrder",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Authorization",
						"value": "{{trust_credential}}",
						"description": "trust_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_credential}}",
						"description": "client_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_customer}}",
						"description": "client_customer",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "{{client_manager}}",
						"description": "client_manager",
						"type": "text",
						"disabled": true
					}
				],
				"url": {
					"raw": "https://{{host}}:9002/rest/v2/electronics/users/{{user}}/orders?cartId={{cartguid}}&lang=en",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"port": "9002",
					"path": [
						"rest",
						"v2",
						"electronics",
						"users",
						"{{user}}",
						"orders"
					],
					"query": [
						{
							"key": "cartId",
							"value": "{{cartguid}}"
						},
						{
							"key": "lang",
							"value": "en"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "8. getOrder",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/json",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{trust_credential}}",
						"description": "trust_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_credential}}",
						"description": "client_credential",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Authorization",
						"value": "{{client_customer}}",
						"description": "client_customer",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "{{client_manager}}",
						"description": "client_manager",
						"type": "text",
						"disabled": true
					}
				],
				"url": {
					"raw": "https://{{host}}:9002/rest/v2/electronics/users/{{user}}/orders/00001003",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"port": "9002",
					"path": [
						"rest",
						"v2",
						"electronics",
						"users",
						"{{user}}",
						"orders",
						"00001003"
					]
				}
			},
			"response": []
		}
	],
	"protocolProfileBehavior": {}
}

要获取更多Jerry的原创文章,请关注公众号"汪子熙":