# Endpoints for Documents

## Base URL for Document Endpoints

Access the server via `https://{processmaker-server}/api/1.0/connector-idp`.

## View Metadata of a Document&#x20;

<mark style="color:blue;">`GET`</mark> `https://`<mark style="color:green;">`{processmaker-server}`</mark>`/api/1.0/connector-idp/get-file/`<mark style="color:green;">`{id}`</mark>

See `200` status code response for cURL example and response example.

#### Path Parameters

<table><thead><tr><th width="147">Name</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>id<mark style="color:red;">*</mark></td><td>String</td><td>Unique ID for the document to find in the information document section of the IDP server.</td></tr></tbody></table>

{% tabs %}
{% tab title="200: OK " %}
Following is an example of getting a document metadata using the file id.

**cURL request:**

```
curl --location --request GET "https://processmaker.com/api/1.0/connector-idp/get-file/d72c9a40-8ef1-4c16-94c8-038cd9b80089"
```

**Example response:**

The request was okay and the response body contains the representation requested.

```json
{
  "data": {
    "type": "file",
    "attributes": {
      "createdAt": "2019-11-29T09:46:29.006+0000",
      "createdBy": "User",
      "documentType": "NONE",
      "modifiedAt": "2019-12-03T07:41:33.445+0000",
      "name": "Welcome to IDP.docx",
      "modifiedBy": null,
      "checkedOutBy": null,
      "id": "d72c9a40-8ef1-4c16-94c8-038cd9b80089",
      "content": 117350
    },
    "relations": {}
  },
  "status": "success",
  "message": null
}
```

{% endtab %}

{% tab title="Script Example" %}

1. [Create a Script](broken://spaces/09GreG9x1Y6qRGRu9MvR/pages/-LQzr3DVMRMidW8fKnwv) to get the metadata of the IDP file using a file id.
2. [Add a Script Task to your process model](broken://spaces/09GreG9x1Y6qRGRu9MvR/pages/-LT9pKy7tB1TxQM4u3Ro#add-a-script-task-element-to-the-process-model) and reference the created script.

{% code overflow="wrap" %}

```php
<?php 
/*  
 *  Welcome to ProcessMaker 4 Script Editor 
 *  To access Environment Variables use getenv("ENV_VAR_NAME") 
 *  To access Request Data use $data 
 *  To access Configuration Data use $config 
 *  To preview your script, click the Run button using the provided input and config data 
 *  Return an array and it will be merged with the processes data 
 *  Example API to retrieve user email by their ID $api->users()->getUserById(1)['email'] 
 *  API Documentation https://github.com/ProcessMaker/docker-executor-php/tree/master/docs/sdk 
 */

$start = microtime(true);
$guzzleClient = new \$GuzzleHttp\Client(['base_uri'=> getenv('API_HOST'),'verify' => false]);
$guzzleOptions['headers']['Accept'] = 'application/json';
$guzzleOptions['headers']['Authorization'] = 'Bearer'.getenv('API_TOKEN');

$guzzleApi = '/api/1.0/connector-idp/get-file/be74e981-f82c-data-b906-669724f0c37f';
$result = json_decode($guzzleClient->request('GET', $guzzleApi, $guzzleOptions)->getBody(),true)['data'];

return $result;
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Update Documents

<mark style="color:orange;">`PUT`</mark> `https://`<mark style="color:green;">`{processmaker-server}`</mark>`/api/1.0/connector-idp/update-file/`<mark style="color:green;">`{id}`</mark>

See `200` status code response for cURL example and response example.

#### Path Parameters

<table><thead><tr><th width="95">Name</th><th width="135">Type</th><th>Description</th></tr></thead><tbody><tr><td>id<mark style="color:red;">*</mark></td><td>String</td><td>Unique ID for the document to find in the information document section of the IDP server.</td></tr></tbody></table>

#### Request Body

<table><thead><tr><th width="104">Name</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td>data</td><td>JSON String</td><td>Attributes specified as key-value pairs. Check the example response to see the JSON structure to send</td></tr></tbody></table>

{% tabs %}
{% tab title="200: OK " %}
Here is an example of updating a file using the file id., where the file attributes are being updated.

**cURL request:**

{% code fullWidth="false" %}

```
curl --location --request PUT "https://processmaker.com/api/1.0/connector-idp/update-file/d72c9a40-8ef1-4c16-94c8-038cd9b80089"
```

{% endcode %}

**Example response:**

The request was okay and the response body contains the representation requested. The response contains all attributes of the updated document.

```
{
  "data": {
    "type": "file",
    "attributes": {
      "createdAt": "2023-12-03T12:47:06.960+0000",
      "createdBy": "User",
      "documentType": "NONE",
      "modifiedAt": "2023-12-05T12:47:06.960+0000",
      "name": "Welcome back to IDP.docx",
      "modifiedBy": "User2",
      "checkedOutBy": "User",
      "id": "d72c9a40-8ef1-4c16-94c8-038cd9b80089",
      "content": 125398,
      "parentId": null
    }
  },
  "status": "success",
  "message": null
}
```

{% endtab %}

{% tab title="Script Example" %}

* [Create a Script](broken://spaces/09GreG9x1Y6qRGRu9MvR/pages/-LQzr3DVMRMidW8fKnwv) to update the metadata (`fulltext`, `name`, `documentType`) of the IDP file using a file id.
* [Add a Script Task to your process model](broken://spaces/09GreG9x1Y6qRGRu9MvR/pages/-LT9pKy7tB1TxQM4u3Ro#add-a-script-task-element-to-the-process-model) and reference the created script.

{% code overflow="wrap" %}

```php
<?php 
/*  
 *  Welcome to ProcessMaker 4 Script Editor 
 *  To access Environment Variables use getenv("ENV_VAR_NAME") 
 *  To access Request Data use $data 
 *  To access Configuration Data use $config 
 *  To preview your script, click the Run button using the provided input and config data 
 *  Return an array and it will be merged with the processes data 
 *  Example API to retrieve user email by their ID $api->users()->getUserById(1)['email'] 
 *  API Documentation https://github.com/ProcessMaker/docker-executor-php/tree/master/docs/sdk 
 */

$start = microtime(true);
$guzzleClient = new \$GuzzleHttp\Client(['base_uri'=> getenv('API_HOST'),'verify' => false]);
$guzzleOptions['headers']['Accept'] = 'application/json';
$guzzleOptions['headers']['Authorization'] = 'Bearer'.getenv('API_TOKEN');

$guzzleOptions['json'] = [
    "attributes" => [
        "fulltext" => "Hello World",
        "name" => "Finance Invoice",
        "documentType" => "Invoice"
    ]
];

$guzzleApi = '/api/1.0/connector-idp/get-file/be74e981-f82c-data-b906-669724f0c37f';
$result = json_decode($guzzleClient->request('GET', $guzzleApi, $guzzleOptions)->getBody(),true)['data'];

return $result;
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://processmaker.gitbook.io/idp/idp-developer/endpoints-for-documents.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
