External systems can push documents to Appian using a Web API. You can then pass the newly uploaded document into a process model for routing, task assignment, and more.
You will need to create a process model to pass the document into.
In the following example, we created the following process variables in our process model:
We then added nodes to do the following:
In order to call the process model from the web API, you will need to create a constant of type Process Model that uses your process model as the value.
In our example, we created a constant that uses our Upload Student Transcript process model for the value.
When you create your web API, you can use the DOCUMENT UPLOAD template to get started. This will populate your expression with the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
a!localVariables(
/*Check whether the request body contains a document*/
local!success: not(isnull(http!request.body)),
if(
local!success,
/*If a document was uploaded, return a successful response*/
a!httpResponse(
statusCode: 200,
headers: {},
/*Print the document id, name, and extension of the uploaded document*/
body: concat(
"Upload Successful: ",
document(http!request.body, "id"),
" - ",
document(http!request.body, "name"),
".",
document(http!request.body, "extension")
)
),
/*If no document was uploaded, return an error code*/
a!httpResponse(
statusCode: 400,
headers: {},
body: "400 Document Not Provided"
)
)
)
You will need to add the a!startProcess() smart service to the expression and call your process model from that smart service. You can use the HTTP request variable to access the document and the queryParameters and headers of the HTTP request in your expression.
In our example, we modified the default DOCUMENT UPLOAD expression as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
a!localVariables(
/*Check whether the request body contains a document*/
local!success: not(isnull(http!request.body)),
if(
local!success,
! /*If a document was uploaded, start the Upload Student Transcript process*/
! a!startProcess(
! processModel: cons!UPLOAD_STUDENT_TRANSCRIPT,
! processParameters: {
! /*A document*/
! transcript: http!request.body,
! /*Metadata from parameters or headers*/
! studentId: http!request.queryParameters.studentId
! },
`onSuccess:` a!httpResponse(
statusCode: 200,
headers: {},
/*Print the document id, name, and extension of the uploaded document*/
body: concat(
"Upload Successful: ",
document(http!request.body, "id"),
" - ",
document(http!request.body, "name"),
".",
document(http!request.body, "extension")
)
),
! onError: a!httpResponse(
! statusCode: 500,
! headers: {},
! body: "500 Internal Server Error"
! )
! ),
/*If no document was uploaded, return an error code*/
a!httpResponse(
statusCode: 400,
headers: {},
body: "400 Document Not Provided"
)
)
)
You can pass information from the web API into the process model, including:
In our example we are using the studentId to find the student in our data store. The studentId is a queryParameter in the HTTP request.
We then write the transcript document to the data store and move it into a different folder.
1
2
3
4
5
6
7
8
9
10
11
12
...
a!startProcess(
processModel: cons!UPLOAD_STUDENT_TRANSCRIPT,
processParameters: {
/*A document*/
`transcript: http!request.body,`
/*Metadata from parameters or headers*/
`studentId: http!request.queryParameters.studentId`
},
...