{
	"info": {
		"_postman_id": "a14c85fd-bb6b-4360-8e68-fab0e30ae012",
		"name": "Kravia 3rd party - Collection",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "10353541"
	},
	"item": [
		{
			"name": "Authentication",
			"item": [
				{
					"name": "Client credentials",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"var data = pm.response.json();\r",
									"pm.collectionVariables.set('token', data.access_token);"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [],
						"body": {
							"mode": "raw",
							"raw": "{\r\n  \"audience\": \"{{auth_audience}}\",\r\n  \"client_id\": \"{{auth_client_id}}\",\r\n  \"client_secret\": \"{{auth_client_secret}}\",\r\n  \"grant_type\": \"client_credentials\"\r\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{base_url}}/api/v2/auth/token",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"auth",
								"token"
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "Account details",
			"item": [
				{
					"name": "Account details",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/api/v2/company?withCreditor=false",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"company"
							],
							"query": [
								{
									"key": "withCreditor",
									"value": "false"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "Creditors",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/api/v2/creditor/list",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"creditor",
								"list"
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "Onboarding",
			"item": [
				{
					"name": "Init onboarding",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"var res = pm.response.json();\r",
									"pm.collectionVariables.set('onboarding-session-id', res.value.sessionId);\r",
									"\r",
									"var creditorData = res.value.creditorsData;\r",
									"creditorData.creditors[0].name =  '[TEST] name';\r",
									"creditorData.creditors[0].organizationNumber = '[TEST]000111222';\r",
									"creditorData.creditors[0].email = pm.collectionVariables.get('onboarding-user-email');\r",
									"creditorData.creditors[0].taxRegistered = true;\r",
									"creditorData.creditors[0].bankAccount = '34324144';\r",
									"\r",
									"pm.collectionVariables.set(\"onboarding-creditor-data\", JSON.stringify(creditorData));"
								],
								"type": "text/javascript"
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik1qVTJSVFV6TmtJelJrUkVRVEkzUmpjNE9EYzJOamd6UVRNeVJUazVOek5EUkRjek5rTXhOQSJ9.eyJodHRwczovL2tyYXZpYS5hcGkuY29tL3JvbGUiOiJBZG1pbiIsImh0dHBzOi8va3JhdmlhLmFwaS5jb20vZW1haWwiOiJrZXZjYWJhbGxlcm9AZ21haWwuY29tIiwiaHR0cHM6Ly9rcmF2aWEuYXBpLmNvbS9uYW1lIjoia2V2Y2FiYWxsZXJvQGdtYWlsLmNvbSIsImlzcyI6Imh0dHBzOi8va3JhdmlhLmV1LmF1dGgwLmNvbS8iLCJzdWIiOiJmWW1wc1R4Yno3cDF6ZzJyenZFVzRFY0tBeXF1eFNFSUBjbGllbnRzIiwiYXVkIjoiaHR0cHM6Ly9maW5jeWNsZWFwaS5rcmF2aWEubmV0IiwiaWF0IjoxNjYzMTAwNjU2LCJleHAiOjE2NjMxODcwNTYsImF6cCI6ImZZbXBzVHhiejdwMXpnMnJ6dkVXNEVjS0F5cXV4U0VJIiwic2NvcGUiOiJyZWFkOmZpbmRhdGEgY3JlYXRlOmZpbmRhdGEiLCJndHkiOiJjbGllbnQtY3JlZGVudGlhbHMifQ.N8Yi6_xOQLnh7g0f0C5pOsuBm5Ps8Ze_GmHCXtLch0fWx2G-XEASsR3KJ-rnNpvb_bb3rwT7INE48qs1vbqv-1YGzlf6JsLzxb6aPwuxxTzW6FRGwcJCLVUa7rrPxU1ARvumutwr3ulmSQUNzmaV1quX2Mh0y28n4DpnF7K8jbkC_O-qeiyoaBWju0EzV4ETfheqvJSzD_Wi26hNbdK88LurgkCE062NNcsJOugr4QANtM1O2HXFLmFcnXhhq2Aouyqhp7vc0uZeeA1mW-Uowy0sncxp7Q-NCuvzmAtkaJj2SJJzstBgIVZErUmc4uqxDdtM8bzjtsye85cdtSEtfg",
									"type": "string"
								}
							]
						},
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\r\n  \"accountingSystem\": 22\r\n}"
						},
						"url": {
							"raw": "{{base_url}}/api/v2.0/onboarding/init",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2.0",
								"onboarding",
								"init"
							]
						}
					},
					"response": []
				},
				{
					"name": "Activate onboarding",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"var res = pm.response.json();\r",
									"pm.collectionVariables.set('onboarding-creditor-id', res.value[0].id);"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\r\n        \"sessionId\": {{onboarding-session-id}},\r\n        \"creditorsData\": {{onboarding-creditor-data}}\r\n}"
						},
						"url": {
							"raw": "{{base_url}}/api/v2.0/onboarding/activate",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2.0",
								"onboarding",
								"activate"
							]
						}
					},
					"response": []
				},
				{
					"name": "Creditor invitation",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.collectionVariables.unset(\"onboarding-session-id\");\r",
									"pm.collectionVariables.unset(\"onboarding-creditor-data\");\r",
									"pm.collectionVariables.unset(\"onboarding-creditor-id\");"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json",
								"type": "text"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\r\n    \"email\": \"{{onboarding-user-email}}\",\r\n    \"name\": \"{{onboarding-user-email}}\"\r\n}"
						},
						"url": {
							"raw": "{{base_url}}/api/v2.0/creditor/{{onboarding-creditor-id}}/invite?termsVersion=latest",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2.0",
								"creditor",
								"{{onboarding-creditor-id}}",
								"invite"
							],
							"query": [
								{
									"key": "termsVersion",
									"value": "latest"
								}
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "Register Invoice",
			"item": [
				{
					"name": "Invoice",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									""
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "test",
							"script": {
								"exec": [
									"var data = pm.response.json();\r",
									"pm.collectionVariables.set('invoiceId', data.value.id);"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "POST",
						"header": [],
						"body": {
							"mode": "raw",
							"raw": "{\r\n    \"isPrivateIndividual\": \"true\",\r\n    \"debtorName\":\"John Doe\",\r\n    \"postalAddress\": \r\n    {        \r\n        \"addressAddressLine1\": \"Bond street\",\r\n        \"addressPostalCode\":\"0100\",\r\n        \"addressCity\":\"Oslo\"\r\n    },\r\n    \"invoiceNo\": 1,\r\n    \"invoiceDate\":\"2020-01-01\",\r\n    \"dueDate\":\"2020-02-01\",\r\n    \"originalAmount\":\"250\",\r\n    \"collectionSystemCreditorId\":\"508773\",\r\n    \"accountingInvoiceId\": \"1234\",\r\n    \"phoneNumber\": \"111111111\",\r\n    \"email\": \"kevin@kravia.ai\",\r\n    \"ssn\": null,\r\n    \"claimType\": \"CollectionCase\",\r\n    \"kid\": \"000100314425000204927\"\r\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{base_url}}/api/v2/invoice/register?startCollection=true",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"invoice",
								"register"
							],
							"query": [
								{
									"key": "startCollection",
									"value": "true"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "Invoice document",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "POST",
						"header": [
							{
								"key": "Content-Typ",
								"value": "multipart/form-data",
								"type": "text"
							}
						],
						"body": {
							"mode": "formdata",
							"formdata": [
								{
									"key": "file",
									"type": "file",
									"src": "/C:/Users/kevca/Desktop/sample.pdf"
								},
								{
									"key": "type",
									"value": "Invoice",
									"type": "text",
									"disabled": true
								}
							]
						},
						"url": {
							"raw": "{{base_url}}/api/v2/invoice/{{invoiceId}}/document?type=InvoiceAttachment",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"invoice",
								"{{invoiceId}}",
								"document"
							],
							"query": [
								{
									"key": "type",
									"value": "InvoiceAttachment"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "Payments",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "POST",
						"header": [],
						"body": {
							"mode": "raw",
							"raw": "[\r\n        {\r\n            \"date\": \"2019-12-23T00:00:00\",\r\n            \"amount\": 2148.00,\r\n            \"voucherNo\": 0,\r\n            \"accountingPaymentId\": \"457923460\",\r\n            \"description\": null,\r\n            \"createdFromOurSettlement\": false,\r\n            \"isWriteOff\": false,\r\n            \"createdFromVoucherId\": null,\r\n            \"createdFromImportId\": null,\r\n            \"invoices\": [\r\n                {\r\n                    \"invoiceId\": {{invoiceId}},\r\n                    \"amount\": 1671.0\r\n                }\r\n            ]\r\n        }\r\n    ]",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{base_url}}/api/v2/invoice/payments",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"invoice",
								"payments"
							]
						}
					},
					"response": []
				},
				{
					"name": "Credit note",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "POST",
						"header": [],
						"body": {
							"mode": "raw",
							"raw": "{\r\n  \"date\": \"2021-09-22T00:00:00\",\r\n  \"accountingPaymentId\": \"7\",\r\n  \"description\": \"®fakturanr. 4 - 100000 - Kevin Caballero\",\r\n  \"amount\": 6250.0,\r\n  \"invoices\": [\r\n    {\r\n        \"invoiceId\": {{invoiceId}},\r\n        \"amount\": -6250.0\r\n    }\r\n  ]\r\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{base-url}}/api/v2/invoice/creditnote",
							"host": [
								"{{base-url}}"
							],
							"path": [
								"api",
								"v2",
								"invoice",
								"creditnote"
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "Search invoices",
			"item": [
				{
					"name": "Search Invoices",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/api/v2/invoice/search?top=20&skip=0",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"invoice",
								"search"
							],
							"query": [
								{
									"key": "top",
									"value": "20"
								},
								{
									"key": "skip",
									"value": "0"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "Delta invoice updates",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/api/v2/invoice/search?top=20&skip=0&byAscending=true&orderBy=ByLastUpdatedTime&lastUpdatedTime=2021-10-26T20:00:36.2760934",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"invoice",
								"search"
							],
							"query": [
								{
									"key": "top",
									"value": "20"
								},
								{
									"key": "skip",
									"value": "0"
								},
								{
									"key": "byAscending",
									"value": "true"
								},
								{
									"key": "orderBy",
									"value": "ByLastUpdatedTime"
								},
								{
									"key": "lastUpdatedTime",
									"value": "2021-10-26T20:00:36.2760934"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "Invoice By Id",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/api/v2/invoice/{{invoiceId}}/details",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"invoice",
								"{{invoiceId}}",
								"details"
							],
							"query": [
								{
									"key": "liveStatusFromCollection",
									"value": "false",
									"disabled": true
								}
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "Debtors",
			"item": [
				{
					"name": "Search debtors",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"var data = pm.response.json();\r",
									"pm.collectionVariables.set('debtorId', data.value.value[0].id);"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/api/v2/debtor?top=20&skip=0",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"debtor"
							],
							"query": [
								{
									"key": "top",
									"value": "20"
								},
								{
									"key": "skip",
									"value": "0"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "Debtor By Id",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/api/v2/debtor/{{debtorId}}?includeInvoices=true",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"debtor",
								"{{debtorId}}"
							],
							"query": [
								{
									"key": "includeInvoices",
									"value": "true"
								}
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "Creditors",
			"item": [
				{
					"name": "Search creditors",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"var data = pm.response.json();\r",
									"pm.collectionVariables.set('creditorId', data.value.value[0].id);"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/api/v2/creditor/list?top=20&skip=0",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"creditor",
								"list"
							],
							"query": [
								{
									"key": "top",
									"value": "20"
								},
								{
									"key": "skip",
									"value": "0"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "Creditor By Id",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"var data = pm.response.json();\r",
									"pm.collectionVariables.set('debtorId', data.value.value[0].id);"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/api/v2/creditor/{{creditorId}}/settings",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"creditor",
								"{{creditorId}}",
								"settings"
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "Settlements",
			"item": [
				{
					"name": "Settlement list",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"var data = pm.response.json();\r",
									"pm.collectionVariables.set('settlementId', data.value.value[0].paymentId);"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{base_url}}/api/v2/settlements?top=200&skip=0",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"settlements"
							],
							"query": [
								{
									"key": "top",
									"value": "200"
								},
								{
									"key": "skip",
									"value": "0"
								}
							]
						}
					},
					"response": []
				},
				{
					"name": "Settlement By Id",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json",
								"type": "text"
							}
						],
						"url": {
							"raw": "{{base_url}}/api/v2/settlements/{{settlementId}}?includeInvoices=true&splitByInvoice=true",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"v2",
								"settlements",
								"{{settlementId}}"
							],
							"query": [
								{
									"key": "creditorsId",
									"value": "113",
									"disabled": true
								},
								{
									"key": "includeInvoices",
									"value": "true"
								},
								{
									"key": "splitByInvoice",
									"value": "true"
								}
							]
						}
					},
					"response": []
				}
			]
		}
	],
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		}
	],
	"variable": [
		{
			"key": "base_url",
			"value": "https://api-stage.kravia.ai"
		},
		{
			"key": "auth_audience",
			"value": "https://api-staging.kraviainkasso.no"
		},
		{
			"key": "auth_client_id",
			"value": "TO_BE_DEFINED"
		},
		{
			"key": "auth_client_secret",
			"value": "TO_BE_DEFINED"
		}
	]
}