-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_subjects.json
150 lines (150 loc) · 4.37 KB
/
update_subjects.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{
"info": {
"_postman_id": "131aaa6f-b790-491a-8310-bffef39a37c0",
"name": "update_subject",
"description": "A demonstration collection that updates or adds a scope note to a subject record. The uri for the subject record to be edited must be supplied.\n\nYou must have an active ArchivesSpace session saved as an environment variable for this collection to work. Run create_aspace_session first to set this up.",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "subject_record",
"event": [
{
"listen": "test",
"script": {
"id": "aa7e69fb-dc30-4938-8af4-795a086cf4b6",
"exec": [
"var jsonObject = pm.response.json()\r",
"\r",
"//This saves the entire subject record so it can be updated in the next step\r",
"pm.environment.set (\"subject_body\", JSON.stringify(jsonObject))"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"id": "0498bce0-6085-4bc6-a4ec-f52238fa7c4d",
"exec": [
"//Spreadsheet search variable block: \r",
"//var sUri = pm.iterationData.get(\"URI\")\r",
"\r",
"//Testing uri block:\r",
"var sUri = \"/subjects/15238\"\r",
"\r",
"//A log to the console so you can see the uri that was passed:\r",
"console.log (\"@@@\" + sUri)\r",
"\r",
"//This sets the uri to be run:\r",
"pm.environment.set(\"subject_uri\", sUri)"
],
"type": "text/javascript"
}
}
],
"id": "d7f2904f-7348-49e5-a853-480f05aa06eb",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"description": "Archives Space session ID",
"key": "X-ArchivesSpace-Session",
"type": "text",
"value": "{{aspace_session}}"
}
],
"url": "{{aspace_base_url}}{{subject_uri}}"
},
"response": []
},
{
"name": "update_subject",
"event": [
{
"listen": "prerequest",
"script": {
"id": "50a082a8-c099-4f5f-993a-fb4262ddfc97",
"exec": [
"var su_body = JSON.parse(pm.environment.get(\"subject_body\"));\r",
"\r",
"//Add or update the scope note for the subject record.\r",
"//Testing block:\r",
"su_body.scope_note = \"New Scope Note\"\r",
"\r",
"//Spreadsheet update block:\r",
"//su_body.scope_note = pm.iterationData.get(\"New Scope Note\")\r",
"\r",
"//If you uncomment this line, it will log the entire accession record to the console. Useful for debugging\r",
"console.log (su_body)\r",
"\r",
"pm.variables.set(\"subject_body\", JSON.stringify(su_body));"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"id": "66e024f4-cd4e-4fff-85dc-72d0701d7e5b",
"exec": [
"//This gets the response from Postman that you see in the Response area after you hit send\r",
"var jsonObject = pm.response.json()\r",
"\r",
"//This tests whether the API returns a status code in the 200s, which means good (unlike 404 not found or things like that)\r",
"pm.test(\"Status code is 200\", function () {\r",
" pm.response.to.have.status(200);\r",
"});\r",
"\r",
"//This logs the uri and status returned by ArchivesSpace. If run as a GET, the status will be \"undefined\". A successful POST should return a status of \"Updated\"\r",
"console.log (\"@@@@\" + jsonObject.uri + \" \" + jsonObject.status)"
],
"type": "text/javascript"
}
}
],
"id": "4b845222-d4bd-4c58-a199-d89140ba9c24",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "POST",
"header": [
{
"description": "Archives Space session ID",
"key": "X-ArchivesSpace-Session",
"type": "text",
"value": "{{aspace_session}}"
}
],
"body": {
"mode": "raw",
"raw": "{{subject_body}}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{aspace_base_url}}{{subject_uri}}",
"host": [
"{{aspace_base_url}}{{subject_uri}}"
],
"query": [
{
"key": "",
"value": "",
"type": "text",
"disabled": true
}
]
}
},
"response": []
}
]
}