> ## Documentation Index
> Fetch the complete documentation index at: https://developers.circularo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 4. Sign and Share in One Step

> [!WARNING]
>
> You are viewing the documentation of release 26.1, which is no longer the current one. [Go to the documentation of the current release 26.2](https://developers.circularo.com/).

## Sign and Share in One Step

This scenario demonstrates how to sign a document and share it for signature with another user in a single API call. This efficient workflow combines two common operations - applying your own signature and requesting signatures from others.

**Key features:**

* Apply your own signature to a document
* Simultaneously request signatures from other users
* Position signatures precisely on the document
* Streamline multi-party signing workflows

### Prerequisites

Before using this combined sign and share workflow, you need:

* A valid authentication token (see the "Authentication & Security" section for details)
* A document to sign and share (see the "Document Management" section for details)
* A signature image
* Knowledge of the recipients you want to request signatures from

> [!NOTE]
>
> This approach is ideal for contracts and agreements that require multiple signatures, allowing you to apply your signature and request others' signatures in a single operation.

## Step 1 - Sign Document and Request Signature

This endpoint demonstrates how to sign a document yourself and simultaneously request a signature from another user. This combined operation streamlines the signing workflow by reducing the number of API calls needed.

* Your signature is applied to the document immediately
* A signature request is sent to the specified recipient
* Both signatures are positioned precisely on the document
* The document's status is updated to reflect that it has been partially signed
* The recipient is notified of the signature request

> [!NOTE]
>
> The `signatures` array contains your own signature that will be applied immediately, while the `signatureFields` array defines where the recipient's signature should be placed.

**Endpoint**

```http theme={null}
POST /share
```

**Request**

```http theme={null}
POST /share?token=VZguf1TmBWzPpqe0NSljqeu1pgMCdoJCkokV30AVyqqpUnb2mfZR1ZFzIp5syIj4

Content-Type: application/json

{
  "id": "85454852-63ed-42f2-a914-2232f272a377",
  "type": "d_default",
  "objectType": "document",
  "data": [
    {
      "sharePurpose": "sign",  //Recipient who will be requested to sign
      "shareTo": "derek.trotter@circularo.com"
    }
  ],
  "signatureFields": [  //Defines where the recipient's signature should be placed
    {
      "user": [
        "derek.trotter@circularo.com"
      ],
      "timestamp": false,
      "required": true,
      "type": "signature",
      "pages": [
        1
      ],
      "position": {
        "percentX": 0.2,
        "percentY": 0.6,
        "percentWidth": 0.4,
        "percentHeight": 0.1
      }
    }
  ],
  "signatures": [  //Your own signature to be applied immediately
    {
      "type": "signature",
      "blob": "EzwFksYOXGjjdNzZkKVQmI4TrlvM2iHdKC9Kdb2rSvAF6ayQGanaK4jJ0JYdOqfZ",
      "pages": [
        1
      ],
      "position": {
        "percentX": 0.5,
        "percentY": 0.3,
        "percentWidth": 0.4,
        "percentHeight": 0.1
      }
    }
  ]
}
```

**Response**

```json theme={null}
[
  {
    "shareId": "xLvDvURXRxbSkctyQ3iT",
    "isActive": true,
    "isPermanentViewToken": false,
    "shareDate": "2023-07-20T14:04:36.186Z",
    "shareType": "sign",
    "sharedBy": "mary.griffin@circularo.com",
    "sharedObjectEsId": "85454852-63ed-42f2-a914-2232f272a377",
    "sharedObjectEsType": "d_default",
    "sharedObjectType": "document",
    "sharedWith": [
      "derek.trotter@circularo.com"
    ],
    ...
  }
]
```

The document has been successfully signed by you and shared with the recipient for their signature. The recipient will receive a notification about the signature request.

* Your signature has been applied to the document at the specified position
* The document's status has been updated to reflect that it has been partially signed
* A signature request has been sent to the recipient
* The recipient can access the document through their Circularo dashboard or via the link in the notification

## Step 2 - Check Document Share Status *(Optional)*

This endpoint demonstrates how to check the status of a document share. This is useful for monitoring the progress of signature requests and determining whether recipients have completed their actions.

* Retrieves the current status of the document share
* Shows whether the share is in progress, completed, cancelled, rejected, or expired
* Helps track the workflow progress of shared documents
* Allows you to take appropriate actions based on the share status

**Endpoint**

```http theme={null}
GET /documents/85454852-63ed-42f2-a914-2232f272a377
```

**Request**

```http theme={null}
GET /documents/85454852-63ed-42f2-a914-2232f272a377?token=VZguf1TmBWzPpqe0NSljqeu1pgMCdoJCkokV30AVyqqpUnb2mfZR1ZFzIp5syIj4
```

**Response**

```json theme={null}
{
  "results": [
    {
      "documentId": "85454852-63ed-42f2-a914-2232f272a377",
      "documentType": "d_default",
      "isSigned": true,
      "workflow": {
        "shareStateName": "inprogress",
        ...
      },
      ...
    }
  ]
}
```

The response contains the following important properties:

* **shareStateName** - Located at `results[0].workflow.shareStateName` in the response.
  * The current status of the document share.
  * Example value: `inprogress`

The document details have been successfully retrieved, including the share status.

* **inprogress**: The share is active and waiting for recipient action
* **completed**: All required signatures or approvals have been collected
* **cancelled**: The share was cancelled by the document owner
* **rejected**: The recipient rejected the signature or approval request
* **expired**: The share has expired without being completed

> [!NOTE]
>
> Use this status information to determine when to send reminders, when to consider a workflow complete, or when to initiate alternative processes if a share was rejected or expired.

***

## Sign and Share Summary

You have successfully signed a document and requested a signature from another user in a single operation. This combined workflow streamlines the signing process by reducing the number of API calls needed.

### Key Concepts

* **Combined Workflow**: Applying your signature and requesting others' signatures in a single API call
* **Signature Positioning**: Precisely placing signatures at specific locations on the document
* **Signature Fields**: Defining where recipients' signatures should be placed
* **Signature Application**: Applying your own signature immediately while requesting others'
* **Share Status Monitoring**: Checking the progress and state of signature requests

### Next Steps

With your document signed and shared, you can now:

* Monitor the status of the signature request (inprogress, completed, cancelled, rejected, or expired)
* Send reminders to the recipient if they haven't signed yet
* Download the fully signed document once all signatures are collected
* Explore more complex signing workflows with multiple recipients and sequential signing

### Example Implementation

> [!NOTE]
>
> See our OpenAPI documentation to learn about the full set of API endpoints and parameters.

> [!NOTE]
>
> Please use proper exception handling and function decomposition in your own code. The code is provided for illustrative purposes only and is not intended for production use.

```javascript theme={null}
// Sign document and request signature in one step
const URL = "https://sandbox.circularo.com";
const API_PATH = "/api/v1";
const TOKEN = "YOUR_AUTH_TOKEN"; // Obtained from login or API key
const DOCUMENT_ID = "YOUR_DOCUMENT_ID"; // ID of the document to sign and share
const DOCUMENT_TYPE = "d_default"; // Type of the document
const SIGNATURE_IMAGE_ID = "YOUR_SIGNATURE_IMAGE_ID"; // ID of your signature image
const RECIPIENT_EMAIL = "recipient@example.com"; // Email of the person who should sign

try {
    // Sign document and request signature in one step
    const signAndShareResponse = await fetch(`${URL}${API_PATH}/share?token=${TOKEN}`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            id: DOCUMENT_ID,
            type: DOCUMENT_TYPE,
            objectType: "document",
            data: [
                {
                    sharePurpose: "sign",
                    shareTo: RECIPIENT_EMAIL
                }
            ],
            // Define where the recipient's signature should be placed
            signatureFields: [
                {
                    user: [RECIPIENT_EMAIL],
                    timestamp: false,
                    required: true,
                    type: "signature",
                    pages: [1],
                    position: {
                        percentX: 0.2,
                        percentY: 0.6,
                        percentWidth: 0.4,
                        percentHeight: 0.1
                    }
                }
            ],
            // Your own signature to be applied immediately
            signatures: [
                {
                    type: "signature",
                    blob: SIGNATURE_IMAGE_ID,
                    pages: [1],
                    position: {
                        percentX: 0.5,
                        percentY: 0.3,
                        percentWidth: 0.4,
                        percentHeight: 0.1
                    }
                }
            ]
        })
    });
    if (!signAndShareResponse.ok) {
        throw new Error(`Sign and share failed: ${signAndShareResponse.status} ${signAndShareResponse.statusText}`);
    }

    const signAndShareData = await signAndShareResponse.json();
    console.log(`Document signed and shared for signature with ${RECIPIENT_EMAIL}`);
    console.log(`Share ID: ${signAndShareData[0].shareId}`);

    // Check document status and share state (Optional)
    const documentStatusResponse = await fetch(`${URL}${API_PATH}/documents/${DOCUMENT_ID}?token=${TOKEN}`);
    if (!documentStatusResponse.ok) {
        throw new Error(`Failed to get document status: ${documentStatusResponse.status} ${documentStatusResponse.statusText}`);
    }

    // Check the share status
    const documentData = await documentStatusResponse.json();
    const shareStatus = documentData.results[0].workflow.shareStateName;
    console.log(`Share status: ${shareStatus}`);

    // Take action based on share status
    switch(shareStatus) {
        case "inprogress":
            console.log("The share is active and waiting for recipient action");
            break;
        case "completed":
            console.log("All required signatures have been collected");
            break;
        case "cancelled":
            console.log("The share was cancelled by the document owner");
            break;
        case "rejected":
            console.log("The recipient rejected the signature request");
            break;
        case "expired":
            console.log("The share has expired without being completed");
            break;
        default:
            console.log(`Unknown share status: ${shareStatus}`);
    }

} catch (error) {
    console.error('Error in sign and share workflow:', error.message);
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.