Skip to content

Commit

Permalink
Black formatting and fix missing /
Browse files Browse the repository at this point in the history
  • Loading branch information
fxprunayre authored Dec 9, 2024
1 parent 9e70822 commit 551f1ab
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions docs/manual/docs/api/the-geonetwork-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 <gn_add>, <gn_create>, <gn_replace> or <gn_delete>
json_data = [{'condition': '',
'value': '<gn_add><gmd:onLine xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco"><gmd:CI_OnlineResource><gmd:linkage><gmd:URL>https://localhost</gmd:URL></gmd:linkage><gmd:protocol><gco:CharacterString>WWW:LINK-1.0-http--link</gco:CharacterString></gmd:protocol><gmd:name><gco:CharacterString>The Title of the URL</gco:CharacterString></gmd:name><gmd:description><gco:CharacterString>The description of the resource</gco:CharacterString></gmd:description><gmd:function></gmd:function></gmd:CI_OnlineResource></gmd:onLine></gn_add>',
'xpath': '/gmd:MD_Metadata/gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions',
},
json_data = [
{
"condition": "",
"value": '<gn_add><gmd:onLine xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco"><gmd:CI_OnlineResource><gmd:linkage><gmd:URL>https://localhost</gmd:URL></gmd:linkage><gmd:protocol><gco:CharacterString>WWW:LINK-1.0-http--link</gco:CharacterString></gmd:protocol><gmd:name><gco:CharacterString>The Title of the URL</gco:CharacterString></gmd:name><gmd:description><gco:CharacterString>The description of the resource</gco:CharacterString></gmd:description><gmd:function></gmd:function></gmd:CI_OnlineResource></gmd:onLine></gn_add>',
"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)

```

0 comments on commit 551f1ab

Please sign in to comment.