{
	"info": {
		"_postman_id": "9655e08b-cb3c-419f-b4ac-49a3e9ef8684",
		"name": "RestAPI Demo",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Receive access token",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							""
						],
						"type": "text/javascript"
					}
				},
				{
					"listen": "test",
					"script": {
						"exec": [
							"pm.test(\"Status code is 200\", function () {",
							"    pm.response.to.have.status(200);",
							"});",
							"",
							"var jsonData = JSON.parse(responseBody);",
							"",
							"pm.test(\"There is access_token in response\", function () {",
							"    pm.expect(jsonData).to.have.property(\"access_token\");",
							"});",
							"",
							"postman.setEnvironmentVariable(\"access_token\", jsonData.access_token);"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"auth": {
					"type": "basic",
					"basic": [
						{
							"key": "password",
							"value": "{{client_secret}}",
							"type": "string"
						},
						{
							"key": "username",
							"value": "{{client_id}}",
							"type": "string"
						}
					]
				},
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"value": "application/x-www-form-urlencoded"
					}
				],
				"body": {
					"mode": "urlencoded",
					"urlencoded": [
						{
							"key": "grant_type",
							"value": "client_credentials",
							"description": "should not be changed",
							"type": "text"
						},
						{
							"key": "audience",
							"value": "{{audience}}",
							"description": "string containing popapi endpoints user wants to access",
							"type": "text"
						},
						{
							"key": "scope",
							"value": "{{scope}}",
							"description": "environment id, should be taken from client credentials on Portal",
							"type": "text"
						}
					]
				},
				"url": {
					"raw": "https://{{hydra_endpoint}}/oauth2/token",
					"protocol": "https",
					"host": [
						"{{hydra_endpoint}}"
					],
					"path": [
						"oauth2",
						"token"
					]
				},
				"description": "Get access token for popapi"
			},
			"response": []
		},
		{
			"name": "Create a record",
			"request": {
				"auth": {
					"type": "bearer",
					"bearer": [
						{
							"key": "token",
							"value": "{{access_token}}",
							"type": "string"
						}
					]
				},
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/json",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"country\": \"ae\", \n    \"record_key\": \"primaryKey\", \n    \"body\": \"string body may be long\",\n    \"range_key1\": 120,\n    \"key2\": \"string search key\"\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{DEMO_URL}}/api/records",
					"host": [
						"{{DEMO_URL}}"
					],
					"path": [
						"api",
						"records"
					]
				},
				"description": "Creates a single record"
			},
			"response": []
		},
		{
			"name": "Create batch",
			"request": {
				"auth": {
					"type": "bearer",
					"bearer": [
						{
							"key": "token",
							"value": "{{access_token}}",
							"type": "string"
						}
					]
				},
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"type": "text",
						"value": "application/json"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"country\": \"ae\",\n    \"records\": [\n        {\n            \"record_key\": \"primaryKey\",\n            \"body\": \"string body may be long\",\n            \"range_key1\": 120,\n            \"key2\": \"string search key\"\n        },\n        {\n            \"record_key\": \"primaryKey2\",\n            \"body\": \"another record body\",\n            \"range_key1\": 30,\n            \"key3\": \"here key3 is used (up to key 10)\"\n        }\n    ]\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{DEMO_URL}}/api/records/batch",
					"host": [
						"{{DEMO_URL}}"
					],
					"path": [
						"api",
						"records",
						"batch"
					]
				},
				"description": "Create a batch of records"
			},
			"response": []
		},
		{
			"name": "Find records",
			"request": {
				"auth": {
					"type": "bearer",
					"bearer": [
						{
							"key": "token",
							"value": "{{access_token}}",
							"type": "string"
						}
					]
				},
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/json",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"country\": \"ae\",\n    \"filter\": {\n        \"record_key\": [\n            \"any\", \"of\", \"these\", \"primaryKey\"\n        ],\n        \"range_key1\": {\"$gt\": 90},\n        \"key2\": \"string search key\"\n    },\n    \"options\": {\n        \"limit\": 10,\n        \"offset\": 0\n    }\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{DEMO_URL}}/api/records/find",
					"host": [
						"{{DEMO_URL}}"
					],
					"path": [
						"api",
						"records",
						"find"
					]
				},
				"description": "Find records. Filters are supported.\nrange_key(s) are numeric and comparison is available ($gt, $gte, $lt, $lte)."
			},
			"response": []
		},
		{
			"name": "Delete a record",
			"request": {
				"auth": {
					"type": "bearer",
					"bearer": [
						{
							"key": "token",
							"value": "{{access_token}}",
							"type": "string"
						}
					]
				},
				"method": "DELETE",
				"header": [],
				"url": {
					"raw": "{{DEMO_URL}}/api/records/ae/:recordKey",
					"host": [
						"{{DEMO_URL}}"
					],
					"path": [
						"api",
						"records",
						"ae",
						":recordKey"
					],
					"variable": [
						{
							"key": "recordKey",
							"value": "primaryKey"
						}
					]
				},
				"description": "Delete a single record"
			},
			"response": []
		},
		{
			"name": "Attach file",
			"request": {
				"auth": {
					"type": "bearer",
					"bearer": [
						{
							"key": "token",
							"value": "{{access_token}}",
							"type": "string"
						}
					]
				},
				"method": "POST",
				"header": [],
				"body": {
					"mode": "formdata",
					"formdata": [
						{
							"key": "file",
							"type": "file",
							"src": "/Users/vladimir/Downloads/Side1.crt"
						}
					]
				},
				"url": {
					"raw": "{{DEMO_URL}}/api/records/ae/:recordKey/files",
					"host": [
						"{{DEMO_URL}}"
					],
					"path": [
						"api",
						"records",
						"ae",
						":recordKey",
						"files"
					],
					"variable": [
						{
							"key": "recordKey",
							"value": "primaryKey"
						}
					]
				},
				"description": "Attach a file to an existing record"
			},
			"response": []
		},
		{
			"name": "Get attached file",
			"request": {
				"auth": {
					"type": "bearer",
					"bearer": [
						{
							"key": "token",
							"value": "{{access_token}}",
							"type": "string"
						}
					]
				},
				"method": "GET",
				"header": [],
				"url": {
					"raw": "{{DEMO_URL}}/api/records/ae/:recordKey/files/:fileId",
					"host": [
						"{{DEMO_URL}}"
					],
					"path": [
						"api",
						"records",
						"ae",
						":recordKey",
						"files",
						":fileId"
					],
					"variable": [
						{
							"key": "recordKey",
							"value": "primaryKey"
						},
						{
							"key": "fileId",
							"value": "627cdac2-e60f-412a-a285-468a23e0cd76"
						}
					]
				},
				"description": "Get attached file"
			},
			"response": []
		},
		{
			"name": "Delete attached file",
			"request": {
				"auth": {
					"type": "bearer",
					"bearer": [
						{
							"key": "token",
							"value": "{{access_token}}",
							"type": "string"
						}
					]
				},
				"method": "DELETE",
				"header": [],
				"url": {
					"raw": "{{DEMO_URL}}/api/records/ae/:key/files/:fileId",
					"host": [
						"{{DEMO_URL}}"
					],
					"path": [
						"api",
						"records",
						"ae",
						":key",
						"files",
						":fileId"
					],
					"variable": [
						{
							"key": "key",
							"value": "primaryKey"
						},
						{
							"key": "fileId",
							"value": "627cdac2-e60f-412a-a285-468a23e0cd76"
						}
					]
				},
				"description": "Delete attached file"
			},
			"response": []
		}
	]
}