From dac76df738ff63d955be80a553508ff268ef59cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pallinger=20P=C3=A9ter?= Date: Thu, 16 Jun 2022 10:06:59 +0200 Subject: [PATCH] - do not delete params in put_request - fix replace documentation and parametrization in edit_dataset_metadata --- src/pyDataverse/api.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pyDataverse/api.py b/src/pyDataverse/api.py index 22aeefe..4eac136 100644 --- a/src/pyDataverse/api.py +++ b/src/pyDataverse/api.py @@ -185,7 +185,7 @@ def post_request(self, url, data=None, auth=False, params=None, files=None): "ERROR: POST - Could not establish connection to API: {0}".format(url) ) - def put_request(self, url, data=None, auth=False, params=None): + def put_request(self, url, data=None, auth=False, params={}): """Make a PUT request. Parameters @@ -198,7 +198,7 @@ def put_request(self, url, data=None, auth=False, params=None): Should an api token be sent in the request. Defaults to `False`. params : dict Dictionary of parameters to be passed with the request. - Defaults to `None`. + Defaults to `{}`. Returns ------- @@ -206,7 +206,6 @@ def put_request(self, url, data=None, auth=False, params=None): Response object of requests library. """ - params = {} params["User-Agent"] = "pydataverse" if self.api_token: params["key"] = self.api_token @@ -1275,7 +1274,7 @@ def edit_dataset_metadata( Get dataset metadata:: >>> data = api.get_dataset(doi).json()["data"]["latestVersion"]["metadataBlocks"]["citation"] - >>> resp = api.edit_dataset_metadata(doi, data, is_replace=True, auth=True) + >>> resp = api.edit_dataset_metadata(doi, data, replace=True, auth=True) >>> resp.status_code 200: metadata updated @@ -1288,7 +1287,7 @@ def edit_dataset_metadata( url = "{0}/datasets/editMetadata/{1}".format( self.base_url_api_native, identifier ) - params = {"replace": True} if replace else {} + params = {"replace": "true"} if replace else {} resp = self.put_request(url, metadata, auth, params) if resp.status_code == 401: @@ -1304,7 +1303,7 @@ def edit_dataset_metadata( else: print( "You may not add data to a field that already has data and does not" - " allow multiples. Use is_replace=true to replace existing data." + " allow multiples. Use replace=True to replace existing data." ) elif resp.status_code == 200: print("Dataset '{0}' updated".format(identifier))