{
	"info": {
		"_postman_id": "e4c32661-a297-4e4a-a0fe-8a032dc7c537",
		"name": "Purchase/Sales",
		"description": "Collection for testing SmartAccounts API connection.\n\n---\n\n**Pending issues**\n\nRequest body containing line breaks will not work!",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "26345440"
	},
	"item": [
		{
			"name": "Sales – Clients",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							""
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "Content-Type",
						"value": "application/json; charset=UTF-8",
						"type": "text"
					}
				],
				"url": {
					"raw": "https://{{host}}/api/purchasesales/clients:get?timestamp={{moment}}&apikey={{apikey}}&signature={{signature}}",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"path": [
						"api",
						"purchasesales",
						"clients:get"
					],
					"query": [
						{
							"key": "timestamp",
							"value": "{{moment}}"
						},
						{
							"key": "apikey",
							"value": "{{apikey}}"
						},
						{
							"key": "signature",
							"value": "{{signature}}"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "Articles",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							""
						],
						"type": "text/javascript"
					}
				}
			],
			"protocolProfileBehavior": {
				"strictSSL": true,
				"followRedirects": false
			},
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "https://{{host}}/api/purchasesales/articles:get?timestamp={{moment}}&apikey={{apikey}}&signature={{signature}}",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"path": [
						"api",
						"purchasesales",
						"articles:get"
					],
					"query": [
						{
							"key": "timestamp",
							"value": "{{moment}}"
						},
						{
							"key": "apikey",
							"value": "{{apikey}}"
						},
						{
							"key": "signature",
							"value": "{{signature}}"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "Client Invoices",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							""
						],
						"type": "text/javascript"
					}
				}
			],
			"protocolProfileBehavior": {
				"strictSSL": true,
				"followRedirects": false
			},
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "https://{{host}}/api/purchasesales/clientinvoices:get?timestamp={{moment}}&apikey={{apikey}}&dateFrom=01.01.2023&signature={{signature}}",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"path": [
						"api",
						"purchasesales",
						"clientinvoices:get"
					],
					"query": [
						{
							"key": "timestamp",
							"value": "{{moment}}"
						},
						{
							"key": "apikey",
							"value": "{{apikey}}"
						},
						{
							"key": "dateFrom",
							"value": "01.01.2023"
						},
						{
							"key": "signature",
							"value": "{{signature}}"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "Sales – Client Invoices",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							""
						],
						"type": "text/javascript"
					}
				}
			],
			"protocolProfileBehavior": {
				"strictSSL": true,
				"followRedirects": false
			},
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"value": "application/json; charset=UTF-8",
						"type": "text"
					},
					{
						"key": "Content-Length",
						"value": "181",
						"type": "text",
						"disabled": true
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\"clientId\":\"<client_id_from_smartaccounts>\",\"date\":\"02.11.2023\", \"currency\":\"EUR\",\"rows\":[{\"code\":\"00010\",\"description\":\"Description\",\"price\":10,\"quantity\":10,\"vatPc\":\"20\"}]}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "https://{{host}}/api/purchasesales/clientinvoices:add?timestamp={{moment}}&apikey={{apikey}}&signature={{signature}}",
					"protocol": "https",
					"host": [
						"{{host}}"
					],
					"path": [
						"api",
						"purchasesales",
						"clientinvoices:add"
					],
					"query": [
						{
							"key": "timestamp",
							"value": "{{moment}}"
						},
						{
							"key": "apikey",
							"value": "{{apikey}}"
						},
						{
							"key": "signature",
							"value": "{{signature}}"
						}
					]
				}
			},
			"response": []
		}
	],
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					"const moment = require('moment');",
					"pm.collectionVariables.set(\"moment\", moment().format(\"DDMMyyyyHHmmss\"));",
					"",
					"const urlParam = pm.variables.replaceIn(pm.request.url.getQueryString());",
					"",
					"function urlParamAndBodyWithoutSignature() {",
					"    let url = urlParam.substring(0,urlParam.indexOf(\"signature\") - 1);",
					"    let body = pm.request.body.toString();",
					"    console.log (url + body);",
					"   return url + body;",
					"}",
					"",
					"function computeHashHex( key_hex) {",
					"   return CryptoJS.HmacSHA256(urlParamAndBodyWithoutSignature(), key_hex).toString(CryptoJS.enc.Hex);",
					"}",
					"",
					"pm.collectionVariables.set(\"signature\",  computeHashHex(pm.environment.get(\"privateKey\")));",
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		}
	],
	"variable": [
		{
			"key": "signature",
			"value": ""
		},
		{
			"key": "moment",
			"value": ""
		},
		{
			"key": "today",
			"value": ""
		}
	]
}