From d889aba388f11bbba3e465f7703f68a6dd94e99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Prunayre?= Date: Mon, 9 Dec 2024 12:01:00 +0100 Subject: [PATCH] Black formatting and fix missing / --- docs/manual/docs/api/the-geonetwork-api.md | 42 ++++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/docs/manual/docs/api/the-geonetwork-api.md b/docs/manual/docs/api/the-geonetwork-api.md index 16a998b907b..ea421cbe9b3 100644 --- a/docs/manual/docs/api/the-geonetwork-api.md +++ b/docs/manual/docs/api/the-geonetwork-api.md @@ -430,13 +430,13 @@ This is an example of how to use requests in python to authenticate to the API a import requests # Set up your username and password: -username = 'username' -password = 'password' +username = "username" +password = "password" # Set up your server and the authentication URL: server = "http://localhost:8080" -authenticate_url = server + '/geonetwork/srv/api/me' +authenticate_url = server + "/geonetwork/srv/api/me" session = requests.Session() session.auth = (username, password) @@ -445,38 +445,42 @@ response = session.get(authenticate_url) # Extract XRSF token xsrf_token = response.cookies.get("XSRF-TOKEN") if xsrf_token: - print("The XSRF Token is:", xsrf_token) + print("The XSRF Token is:", xsrf_token) else: - print("Unable to find the XSRF token") + print("Unable to find the XSRF token") # This example will add an online resource to a specified UUID using the http://localhost:8080/geonetwork/srv/api/records/batchediting endpoint # Set header for connection headers = { - 'Accept': 'application/json', - 'X-XSRF-TOKEN': xsrf_token, - 'JSESSION_ID': response.cookies.get("JSESSIONID") + "Accept": "application/json", + "X-XSRF-TOKEN": xsrf_token, + "JSESSION_ID": response.cookies.get("JSESSIONID"), } # Set the parameters params = { - 'uuids': 'the uuid to be updated', - 'bucket': 'bucketname', - 'updateDateStamp': 'true', + "uuids": "the uuid to be updated", + "bucket": "bucketname", + "updateDateStamp": "true", } # Set the JSON data: note that the value must have one of , , or -json_data = [{'condition': '', -'value': 'https://localhostWWW:LINK-1.0-http--linkThe Title of the URLThe description of the resource', -'xpath': '/gmd:MD_Metadata/gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions', -}, +json_data = [ + { + "condition": "", + "value": 'https://localhostWWW:LINK-1.0-http--linkThe Title of the URLThe description of the resource', + "xpath": "/gmd:MD_Metadata/gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions", + }, ] # Send a put request to the endpoint -response = session.put(server + 'geonetwork/srv/api/records/batchediting', -params=params, -headers=headers, -json=json_data, +response = session.put( + server + "/geonetwork/srv/api/records/batchediting", + params=params, + headers=headers, + json=json_data, ) print(response.text) + ```