Aller au contenu principal

Miralia.ai Analyses API v2 (2.0.0)

Download OpenAPI specification:Download

This is a sample of the Miralia.ai Documentation containing any necessary informations to post an analysis and get its result with the v2 API of Miralia.ai.

Authentication

The Miralia.ai API is secured by API keys, and all your API requests must be made over HTTPS and must be authenticated with one of them.

The API keys will be provided by Miralia.ai. Each key has two values: the "App ID", which identifies your integration and is not sensitive information, and the "Secret Key", which is sensitive data and must be kept confidential.

Each API key uses exactly one of the two authentication methods below, set when the key is created. A key cannot use the other method: the requests of an OAuth2 key sent with the App ID and Secret Key are refused, and an App ID and Secret Key key cannot get an access token.

App ID and Secret Key

Send both values with every request:

  • the "App ID" as a query parameter named appId, so your URLs end with something like ?appId=<YOUR_APP_ID>;
  • the "Secret Key" as the value of the Authorization HTTP header.

OAuth2

Send the "App ID" and "Secret Key" only to the /oauth/token endpoint, with the scope analysis:global, which returns a short-lived access token (OAuth2 client_credentials grant). Then send that access token with every other request, as Authorization: Bearer <access_token>, without the appId query parameter.

When the access token expires, request a new one. An access token stops working as soon as its API key is disabled or deleted.

Getting started

To use our API, you will need to create an analysis. Then, to retrieve the result, you can either do it the "push-based" way, with webhooks, or the "pull-based" way, with other HTTP REST calls.

Create an analysis

You will need to send your message with the /environment/{environmentId}/analyses endpoint. The endpoint's documentation contains all details on how to send your message.

Retrieve results with a webhook

This is the preferred way of retrieving the result: we send the result as soon as possible, and we know when we delivered the result for sure.

If you choose to integrate with this way, we will integrate the webhook in our configuration. When the analysis will be done, Miralia.ai will do a HTTP POST request to an URL you defined. You can also define a pair of header name and value that we will send alongside the request, to protect your endpoint.

For more information on the webhook format, you will have more information on the /analysis/{analysisId}/result endpoint.

Retry policy

If your endpoint does not answer with a success status (HTTP error, timeout, unreachable endpoint...), we automatically retry the delivery with an exponential backoff:

  • up to 3 additional attempts after the initial failed delivery (4 attempts in total) ;
  • the first retry happens 5 seconds after the failure ;
  • this delay is multiplied by 5 on each subsequent attempt (so ~25 seconds, then ~2 minutes) ;
  • if every attempt fails, the result is not pushed anymore — you can still retrieve it with the /analysis/{analysisId}/result endpoint.

Retrieve results by HTTP REST call

By using the the /analysis/{analysisId}/result endpoint, you will have the same output you would have received by webhook.

OAuth2

Get an access token for an API key using the OAuth2 authentication method.

Get an OAuth2 access token

OAuth2 token endpoint, for the client_credentials grant only. Only API keys created with the OAuth2 authentication method can use it.

Authenticate with HTTP Basic: the "App ID" as username and the "Secret Key" as password, and request the analysis:global scope, the only one available. Send the returned access_token on the other endpoints as Authorization: Bearer <access_token>. It is only valid on the project of the API key.

Authorizations:
Client_Credentials
Request Body schema: application/x-www-form-urlencoded
required
grant_type
required
string
Value: "client_credentials"
scope
required
string
Value: "analysis:global"

The scope of the access token. analysis:global is the only one available.

Responses

Request samples

Content type
application/x-www-form-urlencoded
grant_type=client_credentials&scope=analysis%3Aglobal

Response samples

Content type
application/json
{
  • "access_token": "eyJ0eXAiOiJhdCtqd3QiLCJhbGciOiJSUzI1NiJ9...",
  • "token_type": "Bearer",
  • "expires_in": 3600,
  • "scope": "analysis:global"
}

Analyses

Create and access ICv2 analyses.

Create an analysis

Create an analysis in the environment provided in the path.

The inputs of an analysis

An analysis is composed of multiple inputs. For each input, you must specify:

  • the type of the input: is it the BODY (the main content)? An ATTACHMENT (a file)? Or another type for more information? (TICKET_TOPIC for example)
  • the content type of the input: is it a file or simply text.

