diff --git a/doc/sphinx-guides/source/api/native-api.rst b/doc/sphinx-guides/source/api/native-api.rst index 5ed673a0b2a..769e224dfe0 100644 --- a/doc/sphinx-guides/source/api/native-api.rst +++ b/doc/sphinx-guides/source/api/native-api.rst @@ -204,11 +204,15 @@ Delete a Private URL from a dataset (if it exists):: DELETE http://$SERVER/api/datasets/$id/privateUrl?key=$apiKey -Add a file to an existing Dataset. Description and tags are optional:: +Add a file to an existing Dataset. Description and tags are optional:: POST http://$SERVER/api/datasets/$id/add?key=$apiKey -Example python code to add a file. This may be run by changing these parameters in the sample code: +A more detailed "add" example using curl:: + + curl -H "X-Dataverse-key:$API_TOKEN" -X POST -F 'file=@data.tsv' -F 'jsonData={"description":"My description.","categories":["Data"]}' "https://example.dataverse.edu/api/datasets/:persistentId/add?persistentId=$PERSISTENT_ID" + +Example python code to add a file. This may be run by changing these parameters in the sample code: * ``dataverse_server`` - e.g. https://dataverse.harvard.edu * ``api_key`` - See the top of this document for a description @@ -295,10 +299,14 @@ In practice, you only need one the ``dataset_id`` or the ``persistentId``. The e Files ~~~~~~~~~~~ -Replace an existing file where ``id`` is the Database id of the file to replace. Note that metadata such as description and tags are not carried over from the file being replaced:: +Replace an existing file where ``id`` is the database id of the file to replace. Note that metadata such as description and tags are not carried over from the file being replaced:: POST http://$SERVER/api/files/{id}/replace?key=$apiKey +A more detailed "replace" example using curl:: + + curl -H "X-Dataverse-key:$API_TOKEN" -X POST -F 'file=@data.tsv' -F 'jsonData={"description":"My description.","categories":["Data"]}' "https://localhost:8181/api/files/$FILE_ID/replace" + Example python code to replace a file. This may be run by changing these parameters in the sample code: * ``dataverse_server`` - e.g. https://dataverse.harvard.edu diff --git a/scripts/search/tests/create-all-and-test b/scripts/search/tests/create-all-and-test index 50612544b44..a49b0e264f5 100755 --- a/scripts/search/tests/create-all-and-test +++ b/scripts/search/tests/create-all-and-test @@ -8,9 +8,16 @@ scripts/search/create-tree-dvs1 > /tmp/tree-dvs1 echo "Creating some datasets" curl -s --insecure --data-binary @scripts/search/tests/data/dataset-trees1.xml -H 'Content-Type: application/atom+xml' -u $SPRUCEKEY: https://localhost:8181/dvn/api/data-deposit/v1.1/swordv2/collection/dataverse/spruce | xmllint -format - >/dev/null curl -s -X POST -H "Content-type:application/json" -d @scripts/search/tests/data/dataset-finch1.json "http://localhost:8080/api/dataverses/finches/datasets/?key=$FINCHKEY" >/dev/null -echo "Uploading a file" +echo "Uploading a file via the SWORD API" . scripts/search/assumptions curl -s --insecure --data-binary @scripts/search/data/binary/trees.zip -H 'Content-Disposition: filename=trees.zip' -H 'Content-Type: application/zip' -H 'Packaging: http://purl.org/net/sword/package/SimpleZip' -u $SPRUCEKEY: https://localhost:8181/dvn/api/data-deposit/v1.1/swordv2/edit-media/study/$FIRST_SPRUCE_DOI >/dev/null +echo "Uploading a file via the native API" +# echo $FIRST_FINCH_DOI # FIXME: Why is this empty? +STATUS_CODE_FROM_UPLOADING_FILE_VIA_NATIVE=$(curl -H "X-Dataverse-key:$FINCHKEY" --insecure --write-out %{http_code} --silent --output /dev/null -X POST -F "file=@scripts/search/data/replace_test/growing_file/2016-01/data.tsv" -F 'jsonData={"description":"My description.","categories":["Data"]}' "http://localhost:8080/api/v1/datasets/$FIRST_FINCH_DATASET_ID/add") +if [[ "$STATUS_CODE_FROM_UPLOADING_FILE_VIA_NATIVE" != 200 ]]; then + echo "Couldn't upload file to dataset $FIRST_FINCH_DATASET_ID via native API!" + exit 1 +fi # give the file a little time to ingest sleep 2 echo "Everything in draft, checking permissions. Silence is golden." diff --git a/scripts/search/tests/expected/finch1 b/scripts/search/tests/expected/finch1 index 181925ea0a9..f9fa17cee1a 100644 --- a/scripts/search/tests/expected/finch1 +++ b/scripts/search/tests/expected/finch1 @@ -1,4 +1,5 @@ [ + "files:data.tsv", "datasets:Darwin's Finches", "dataverses:Birds", "dataverses:Finches",