Skip to content

Commit 38a4d06

Browse files
authored
Merge pull request #12140 from dsd-sztaki-hu/preview-url-token-as-api-token-doc
document preview URL token usage as API key
2 parents a9ab923 + 9691097 commit 38a4d06

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

doc/sphinx-guides/source/api/auth.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ You can reset your API Token from your account page in your Dataverse installati
6666

6767
.. _bearer-tokens:
6868

69+
Using Preview URL Tokens as API Token
70+
--------------------------------------
71+
72+
If you want to access a dataset's contents shared by a preview URL (see :ref:`previewUrl`, :ref:`get-file-using-preview-url-token`, :ref:`get-dataset-by-preview-url-token` and :ref:`create-a-preview-url-for-a-dataset`) using the API, you can use the token in the preview URL as API_TOKEN.
73+
74+
.. code-block:: bash
75+
76+
SERVER_URL=https://demo.dataverse.org
77+
PREVIEW_URL_TOKEN=a56444bc-7697-4711-8964-e0577f055fd2
78+
79+
# this gets you the file listing with the corresponding file IDs, file names and other file metadata
80+
curl "$SERVER_URL/api/datasets/privateUrlDatasetVersion/$PREVIEW_URL_TOKEN"
81+
82+
# this gets you a specific file
83+
FILE_ID=1111111
84+
FILENAME=example.txt
85+
curl -H "X-Dataverse-key:$PREVIEW_URL_TOKEN" -o "$FILENAME" "$SERVER_URL/api/access/datafile/$FILE_ID"
86+
6987
Bearer Tokens
7088
-------------
7189

doc/sphinx-guides/source/api/dataaccess.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@ The fully expanded example above (without environment variables) looks like this
168168
169169
curl -H "Range:bytes=0-9" https://demo.dataverse.org/api/access/datafile/42
170170
171+
172+
.. _get-file-using-preview-url-token:
173+
174+
Using a Preview URL Token
175+
~~~~~~~~~~~~~~~~~~~~~~~~~
176+
177+
If you want to access a file in a dataset shared by a preview URL (see :ref:`previewUrl`, :ref:`get-dataset-by-preview-url-token` and :ref:`create-a-preview-url-for-a-dataset`) using the API, you can use the token in the preview URL as API_TOKEN.
178+
179+
.. code-block:: bash
180+
181+
SERVER_URL=https://demo.dataverse.org
182+
PREVIEW_URL_TOKEN=a56444bc-7697-4711-8964-e0577f055fd2
183+
FILE_ID=1111111
184+
FILENAME=example.txt
185+
curl -H "X-Dataverse-key:$PREVIEW_URL_TOKEN" -o "$FILENAME" "$SERVER_URL/api/access/datafile/$FILE_ID"
186+
187+
171188
Multiple File ("bundle") download
172189
---------------------------------
173190

doc/sphinx-guides/source/api/native-api.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,8 @@ The fully expanded example above (without environment variables) looks like this
28082808
curl -H "X-Dataverse-key:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -X DELETE "https://demo.dataverse.org/api/datasets/2347/assignments/6"
28092809
28102810
2811+
.. _create-a-preview-url-for-a-dataset:
2812+
28112813
Create a Preview URL for a Dataset
28122814
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28132815

@@ -3914,6 +3916,8 @@ Like :ref:`get-export-formats`, this API can be used to get URLs to dataset meta
39143916
39153917
curl -H "Accept:application/json" "$SERVER_URL/api/datasets/:persistentId/versions/$VERSION/linkset?persistentId=$PERSISTENT_IDENTIFIER"
39163918
3919+
.. _get-dataset-by-preview-url-token:
3920+
39173921
Get Dataset By Preview URL Token
39183922
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39193923

@@ -3932,6 +3936,8 @@ Usage example:
39323936
39333937
curl "https://demo.dataverse.org/api/datasets/previewUrlDatasetVersion/a56444bc-7697-4711-8964-e0577f055fd2?returnOwners=true"
39343938
3939+
For downloading files using a preview URL token, see the :ref:`Data Access API <get-file-using-preview-url-token>`.
3940+
39353941

39363942
.. _get-citation:
39373943

@@ -3997,6 +4003,7 @@ Get Citation by Preview URL Token
39974003
39984004
curl "$SERVER_URL/api/datasets/previewUrlDatasetVersion/$PREVIEW_URL_TOKEN/citation"
39994005
4006+
40004007
.. _get-dataset-summary-field-names:
40014008

40024009
Get Summary Field Names

0 commit comments

Comments
 (0)