This section explain how to use automation REST calls using raw HTTP requests and response - this page is more theory than concrete examples. You can check concrete examples using different HTTP clients to here:
| Children Display |
|---|
Raw HTTP examples
Here is a complete example on using automation service. This example will do the following:
- get the automation registry
- set a blob on an existing document (let say "/default-domain/workspaces/myws/file") by forcing the server to avoid returning back the blob.
- get the same document with all the data inside (all the schemas)
- download the content of the blob we set at step 2. (and using the information available in the document retrieved at step 3.)
1. Get the automation registry
REQUEST:
| Code Block |
|---|
GET /automation HTTP/1.1 Accept: application/json+nxautomation Host: localhost:8080 |
RESPONSE:
| Code Block |
|---|
HTTP/1.1 200 OK Content-Type: application/json+nxautomation |
| Code Block |
|---|
{
"operations": [
{
"id" : "Blob.Attach",
"label": "Attach File",
"category": "Files",
"description": "Attach the input file to the document given as a parameter. If the xpath points to a blob list then the blob is appended to the list, otherwise the xpath should point to a blob property. If the save parameter is set the document modification will be automatically saved. Return the blob.",
"url": "Blob.Attach",
"signature": [ "blob", "blob" ],
"params": [ ... ]
},
... // other operation follows here
],
"chains" : [
// a list of operation chains (definition is identical to regular operations)
]
}
|
2. Upload a blob into a File document: "/default-domain/workspaces/myws/file"
See the X-NXVoidOperation header to avoid the blob being returned by the server.
REQUEST:
| Code Block |
|---|
POST /automation/Blob.Attach HTTP/1.1
Accept: application/json+nxentity, */*
Content-Type: multipart/related;
boundary="----=_Part_0_130438955.1274713628403"; type="application/json+nxrequest"; start="request"
Authorization: Basic QWRtaW5pc3RyYXRvcjpBZG1pbmlzdHJhdG9y
X-NXVoidOperation: true
Host: localhost:8080
|
| Code Block |
|---|
------=_Part_0_130438955.1274713628403
Content-Type: application/json+nxrequest; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: request
Content-Length: 75
{"params":{"document":"/default-domain/workspaces/myws/file"},"context":{}}
------=_Part_0_130438955.1274713628403
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
Content-Disposition: attachment; filename=test.jpg
Content-ID: input
[binary data comes here]
------=_Part_0_130438955.1274713628403--
|
RESPONSE: 204
3. Get the document data where we uploaded the blob
(see X-NXDocumentProperties header used to specify that all the document data (schemas) should be returned)
REQUEST:
| Code Block |
|---|
POST /automation/Document.Fetch HTTP/1.1 Accept: application/json+nxentity, */* Content-Type: application/json+nxrequest; charset=UTF-8 Authorization: Basic QWRtaW5pc3RyYXRvcjpBZG1pbmlzdHJhdG9y X-NXDocumentProperties: * Host: localhost:8080 |
| Code Block |
|---|
{"params":{"value":"/default-domain/workspaces/myws/file"},"context":{}}
|
RESPONSE:
| Code Block |
|---|
HTTP/1.1 200 OK Content-Type: application/json+nxentity Content-Length: 1121 |
| Code Block |
|---|
{
"entity-type": "document",
"uid": "96bfb9cb-a13d-48a2-9bbd-9341fcf24801",
"path": "/default-domain/workspaces/myws/file",
"type": "File",
"state": "project",
"title": "file",
"lastModified": "2010-05-24T15:07:08Z",
"properties": {
"uid:uid": null,
"uid:minor_version": "0",
"uid:major_version": "1",
"dc:creator": "Administrator",
"dc:contributors": ["Administrator"],
"dc:source": null,
"dc:created": "2010-05-22T08:42:56Z",
"dc:description": "",
"dc:rights": null,
"dc:subjects": [],
"dc:valid": null,
"dc:format": null,
"dc:issued": null,
"dc:modified": "2010-05-24T15:07:08Z",
"dc:coverage": null,
"dc:language": null,
"dc:expired": null,
"dc:title": "file",
"files:files": [],
"common:icon": null,
"common:icon-expanded": null,
"common:size": null,
"file:content": {
"name": "test.jpg",
"mime-type": "image/jpeg",
"encoding": null,
"digest": null,
"length": "290096",
"data": "files/96bfb9cb-a13d-48a2-9bbd-9341fcf24801?path=%2Fcontent"
},
"file:filename": null
}
|
4. Download the content of the blob we set at step 2.
You notice in the last result that the documents contains our blob and the "data" property points to a relative URL that can be used to download the blob content.
Let's download it:
REQUEST:
| Code Block |
|---|
GET /automation/files/96bfb9cb-a13d-48a2-9bbd-9341fcf24801?path=%2Fcontent HTTP/1.1 Authorization: Basic QWRtaW5pc3RyYXRvcjpBZG1pbmlzdHJhdG9y Host: localhost:8080 |
RESPONSE:
| Code Block |
|---|
HTTP/1.1 200 OK Content-Type: image/jpeg Content-Length: 290096 Content-Disposition: attachment; filename=test.jpg |
| Code Block |
|---|
[the blob raw data here] |