To specify the inputs, you have to build the inputs JSON array. Here is an example with all kinds of inputs:

[
  {
    "type": "BODY",
    "contentType": "file",
    "file_key": "file_1"
  },
  // another possibility is to use a text input as the main content
  // but you should have only one BODY input
  {
    "type": "BODY",
    "contentType": "text",
    "text": "Main content to analyse",
    "name": "Main content" // This is optional, but recommended
  },
  // if you have attachments, you can specify them
  {
    "type": "ATTACHMENT",
    "contentType": "file",
    "file_key": "attachment_1"
  },
  {
    "type": "ATTACHMENT",
    "contentType": "file",
    "file_key": "attachment_2"
  },
  // if you have more information that golem must analyse.
  {
    "type": "TICKET_TOPIC",
    "contentType": "text",
    "text": "Ticket topic",
    "name": "TICKET_TOPIC" // This is optional, but recommended
  }
]

This inputs array must be set in the payload field of the request. The request must be a multipart/form-data request, and payload is mandatory to describe the analysis. It contains a JSON object, with the inputs array, but also other fields, namely:

  • metadata: a JSON object containing the metadata of the analysis. Metadata are data you might want to keep around on your analysis, for example to match it back to something on your end when you receive the result by webhook.
    • the inbox metadata is special: if you have multiple "inboxes" for your messages, you should set this field to the inbox of the message. It will open a lot of features in the Miralia.ai console.
  • name: a string containing the name of the analysis. This is optional, and by default is set to the filename of the first BODY file. If that file has a non-descriptive name, you should set this field.
  • configurationOptions: a JSON object of options changing how this analysis is processed. All optional:
    • enableFileOperationSplit (boolean, default true): if false, turns off for this analysis only, the splitting of files containing several documents (for example a single PDF holding multiple invoices), even if splitting is enabled in the environment configuration.
      • No split entries will then appear in fileOperations.
      • If your environment doesn't have file splitting enabled, this option has no effect.
    • manualFinalStatusUpdate (boolean, default false): the success or failure of the analysis must be confirmed by an external automation. If you're not sure if you need it, you don't need it.
  • manualFinalStatusUpdate: deprecated, use configurationOptions.manualFinalStatusUpdate instead.
  • inputs: the array of inputs described above.

Here is a complete payload example, for a request uploading the files file_1 and attachment_1:

{
  "name": "custom-analysis-name", // optional
  "metadata": { // optional
    "inbox": "my_inbox_address@example.com",
    "ticket_id": "123456"
  },
  "configurationOptions": { // optional, as is each option
    "enableFileOperationSplit": false,
    "manualFinalStatusUpdate": false
  },
  "inputs": [
    {
      "type": "BODY",
      "contentType": "file",
      "file_key": "file_1"
    },
    {
      "type": "ATTACHMENT",
      "contentType": "file",
      "file_key": "attachment_1"
    }
  ]
}
Authorizations:
(Secret_KeyApp_ID) OAuth2
path Parameters
environmentId
required
integer <int64>

ID of the environment where the analysis must be created

Request Body schema:

Content and settings for this analysis

file
string <binary>
manualFinalStatusUpdate
boolean
Deprecated

Deprecated, use configurationOptions.manualFinalStatusUpdate in payload instead.

metadata
object

Metadata associated to the analysis. If you specify the inbox metadata, tools will be available to work with analysis coming from precises inboxes.

payload
string

A JSON Object encoded as a string which defines how to create an API.

  • inputs describes the inputs of the analysis. Usually, you don't touch this.
  • name allows overriding the name of the analysis. If not defined, it will use the filename of the BODY file
  • metadata defines the metadata associated to the analysis. Useful for integration purposes. If you specify the inbox metadata, tools will be available to work with analyses coming from precises inboxes.
  • configurationOptions changes how this analysis is processed: enableFileOperationSplit (default true) and manualFinalStatusUpdate (default false).
  • manualFinalStatusUpdate is deprecated, use configurationOptions.manualFinalStatusUpdate instead.
files*
additional property
string <binary>

