Integrating IDP with Anypoint Studio | MuleSoft Documentation
# Integrating IDP with Anypoint Studio
Execute a published document action and retrieve the results from Anypoint Studio using that document action’s IDP Runtime Service API connector. This connector generates automatically when you publish a document action to Anypoint Exchange. Then, you can download it as a Mule connector from Exchange.
Each document action version generates a different connector. For example, when you publish a document action for the first time, it generates a connector in Exchange that executes version `1.0.0` of this document action. Then, if you modify the document action and republish it as version `1.1.0`, it generates a different connector that you must download and install in Studio to execute this new document action version. Consider this behavior when building your integrations.
The IDP Runtime Service API connector has the following operations:
  * **getDocumentActionExecution**
Retrieves the result of a document action execution.
  * **postDocumentActionExecution**
Submits a document to IDP for processing.


## Before You Begin
Ensure you have the following Anypoint permissions: 

Execute Published Actions
    
Enables a user to execute a published document action and retrieve the results of the execution.
If you already have a connected app configured for IDP, you don’t need the **Configure Connected Apps** permission and you can use your existing connected app instead of creating a new one.
## Create a Connected App
To communicate with the IDP API, create a connected app with the following details:
  * Type: `App acts on its own behalf (client credentials)`
  * Scopes: `Execute Published Actions`


After you create the connected app, copy its **ID** and **Secret** for further use.
For more information, see Secure API Integration with Connected Apps.
## Obtain the Access Token
After you configure the connected app, use the following `curl` command to get the token:
```
curl --location --request POST 'https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token' \ **(1)**
--header 'Content-Type: application/json' \
--data-raw '{
 "grant_type": "client_credentials",
 "client_id": "<connected-app-client-id>", **(2)**
 "client_secret": "<connected-app-client-secret>" **(3)**
}'
```

If you are in the EU region, use the `eu1.anypoint.mulesoft.com` domain.  
---  
Replace `<connected-app-client-id>` with the client ID from your connected app.  
Replace `<connected-app-client-secret>` with the client secret from your connected app.  
Use the access token when calling the IDP API.
## Configure the IDP Runtime Service API Connector
Before using its operations, configure the connector by providing the following values, either manually or through a Global Configuration Element:
  * **host** : Anypoint endpoint URL
For example: `idp-rt.{region}.anypoint.mulesoft.com`
  * **port** : HTTP port for the connection
For example: `443`
  * **basePath** : Base path of the URL to call, without the protocol
  * **protocol** : Protocol for the call, in uppercase
For example: `HTTPS`
  * **Response timeout** : Response timeout for this operation
  * **clientId** : Client ID of the connected app to call IDP
  * **clientSecret** : Client Secret of the connected app to call IDP
  * **accessTokenUrl** : URL to obtain the access token for your connected app
For example: `https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token`


## Submit a Document to IDP
Use the **postDocumentActionExecution** operation to send a document to IDP and execute the corresponding document action version.
Specify the details of the request in the **Postdocumentactionexecution request data** field of the connector. The following is a sample request:
```
%dw 2.0
output multipart/form-data
---
{
  parts : {
  	 callback : {
  	 	 headers : {
        "Content-Type" : "text/plain"
        },
      content : '{"noAuthUrl": "https://{yourCallbackURL}.com"}'
    },
    file : {
      headers : {
        "Content-Disposition" : {
          "name": "file",
          "filename": "{myFile.jpg}",
          "subtype": "form-data"
          },
        "Content-Type" : "image/jpg"
        },
      content : payload
      }
    }
}
```

The response from this operation contains the execution ID that you must use to retrieve the execution results.
## Retrieve the Results of the Execution
Use the **getDocumentActionExecution** operation to get the results of a document action execution by specifying its execution ID.
The following is a sample response from this operation, shortened for better readability:
```
{
  "id": "d68e099e-8d37-4188-905a-0eac68b7bf61",
  "documentName": "invoice-1.jpg",
  "status": "SUCCEEDED",
  "pages": [
    {
      "page": 1,
      "fields": {
        "invoiceDate": {
          "value": "1 June, 1983"
        },
        "invoiceNumber": {
          "value": "8248"
        }
        ...
      },
      "tables": {
        "table1": [
          {
            "unitPrice": {
              "value": ""
            },
            "price": {
              "value": "$ 198.00"
            }
            ...
          }
        ]
      },
      "prompts": {
        "business": {
          "prompt": "what is the company main business",
          "source": "document",
          "answer": {
            "value": null
          }
        }
      }
    }
  ]
}
```

## See Also
  * Analyzing Documents Using Pre-Built Schemas
  * Publishing Document Actions