Commit bc256693 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Fix dupal uuid retrieval

parent 55628b4c
Pipeline #26438 passed with stages
in 1 minute and 50 seconds
......@@ -64,7 +64,7 @@ class WriteTypeReportToDrupal(Resource):
'message': f'Missing a element in input body: {er}'
}, 400
try:
node_id = self.get_node_id(identifier, node_type)
node_id = self.get_drupal_uuid(identifier, node_type)
return self.write_results(node_type, node_id, status, report)
except ImportApiError as e:
current_app.logger.error(
......@@ -73,16 +73,12 @@ class WriteTypeReportToDrupal(Resource):
'error': f"Could not write report to {node_type}/{identifier}: "
f"{e.message}"}, 500
def get_node_id(self, memobase_id: str, node_type: str):
current_app.logger.debug(
f'Retrieve node id from durpal json api with memobase id {memobase_id}.')
url = f'{self.base_url}/jsonapi/node/{node_type}?filter[' \
f'field_memobase_id]={memobase_id}'
def get_drupal_uuid(self, memobase_id: str, node_type: str):
url = f'{self.base_url}/jsonapi/node/{node_type}?filter[field_memobase_id]={memobase_id}'
response = requests.get(url, headers=self.headers)
if response.ok:
try:
return response.json()['data'][0]['attributes']['drupal_internal__nid']
return response.json()['data'][0]['id']
except KeyError as er:
current_app.logger.error(f"Could not find the key {er} in data: {response.text}.")
raise ImportApiError(f"Could not find the key {er} in data (url={url}): "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment