Blue Prism 7.0 - Web APIs
Blue Prism 7.0 - Web APIs
0
Web APIs
Contents
Trademarks and Copyright
Contents iiiii
Actions
Basic API definition
Parameters
Request
Response (action-specific)
settings
5 5
6
8
Headers 9
Parameters 10
Common authentication
Authentication types
12 13
Common code
Code options
Shared code
15 15
Connection settings 16
Credential manager 17
Custom credentials 18
Configure the credential 18
Configure the Web API definition 18
Specify the credential in an object or process 19
Extract response data with JSONPath 20
Configure the API definition response 20
View the response in Process Studio 20
JSONPath syntax
Example
21 21
Sending files 23
Send a single file
Web API definition
Process
23 23
Once an API definition has been configured, the associated Actions can be used in Objects to enable
Process Developers to use interactions with third-party services as part of an automation.
Basic settings
The common components and settings for all requests in an API definition.
Name
A name, unique in the environment, that is used to identify the API definition in Blue Prism. The name is
used when selecting the API definition in Action stages.
Base URL
The part of a URL that is used for every HTTP request within the API.
Advanced settings
Apply connection timeout settings for configured web services:
• HTTP request connection timeout – The maximum length of time that Blue Prism waits for a
response to an HTTP request before an exception is thrown.
• Authorization server request connection timeout – The maximum length of time Blue Prism waits
for a response to an authorization server request before an exception is thrown. This setting is only
available for OAuth 2.0 (Client Credentials) and OAuth 2.0 (JWT Bearer Token) authentication
types when selected in the Common Authentication settings for an API definition.
Actions
A Web API definition can include multiple Actions, each one representing a different request to a specific
endpoint using the required HTTP method. All configured actions for an API display in the navigation tree
and are listed in the main screen when the Actions node is selected.
Click Add Action to create a new action for an API definition and configure the associated parameters.
Name
A unique name for the action. The name is used when selecting business objects for actions in Object and
Process Studio.
Description
An optional description to provide more information about the action.
Enabled
Actions must be enabled to be available for selection in objects and processes.
Parameters (action-specific)
These parameters are specific to the action and are used in combination with the common parameters as
the inputs for an action in objects and processes. When enclosed in square brackets, parameter names
are used dynamically to add their values to URLs, header values, and request bodies.
Request
Define the HTTP Request that will made to this API Endpoint by selecting the required HTTP method
and adding the URL path, body content, and headers.
Method
The HTTP method used for the request. The drop-down contains the standard HTTP methods but any
request verbs can be entered into the free-text field. Validation is performed on the field to prevent the
input of non-allowed characters.
URL Path
The URL path particular to the action that defines the specific request when used with the base URL. The
URL path can be parametrized using common and request-specific parameters, enclosed in square
brackets.
For example, the base URL is:
http://staff.database.com
The URL Path is:
/api/[version]/employee/[id]
When the parameters are expanded and added to the base URL, a request is made to this address:
http://staff.database.com/api/v1/employee/26855
Body
Configure the content to be sent with the HTTP request using one of the following content types:
• None – The request does not include body content. This is usual for actions that retrieve
information, such as those using the GET method.
• Template – Send text-based body content such JSON or XML. Parameters can be used to add data
to the request body.
• Single File – Send files as part of the API request. The API definition specifies an input parameter
that is used to reference a file from a data stage in a process.
• Multiple Files – Send multiple files as part of the API request. The API definition specifies an input
parameter that is used to reference files from a collection stage in a process.
• Custom Code – For complex scenarios the request body can be generated using code. Where
required, this can incorporate code from the Common Code area of the API definition.
Headers (action-specific)
Add a name and value for each header specific to this action. The headers used in a request are a
combination of the common headers in the API definition and the headers set at action level. If an action-
specific header has the same name as a common header, the value of the action specific is used in any
requests.
Response
Transform the HTTP response using JSON Path or custom code to extract the required data. The data
can be stored in data items, making it easier to use in other stages of an object or process. Custom code
can be used to configure more complex responses, for example, performing calculations on the response
data.
The response output is defined using the following fields:
• Parameter – The name of the output parameter created to store the data specified.
• Data Type – The data type of the output parameter.
• Method – The method can be either JSONPath or Custom Code. If using Custom Code, the outputs
are ref parameters that need to be assigned.
• JSON Path – If using JSONPath, the expression needed to extract specific elements of the JSON
into output parameters. These output parameters have a specified Blue Prism data type, and the
object found using the JSON Path will be converted to that data type.
For further information about configuring responses, see Extracting response data with JSON
Path.
Headers
Configure the HTTP headers to be sent as part of a Web API request. Headers can be defined for the
whole API and for individual request methods:
• Common – Common headers are sent in every request generated by the actions in an
API definition.
• Request-specific – Headers that are only sent in requests for the associated actions.
Headers are defined by entering a name and the required value. Values can include parameters, that
dynamically add their values when the API is called.
The same name can be used for common and request-specific headers. Where this is the case, and both
have a value configured in the API definition, the value of the request-specific header is used when the
API is called.
This example shows an API request, created from an API definition:
• The request includes both common and request-specific headers.
• The Content-Type header has a value set in the common header that is overwritten by the value in
the request-specific header when the API is called.
• The From header is populated with the value set in the email-address parameter.
Parameters
Parameters provide a method of passing data into an API request by dynamically adding a value when an
API is called from within a process. They can be used in base URLs, action URL paths, headers, request
bodies, and when exposed to processes, they are available as inputs for actions in objects and processes
when the appropriate API service is selected as a business object.
Two types of parameters can be configured in an API definition, common parameters and action specific
parameters. Common parameters are used in all actions and parameters configured at action level are
available only to that action.
To use a parameter value in URL paths, headers, and request bodies, enclose parameters in square
brackets. For example:
http://staff.database.com/api/[version]/employee/[id]
When a process that uses the associated API definition is run and the parameters are expanded, the URL
could become:
http://staff.database.com/api/v2/employee/290054
To use square brackets without referencing a parameter, the text must start with double square brackets.
For example, if the request body included:
{
"favourite-colours": [["green", "red", "blue"]
}
When the API is called, the HTTP request includes the square brackets:
{
"favourite-colours": ["green", "red", "blue"]
}
Parameters are applied at the point at which an API is called and values are taken from the API definition
if an initial value has been set. However, if the parameter has been exposed and a value has been entered
as an input in a process action, this value will be used.
In the following example, two common parameters are configured in the API definition, both with initial
values set and both exposed to processes.
An input value for the version parameter is set in an action but not for the id parameter.
When the action runs and the API is called, the version parameter value is taken from the API definition
and the id from the action input.
Common authentication
Where API requests require authentication to send and receive information, credentials specific to the
authentication type can be configured. Blue Prism supports the use of the following authentication types
for API requests:
• Basic
• Bearer Token
• OAuth 2.0 (Client Credentials)
• OAuth 2.0 (JWT Bearer Token)
• Custom
Credentials are used to store the data required to make an authenticated request to a Web API.
Credentials applicable to the above authentication types are created in Credential Manager and then
used to authenticate any request to the Web API. The credential selected in the API definition is used for
all associated actions. However, when exposed to processes, an alternative credential can be used when
specified as an input parameter.
In the example below, the Address Credential has been selected in the API definition as the default
credential for all associated actions where an alternative value is not specified in the action inputs in
Object Studio and Process Studio.
Given that Expose to process has been selected, a related input parameter is available for processes. The
name of an alternative credential has been specified in the input parameter and is used when the API is
called.
Authentication types
The following authentication types can be configured within a Web API definition.:
None
The API does not require authentication.
Basic
Uses HTTP Basic Authentication to send a username and password from a selected credential in request
headers. If required, and if the API supports it, select the Pre-emtively send the authorization header
check box. Pre-emptive authorization sends the basic authentication response directly with the HTTP
request rather than when responding to an unauthorized response.
Select the required credential from the drop-down list and if required, select Expose to process and enter
a parameter name.
Bearer Token
This credential type caters for situations where the token has already been obtained and needs to be sent
in the authorization header. This could be used to support situations whereby Blue Prism uses a different
method, such as a code stage, to obtain the token.
The token is stored in a credential and referenced in an API definition. When used in request headers the
token passed in the following format:
Authorization: Bearer <AccessToken>
For example, Authorization: Bearer FGRS5-PUUDW-NBC2Q-96UYR-QBDSY
Custom
Custom credentials allow bespoke authentication methods to be used in Blue Prism. For example, a
custom credential could be used to authenticate using an API key or subscription key, stored securely in
the password field of a credential. The credential, stored in Credential Manager can be passed into the
API request as a parameter allowing it to be used in the request body, header, or URL.
For more information about using custom credentials, see Custom credentials.
Common code
Some third-party APIs require more complex request and response data. The Share Code and Code
Options settings are used when configuring code in individual actions to generate the body content for a
request or to transform the HTTP response into output parameters.
Code options
Specify the language to use for all code in the API definition and add any third-party libraries and the
related Namespace Imports. The following languages are supported:
• Visual Basic
• C#
Shared code
Add any code, such as library functions and common properties, that is required across the whole API to
define HTTP body content and responses.
Connection settings
Configure advanced connection settings, applied when making web requests. Any user with the System
– Web Connection Settings permission enabled for their user role can configure these settings.
Default settings can be configured for all Web API requests. The default settings are overridden if values
are set for specific URIs:
• URI – The URI for which the settings will be applied. The URI must only be comprised of scheme
and host and the settings are applied to all requests that use the entered URI.
• Connection limit – The number of connections per service point.
• Connection lease timeout – The time permitted for a connection to remain idle before it closes.
• Maximum idle time – The number of seconds after which a connection is closed.
Credential manager
For API requests that require authorization, it is necessary to add the relevant credentials to Credential
Manager.
1. Select System > Security > Credentials and click New.
The Credentials Details dialog displays.
2. Select the authentication type for the credential:
• Basic – Add the authentication username and password required to create the basic
authentication header.
• Bearer Token – Add the Bearer token to add to the authentication header.
• OAuth 2.0 (Client Credentials) – Add the client identifier and secret, stored in a credential,
to retrieve an OAuth 2.0 access token from an authorization server. The access token is then
used to authenticate Web API requests.
• OAuth 2.0 (JWT Bearer Token) – Add the JWT issuer and private key, used to sign the JWT
– a PKCS8 private key is expected in a PEM base64-encoded format. The JWT is then sent to
the authorization server to get the access token required to authenticate the request.
For further information about configuring authentication types in API definitions, see Common
authentication.
4. In the Additional Properties section, add any general purpose, named properties for the credential.
The values are held securely within the database and can be requested by processes.
5. Select the Access Rights tab and define the required permissions.
It is recommended that the access rights are configured so only user accounts with the appropriate
security roles are able to access to each credential. When a credential is limited by security role:
• The selected security roles must be held by the user(s) who require access to the credential
when building or debugging a process or object.
• Only runtime resources that are configured to explicitly authenticate will potentially be able
to access the credential.
• The selected security roles must be held by the account(s) used by runtime resources to
authenticate against the environment.
7. Click OK to save.
Custom credentials
This example demonstrates how to pass an API key, securely stored in a credential, into a request URL as
a query string.
In the URL for the request, enter [Credential.Password] in place of the API key.
This parametrizes the password field of the given credential, allowing the value to be passed. The same
syntax can be used to pass other values from a credential:
• [Credential.Password]
• [Credential.UserName]
• [Credential.AdditionalProperties<propertyname>]
When the object or process is run, the API key from the credential is used in the request:
GET http://www.postcodeuk.com/address/UK/"Andy Taylor"?api_key=FGRS5-PUUDW-NBC2Q-
96UYR-QBDSY
To extract this data, select the Response for the required action in the API definition. Add a parameter for
each data item selecting the appropriate data type and method.
When the process is run, data from the response is stored in the appropriate stage allowing it to be easily
used elsewhere in the process.
If the JSONPath defined for the output parameter does not find a match in an HTTP response, the
output parameter will return an empty data item/collection. If the JSONPath defined for the output
parameter finds multiple possible matches in an HTTP response, an exception will be thrown in the
process.
JSONPath syntax
Blue Prism supports the following syntax for JSONPath expressions:
JSONPath Description
$ The root object or element.
@ The current object or element.
. or [] Child operator.
.. Recursive descent.
* Wildcard.
[] The native array operator.
[start:end:step] Array slice operator.
?() Applies a filter (script) expression.
() Script expression, using the underlying script engine.
Example
A staff database contains a number of records that includes data about the employees of an organization.
{
"staff-database": {
"employee": [
{
"id": 1245,
"name": "Geoff Bryant",
"salary": 45000,
"age": 46
},
{
"id": 1365,
"name": "Tom Roberts",
"salary": 38000,
"job-title": "developer"
"age": 34
},
{
"id": 1287,
"name": "Herman Blunt",
"salary": 27000,
"job-title": "tester"
"age": 26
},
]
}
}
The following are examples of how JSONPath can be used to extract data.
JSONPath Result
Sending files
The following examples demonstrate how to send single or multiple files as part of an HTTP request.
Process
In Process Studio, a process contains a data item called Notes with a Data Type of Binary into which a file
has been imported.
An action stage in the process uses the API definition and references the Notes data item as the value for
the input parameter.
When the API is called, the file imported into the data item is sent as part of the HTTP request.
Process
A process contains a collection item called Files into which a number of files have been imported.
Collections passed into input parameters are expected to use the following specified schema:
When creating a collection, the required schema can be imported by clicking Import Fields from the
Collection Properties and selecting a parameter from required web API action.
An action stage in the process uses the API definition and references the Files data item as the value for
the input parameter.
When the API is called, the file is sent as part of the HTTP request.