Skip to content
This repository has been archived by the owner on Jul 2, 2018. It is now read-only.

Items: Create new item

Natasa Bulatovic edited this page Jul 20, 2015 · 10 revisions

##POST /items Creates a new imeji item in a collection (multipart/form-data)

###Parameters

  • file (multipart/form-data) - file to be uploaded when new item is created (optional)
  • json - the JSON formatted item (containing collection URI, metadata or optionally, fetch/reference URL in case when file parameter is not provided i.e. file is not explicitly uploaded). Note that JSON body must contain element "collectionId" with valid collection identifier.

####Response status codes #####201 Created Successful creation of the item

#####400 Bad request The body of the request is not syntactically correct, user provided false body for the request

#####401 Unauthorized Authentication is necessary to create an item, and user is not authenticated or provided invalid credentials

#####403 Forbidden Wrong credentials provided to create an item (User does not have a right to create it)

#####422 Unprocessable Entity The body of the request is syntactically correct, but data are not semantically correct e.g. missing a mandatory field such as the collectionid.

####Example request

curl --user admin:admin \
       -v include --form json='{<see_example_request_body_below>}' \
       --form=upload=<yourfilename-to-upload> \
       http://<base-url-rest-api>/items

#####Example request body #######JSON body of request with directly uploaded file, file name is not provided explicitly { "collectionId": "WI2WwImATeSje4VG", "metadata": [ { "position": 0, "value": { "text": "TEST DATA SET" }, "statementUri": "http://imeji.org/terms/statement/YdQbalnDR2sqQQp", "typeUri": "http://imeji.org/terms/metadata#text", "labels": [ { "language": "en", "value": "DATA_SET_PARAMETER_NAME" } ] }, { "position": 1, "value": { "text": "This is a test data set" }, "statementUri": "http://imeji.org/terms/statement/X4K2c_8ZSB9Hn2Fu", "typeUri": "http://imeji.org/terms/metadata#text", "labels": [ { "language": "en", "value": "Description" } ] } ] }

#######JSON body of the request with directly uploaded file, but change the filename during item creation

   {
      "collectionId": "WI2WwImATeSje4VG",
      "filename": "imeji_resource_history_resttest_changed_filename.png",
      "metadata": [ {
      "position": 0,
      "value": {
        "text": "TEST DATA SET"
      },
      "statementUri": "http://imeji.org/terms/statement/YdQbalnDR2sqQQp",
      "typeUri": "http://imeji.org/terms/metadata#text",
      "labels": [
        {
          "language": "en",
          "value": "DATA_SET_PARAMETER_NAME"
        }
      ]
    },
    {
      "position": 1,
      "value": {
        "text": "This is a test data set"
      },
      "statementUri": "http://imeji.org/terms/statement/X4K2c_8ZSB9Hn2Fu",
      "typeUri": "http://imeji.org/terms/metadata#text",
      "labels": [
        {
          "language": "en",
          "value": "Description"
        }
      ]
    }
    ]
    }

#######JSON body of the request containing the URL from where the file should be fetched { "collectionId": "WI2WwImATeSje4VG", "fetchUrl" : "http://somefetchurl/thisistheoriginalfilename.png" "filename": "imeji_resource_history_resttest_changed_filename.png", "metadata": [ { "position": 0, "value": { "text": "TEST DATA SET" }, "statementUri": "http://imeji.org/terms/statement/YdQbalnDR2sqQQp", "typeUri": "http://imeji.org/terms/metadata#text", "labels": [ { "language": "en", "value": "DATA_SET_PARAMETER_NAME" } ] }, { "position": 1, "value": { "text": "This is a test data set" }, "statementUri": "http://imeji.org/terms/statement/X4K2c_8ZSB9Hn2Fu", "typeUri": "http://imeji.org/terms/metadata#text", "labels": [ { "language": "en", "value": "Description" } ] } ] }

In the examples above, the file fetched will be renamed to the provided new filename. If the filename parameter was ommitted, the original file name is stored with the uploaded file (as fetched from the provided fetchUrl)

#######Request containing the URL from where the file should be referenced { "collectionId": "WI2WwImATeSje4VG", "referenceUrl" : "http://somefetchurl/thisistheoriginalfilename.png" }

An item will be created in Imeji, but the file content will not be uploaded to internal imeji storage, rather will be referenced. This method can be used to reference already existing file storage and describe the files through imeji.

#####Response

Clone this wiki locally