-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Figure out a way to get a list of fields for a content type via REST #6
Comments
Unfortunately,
JSON::API also provides a way to
Can't find any documentation though. |
JSON::API to the rescue:
will return one node of the islandora_object type, with all fields listed and populated. Doesn't give you the field type or UUID, though. |
JSON::API allows fetching of field configuration by field UUID:
So, if we can get field UUIDs from content types, we can introspect a node's fields prior to generating requests. Only missing piece is to get the field UUIDs on a node. |
#!/usr/bin/env python3
import os
import sys
import json
import requests
fields_url = 'http://admin:islandora@localhost:8000/jsonapi/field_config/field_config'
headers = {'Content-Type': 'application/json'}
response = requests.get(fields_url, auth=('admin', 'islandora'), headers=headers)
field_config = json.loads(response.text)
field_types = {}
for item in field_config['data']:
field_name = item['attributes']['field_name']
field_types[field_name] = item['attributes']['field_type']
print(field_types) gets us a dictionary like this: {
'body': 'text_with_summary',
'comment_body': 'text_long',
'field_access_terms': 'entity_reference',
'field_file_size': 'integer',
'field_media_audio_file': 'file',
'field_media_of': 'entity_reference',
'field_media_use': 'entity_reference',
'field_mime_type': 'string',
'field_media_file': 'file',
'field_height': 'integer',
'field_media_image': 'image',
'field_width': 'integer',
'field_media_oembed_video': 'string',
'field_media_video_file': 'file',
'comment': 'comment',
'field_image': 'image',
'field_tags': 'entity_reference',
'field_alternative_title': 'string',
'field_description': 'string_long',
'field_display_hints': 'entity_reference',
'field_edtf_date': 'edtf',
'field_edtf_date_created': 'edtf',
'field_edtf_date_issued': 'edtf',
'field_extent': 'string',
'field_identifier': 'string',
'field_linked_agent': 'typed_relation',
'field_member_of': 'entity_reference',
'field_model': 'entity_reference',
'field_pid': 'string',
'field_resource_type': 'entity_reference',
'field_rights': 'string',
'field_subject': 'entity_reference'
} |
A glitch. Neither |
|
Resolved with 3e95222. |
If we can inspect the fields that a content type has configured, we can validate that the columns in the input file match machine field names, and we can also dynamically create requests for string, taxo term, and linked references.
The text was updated successfully, but these errors were encountered: