Skip to content

Commit

Permalink
add curl examples for file add and replace #1612 #2290
Browse files Browse the repository at this point in the history
Also "add" example to phoenix scripts.
  • Loading branch information
pdurbin committed Jan 24, 2017
1 parent 67f9ad9 commit cc1d614
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
14 changes: 11 additions & 3 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 '[email protected]' -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
Expand Down Expand Up @@ -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 '[email protected]' -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
Expand Down
9 changes: 8 additions & 1 deletion scripts/search/tests/create-all-and-test
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
1 change: 1 addition & 0 deletions scripts/search/tests/expected/finch1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
"files:data.tsv",
"datasets:Darwin's Finches",
"dataverses:Birds",
"dataverses:Finches",
Expand Down

0 comments on commit cc1d614

Please sign in to comment.