Hi list,
First of all, thanks for having me. I'm having trouble updating a metadata
record through the REST API and don't know where to start. I've posted an
issue at
https://gis.stackexchange.com/questions/371749/automated-updates-for-fields-in-a-metadata-record
but my understanding now is that I'll be probably better off asking in this
mailing list.
I've tried re-creating the solution from
https://sourceforge.net/p/geonetwork/mailman/message/36703820/ but it
doesn't work; there's no 'XSRF-TOKEN' in the cookie jar after the first
post request. I've tried doing a first dummy call that gets me this token,
but then I strike out with a 500 error message:
def gn_api_xml_push(xml_file_path: str) -> str:
gn_base_url = 'https://my_geonetwork <https://data.geodan.io>'
gn_api_url = gn_base_url + '/api/0.1/records'
# set up the session
session = requests.Session()
session.auth = ('user', 'pass')
# Log in
login_response = session.get(gn_base_url)
assert login_response.status_code == 200, f'Error authenticating with
server {gn_base_url}: response {login_response.status_code}'
session.post(gn_api_url) # Do a dummy post to get XSRF-TOKEN
# Do the record posting itself
headers = {
'Cache-Control': 'no-cache',
'Content-Type': 'application/x-www-form-urlencoded',
'X-XSRF-TOKEN': session.cookies.get_dict()['XSRF-TOKEN'],
'Accept': "application/json"
}
response = session.post(gn_api_url,
files= {'file': open(xml_file_path, 'rb')} ,
data= {'rejectIfInvalid': True} ,
headers=headers,
cookies=session.cookies.get_dict())
I'm also unsure on whether this will do it for us - will this update an
existing record with the contents of the XML? The XML I used by the way is
just a copy of the existing record - will this work? Or should I do a put
call to displace the contents, or a delete call to drop the record first?
Maybe the answer is somewhere in the archives of this mailing list, but
there's so much content to go through...
Kind regards and many thanks,
Rein van 't Veer
Geospatial Data Scientist