The files you want to upload. The name of the field in the request payload (e.g., file or file1) must be specified in the inputs field of the payload parameter.

Responses

Request samples

Content type
No sample

Response samples

Content type
application/json
{
  • "id": "7f8e8725-221d-4128-bdb4-c655d0884ca8"
}

Get the result of an analysis

Get an analysis result according to a configured flow.

The result can be overridden by integrations, but unless explicitly told so, the result will contain the same payload sent to any webhook.

The payload is configured on Miralia.ai side. If the output misses some information you see here but is absent from the result, it might be a misconfiguration.

Authorizations:
(Secret_KeyApp_ID) OAuth2
path Parameters
analysisId
required
string

ID of the analysis

Responses

Response samples

Content type
application/json
Example

The analysis has finished, the result contains the same data as the webhook payload.

{
  • "status": "FINISHED",
  • "result": {
    }
}

Download a file from an analysis

Download the raw content of a document belonging to an analysis.

fileId accepts any document identifier found in fileOperations: both the id of a fileOperations entry (the resulting split or merged document) and the id of any of its sources (the original document(s) it was produced from) can be downloaded individually this way.

Authorizations:
(Secret_KeyApp_ID) OAuth2
path Parameters
analysisId
required
string

ID of the analysis

fileId
required
string <uuid>

ID of the document to download, taken from fileOperations[].id or fileOperations[].sources[].id in the analysis result.

Responses

Response samples

Content type
application/json
Example

No analysis matches this analysisId.

{
  • "code": 404,
  • "message": "Analysis not found"
}

Feedback

This route allows a user to send feedback on an analysis (a correction). Only categories, attachmentsCategories, extractedData, and rpaActions can be corrected; other fields are ignored. You can use feedbackURL in the result's payload to send a feedback on the analysis you queried.

/!\ Warning: submitting feedback replaces the entire feedback object stored on the analysis. Fields omitted from your payload are not preserved — fetch the analysis's current feedback first and resend it merged with your corrections if you want to keep them.

result must be a JSON object. Sending an empty one ({}, or []), or one whose fields are all null, clears the analysis's feedback. Any other array is rejected with a 400.

Authorizations:
(Secret_KeyApp_ID) OAuth2
path Parameters
analysisId
required
string
Request Body schema: application/json
object (feedback)

Feedback / correction payload for POST /analyses/{analysisId}/feedback.

Unlike the result payload, only a subset of fields can be corrected: categories, attachmentsCategories, extractedData, and rpaActions. Any other field is ignored.

Must be a JSON object. An empty object ({}, or []) clears the feedback; any other array is rejected with a 400.

Submitting this payload replaces the entire feedback object stored on the analysis, whether the previous feedback was entered manually in the console or sent via the API. Fields you omit are not preserved — fetch the analysis's current feedback first and merge it with your corrections if you want to keep them.

categories
Array of strings (categories)

Categories detected on the message body. Usually empty or a single-entry array, unless multi-label categorisation is configured. Some categories may be filtered out by environment configuration.

object (attachmentsCategories)

Categories detected per attachment file name.

Shape: { "<attachmentFileName>": ["<category>", ...] }.

object (extractedData)

Structured data extracted from the message and/or attachments. The exact keys depend on your extraction configuration.

Common shape: { "message": { ... }, "attachments": { "<fileName>": { ... } } }.

object

Corrections for RPA actions, keyed by action name.

Unlike the result payload's rpaActions (which lists triggered action names), the feedback shape carries, per action, two independent boolean assessments:

  • rpa_action_configurations: whether this action was expected to trigger.
  • rpa_action_executions: whether, given it did trigger, it was executed correctly.

Both keys are optional and independent; submit only the ones you want to qualify.

Shape: { "<actionName>": { "rpa_action_configurations"?: boolean, "rpa_action_executions"?: boolean } }.

Responses

Request samples

Content type
application/json
{
  • "result": {
    }
}

Response samples

Content type
application/json
Example

result is not a JSON object: a string, a number, a boolean, null, or a non-empty array such as ["Convocation"]. An empty array ([]) is accepted and clears the feedback, like {}.

{
  • "code": 400,
  • "message": "Field result must be an object"
}