|
343 | 343 | " if class_id:\n",
|
344 | 344 | " payload['o:resource_class'] = self.format_resource_id(class_id, 'resource_classes')\n",
|
345 | 345 | " if item_set_id:\n",
|
346 |
| - " payload['o:item_set'] = self.format_resource_id(template_id, 'item_sets')\n", |
| 346 | + " payload['o:item_set'] = self.format_resource_id(item_set_id, 'item_sets')\n", |
347 | 347 | " if media_files:\n",
|
348 | 348 | " files = self.add_media_to_payload(payload, media_files)\n",
|
349 | 349 | " response = self.s.post(f'{self.api_url}/items', files=files, params=self.params)\n",
|
|
1306 | 1306 | ")"
|
1307 | 1307 | ]
|
1308 | 1308 | },
|
1309 |
| - { |
1310 |
| - "cell_type": "code", |
1311 |
| - "execution_count": null, |
1312 |
| - "metadata": {}, |
1313 |
| - "outputs": [], |
1314 |
| - "source": [ |
1315 |
| - "template_payload = omeka.prepare_template_payload('templates/Person.json')" |
1316 |
| - ] |
1317 |
| - }, |
1318 |
| - { |
1319 |
| - "cell_type": "code", |
1320 |
| - "execution_count": null, |
1321 |
| - "metadata": {}, |
1322 |
| - "outputs": [ |
1323 |
| - { |
1324 |
| - "data": { |
1325 |
| - "text/plain": [ |
1326 |
| - "{'@context': 'https://timsherratt.org/collections/api-context',\n", |
1327 |
| - " '@id': 'https://timsherratt.org/collections/api/resource_templates/9',\n", |
1328 |
| - " '@type': 'o:ResourceTemplate',\n", |
1329 |
| - " 'o:id': 9,\n", |
1330 |
| - " 'o:label': 'Person',\n", |
1331 |
| - " 'o:owner': {'@id': 'https://timsherratt.org/collections/api/users/1',\n", |
1332 |
| - " 'o:id': 1},\n", |
1333 |
| - " 'o:resource_class': {'@id': 'https://timsherratt.org/collections/api/resource_classes/492',\n", |
1334 |
| - " 'o:id': 492},\n", |
1335 |
| - " 'o:title_property': {'@id': 'https://timsherratt.org/collections/api/properties/1116',\n", |
1336 |
| - " 'o:id': 1116},\n", |
1337 |
| - " 'o:description_property': {'@id': 'https://timsherratt.org/collections/api/properties/528',\n", |
1338 |
| - " 'o:id': 528},\n", |
1339 |
| - " 'o:resource_template_property': [{'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1116',\n", |
1340 |
| - " 'o:id': 1116},\n", |
1341 |
| - " 'o:alternate_label': None,\n", |
1342 |
| - " 'o:alternate_comment': None,\n", |
1343 |
| - " 'o:data_type': ['literal'],\n", |
1344 |
| - " 'o:is_required': True,\n", |
1345 |
| - " 'o:is_private': False},\n", |
1346 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1199',\n", |
1347 |
| - " 'o:id': 1199},\n", |
1348 |
| - " 'o:alternate_label': None,\n", |
1349 |
| - " 'o:alternate_comment': None,\n", |
1350 |
| - " 'o:data_type': ['uri'],\n", |
1351 |
| - " 'o:is_required': False,\n", |
1352 |
| - " 'o:is_private': False},\n", |
1353 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/528',\n", |
1354 |
| - " 'o:id': 528},\n", |
1355 |
| - " 'o:alternate_label': None,\n", |
1356 |
| - " 'o:alternate_comment': None,\n", |
1357 |
| - " 'o:data_type': ['literal'],\n", |
1358 |
| - " 'o:is_required': False,\n", |
1359 |
| - " 'o:is_private': False},\n", |
1360 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/417',\n", |
1361 |
| - " 'o:id': 417},\n", |
1362 |
| - " 'o:alternate_label': None,\n", |
1363 |
| - " 'o:alternate_comment': None,\n", |
1364 |
| - " 'o:data_type': [],\n", |
1365 |
| - " 'o:is_required': False,\n", |
1366 |
| - " 'o:is_private': False},\n", |
1367 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1144',\n", |
1368 |
| - " 'o:id': 1144},\n", |
1369 |
| - " 'o:alternate_label': None,\n", |
1370 |
| - " 'o:alternate_comment': None,\n", |
1371 |
| - " 'o:data_type': [],\n", |
1372 |
| - " 'o:is_required': False,\n", |
1373 |
| - " 'o:is_private': False},\n", |
1374 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/282',\n", |
1375 |
| - " 'o:id': 282},\n", |
1376 |
| - " 'o:alternate_label': None,\n", |
1377 |
| - " 'o:alternate_comment': None,\n", |
1378 |
| - " 'o:data_type': ['literal'],\n", |
1379 |
| - " 'o:is_required': False,\n", |
1380 |
| - " 'o:is_private': False},\n", |
1381 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1357',\n", |
1382 |
| - " 'o:id': 1357},\n", |
1383 |
| - " 'o:alternate_label': None,\n", |
1384 |
| - " 'o:alternate_comment': None,\n", |
1385 |
| - " 'o:data_type': ['numeric:timestamp', 'literal'],\n", |
1386 |
| - " 'o:is_required': False,\n", |
1387 |
| - " 'o:is_private': False},\n", |
1388 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1464',\n", |
1389 |
| - " 'o:id': 1464},\n", |
1390 |
| - " 'o:alternate_label': None,\n", |
1391 |
| - " 'o:alternate_comment': None,\n", |
1392 |
| - " 'o:data_type': ['customvocab:1'],\n", |
1393 |
| - " 'o:is_required': False,\n", |
1394 |
| - " 'o:is_private': False},\n", |
1395 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1042',\n", |
1396 |
| - " 'o:id': 1042},\n", |
1397 |
| - " 'o:alternate_label': None,\n", |
1398 |
| - " 'o:alternate_comment': 'Place|Heritage place|State|Country',\n", |
1399 |
| - " 'o:data_type': ['resource:item', 'uri', 'literal'],\n", |
1400 |
| - " 'o:is_required': False,\n", |
1401 |
| - " 'o:is_private': False},\n", |
1402 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/708',\n", |
1403 |
| - " 'o:id': 708},\n", |
1404 |
| - " 'o:alternate_label': None,\n", |
1405 |
| - " 'o:alternate_comment': None,\n", |
1406 |
| - " 'o:data_type': ['numeric:timestamp', 'literal'],\n", |
1407 |
| - " 'o:is_required': False,\n", |
1408 |
| - " 'o:is_private': False},\n", |
1409 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1468',\n", |
1410 |
| - " 'o:id': 1468},\n", |
1411 |
| - " 'o:alternate_label': None,\n", |
1412 |
| - " 'o:alternate_comment': None,\n", |
1413 |
| - " 'o:data_type': ['customvocab:1'],\n", |
1414 |
| - " 'o:is_required': False,\n", |
1415 |
| - " 'o:is_private': False},\n", |
1416 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/766',\n", |
1417 |
| - " 'o:id': 766},\n", |
1418 |
| - " 'o:alternate_label': None,\n", |
1419 |
| - " 'o:alternate_comment': 'Place|Heritage place|State|Country',\n", |
1420 |
| - " 'o:data_type': ['resource:item', 'uri', 'literal'],\n", |
1421 |
| - " 'o:is_required': False,\n", |
1422 |
| - " 'o:is_private': False},\n", |
1423 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/922',\n", |
1424 |
| - " 'o:id': 922},\n", |
1425 |
| - " 'o:alternate_label': None,\n", |
1426 |
| - " 'o:alternate_comment': 'Person',\n", |
1427 |
| - " 'o:data_type': ['resource:item', 'uri'],\n", |
1428 |
| - " 'o:is_required': False,\n", |
1429 |
| - " 'o:is_private': False},\n", |
1430 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/265',\n", |
1431 |
| - " 'o:id': 265},\n", |
1432 |
| - " 'o:alternate_label': None,\n", |
1433 |
| - " 'o:alternate_comment': 'Person',\n", |
1434 |
| - " 'o:data_type': ['resource:item', 'uri'],\n", |
1435 |
| - " 'o:is_required': False,\n", |
1436 |
| - " 'o:is_private': False},\n", |
1437 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1209',\n", |
1438 |
| - " 'o:id': 1209},\n", |
1439 |
| - " 'o:alternate_label': None,\n", |
1440 |
| - " 'o:alternate_comment': None,\n", |
1441 |
| - " 'o:data_type': [],\n", |
1442 |
| - " 'o:is_required': False,\n", |
1443 |
| - " 'o:is_private': False},\n", |
1444 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1384',\n", |
1445 |
| - " 'o:id': 1384},\n", |
1446 |
| - " 'o:alternate_label': None,\n", |
1447 |
| - " 'o:alternate_comment': 'Person',\n", |
1448 |
| - " 'o:data_type': ['resource:item', 'uri'],\n", |
1449 |
| - " 'o:is_required': False,\n", |
1450 |
| - " 'o:is_private': False},\n", |
1451 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1358',\n", |
1452 |
| - " 'o:id': 1358},\n", |
1453 |
| - " 'o:alternate_label': None,\n", |
1454 |
| - " 'o:alternate_comment': 'Person',\n", |
1455 |
| - " 'o:data_type': ['resource:item', 'uri'],\n", |
1456 |
| - " 'o:is_required': False,\n", |
1457 |
| - " 'o:is_private': False},\n", |
1458 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/870',\n", |
1459 |
| - " 'o:id': 870},\n", |
1460 |
| - " 'o:alternate_label': None,\n", |
1461 |
| - " 'o:alternate_comment': 'Person',\n", |
1462 |
| - " 'o:data_type': ['resource:item', 'uri'],\n", |
1463 |
| - " 'o:is_required': False,\n", |
1464 |
| - " 'o:is_private': False},\n", |
1465 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/981',\n", |
1466 |
| - " 'o:id': 981},\n", |
1467 |
| - " 'o:alternate_label': None,\n", |
1468 |
| - " 'o:alternate_comment': 'Organisation',\n", |
1469 |
| - " 'o:data_type': ['resource:item', 'uri', 'literal'],\n", |
1470 |
| - " 'o:is_required': False,\n", |
1471 |
| - " 'o:is_private': False},\n", |
1472 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1253',\n", |
1473 |
| - " 'o:id': 1253},\n", |
1474 |
| - " 'o:alternate_label': None,\n", |
1475 |
| - " 'o:alternate_comment': 'Organisation',\n", |
1476 |
| - " 'o:data_type': ['resource:item', 'uri', 'literal'],\n", |
1477 |
| - " 'o:is_required': False,\n", |
1478 |
| - " 'o:is_private': False},\n", |
1479 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/804',\n", |
1480 |
| - " 'o:id': 804},\n", |
1481 |
| - " 'o:alternate_label': None,\n", |
1482 |
| - " 'o:alternate_comment': 'Event',\n", |
1483 |
| - " 'o:data_type': ['resource:item'],\n", |
1484 |
| - " 'o:is_required': False,\n", |
1485 |
| - " 'o:is_private': False},\n", |
1486 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/588',\n", |
1487 |
| - " 'o:id': 588},\n", |
1488 |
| - " 'o:alternate_label': None,\n", |
1489 |
| - " 'o:alternate_comment': 'Vehicle',\n", |
1490 |
| - " 'o:data_type': ['resource:item'],\n", |
1491 |
| - " 'o:is_required': False,\n", |
1492 |
| - " 'o:is_private': False},\n", |
1493 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1391',\n", |
1494 |
| - " 'o:id': 1391},\n", |
1495 |
| - " 'o:alternate_label': None,\n", |
1496 |
| - " 'o:alternate_comment': 'Book|Book chapter|Article|Newspaper article|Archival document|Archival file|Photograph|Art work',\n", |
1497 |
| - " 'o:data_type': ['resource:item'],\n", |
1498 |
| - " 'o:is_required': False,\n", |
1499 |
| - " 'o:is_private': False},\n", |
1500 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/742',\n", |
1501 |
| - " 'o:id': 742},\n", |
1502 |
| - " 'o:alternate_label': None,\n", |
1503 |
| - " 'o:alternate_comment': None,\n", |
1504 |
| - " 'o:data_type': ['uri'],\n", |
1505 |
| - " 'o:is_required': False,\n", |
1506 |
| - " 'o:is_private': False},\n", |
1507 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/393',\n", |
1508 |
| - " 'o:id': 393},\n", |
1509 |
| - " 'o:alternate_label': None,\n", |
1510 |
| - " 'o:alternate_comment': None,\n", |
1511 |
| - " 'o:data_type': ['uri'],\n", |
1512 |
| - " 'o:is_required': False,\n", |
1513 |
| - " 'o:is_private': False},\n", |
1514 |
| - " {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/246',\n", |
1515 |
| - " 'o:id': 246},\n", |
1516 |
| - " 'o:alternate_label': None,\n", |
1517 |
| - " 'o:alternate_comment': None,\n", |
1518 |
| - " 'o:data_type': ['uri'],\n", |
1519 |
| - " 'o:is_required': False,\n", |
1520 |
| - " 'o:is_private': False}]}" |
1521 |
| - ] |
1522 |
| - }, |
1523 |
| - "execution_count": null, |
1524 |
| - "metadata": {}, |
1525 |
| - "output_type": "execute_result" |
1526 |
| - } |
1527 |
| - ], |
1528 |
| - "source": [ |
1529 |
| - "omeka_auth.upload_template('templates/Person.json')" |
1530 |
| - ] |
1531 |
| - }, |
1532 | 1309 | {
|
1533 | 1310 | "cell_type": "markdown",
|
1534 | 1311 | "metadata": {},
|
|
1891 | 1668 | "assert test_item['dcterms:title'][0]['value'] == new_item['dcterms:title'][0]['@value']"
|
1892 | 1669 | ]
|
1893 | 1670 | },
|
| 1671 | + { |
| 1672 | + "cell_type": "markdown", |
| 1673 | + "metadata": {}, |
| 1674 | + "source": [ |
| 1675 | + "You can also add an item to an existing item set by supplying the `item_set_id` parameter." |
| 1676 | + ] |
| 1677 | + }, |
| 1678 | + { |
| 1679 | + "cell_type": "code", |
| 1680 | + "execution_count": null, |
| 1681 | + "metadata": {}, |
| 1682 | + "outputs": [], |
| 1683 | + "source": [ |
| 1684 | + "# Get a random item set id\n", |
| 1685 | + "random_item_set = random.choice(omeka_auth.get_resources('item_sets')['results'])\n", |
| 1686 | + "item_set_id = random_item_set['o:id']\n", |
| 1687 | + "\n", |
| 1688 | + "# Create a new item using the item set id\n", |
| 1689 | + "new_item_in_item_set = new_item = omeka_auth.add_item(payload, item_set_id=item_set_id)\n", |
| 1690 | + "\n", |
| 1691 | + "# Check that the ids match\n", |
| 1692 | + "assert new_item_in_item_set['o:item_set'][0]['o:id'] == item_set_id" |
| 1693 | + ] |
| 1694 | + }, |
1894 | 1695 | {
|
1895 | 1696 | "cell_type": "markdown",
|
1896 | 1697 | "metadata": {},
|
|
2690 | 2491 | "cell_type": "markdown",
|
2691 | 2492 | "metadata": {},
|
2692 | 2493 | "source": [
|
2693 |
| - "In the example below I'm going to manually step through the process of adding a new item to Omeka using the API in order to demonstrate the methods available. But of course the point of using the API is to automate such processes -- joining together the individual steps so they can be embedded into your own systems or workflows.\n", |
| 2494 | + "In the example below I'm going to manually step through the process of adding a new item to Omeka using the API in order to demonstrate the methods available. But of course the point of using the API is to automate such processes -- joining together the individual steps so they can be embedded into your own systems or workflows. For a more detailed example that uploads Trove newspaper articles from a variety of sources, including Trove searches, Trove lists, and Zotero libraries, see the [GLAM Workbench](https://glam-workbench.net/trove-newspapers/#upload-trove-newspaper-articles-to-omeka-s).\n", |
2694 | 2495 | "\n",
|
2695 |
| - "Let's suppose we want to add this newspaper article in Trove to our Omeka instance. To take best advantage of Omeka's linked data infrastructure, we'll actually create two resources -- one for the article, and one for the newspaper it was published in.\n", |
| 2496 | + "Let's suppose we want to add [this newspaper article](http://nla.gov.au/nla.news-article226799674) in Trove to our Omeka instance. To take best advantage of Omeka's linked data infrastructure, we'll actually create two resources -- one for the article, and one for the newspaper it was published in.\n", |
2696 | 2497 | "\n",
|
2697 | 2498 | "I've already created templates labelled 'Newspaper' and 'Newspaper article'.\n",
|
2698 | 2499 | "\n",
|
|
0 commit comments