# Updating a Request

After a request is created, it can be updated by the authorized parties. Each update requires a signature and is persisted to the Request Network.

## Summary of Actions

| Action                     | Description                                                       | Authorized Role              |
| -------------------------- | ----------------------------------------------------------------- | ---------------------------- |
| **accept**                 | Accept a request, indicating that it will be paid                 | Payer                        |
| **cancel**                 | Cancel a request                                                  | Payee or Payer               |
| **reduceExpectedAmount**   | Reduce the expected amount                                        | Payee                        |
| **increaseExpectedAmount** | Increase the expected amount                                      | Payer                        |
| **addStakeholders**        | Grant 1 or more third parties access to view an encrypted request | Payee, Payer, or Third Party |

## Examples

### Initialize the Request Client

First, retrieve the request you want to update. You must provide a `signatureProvider` to sign the update transactions.

```javascript
const { RequestNetwork, Types } = require("@requestnetwork/request-client.js");

const requestClient = new RequestNetwork({
  nodeConnectionConfig: { baseURL: "https://sepolia.gateway.request.network/" },
  signatureProvider: epkSignatureProvider, // Required for updates
});

const request = await requestClient.fromRequestId('YOUR_REQUEST_ID');
```

### Accept a Request (Payer)

The payer can accept a request to signal their intention to pay.

```javascript
const updatedRequestData = await request.accept({
  type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
  value: payerIdentity,
});

// Wait for the update to be persisted
await request.waitForConfirmation();
```

### Cancel a Request (Payee or Payer)

Either the payee or the payer can cancel a request.

```javascript
const updatedRequestData = await request.cancel({
  type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
  value: signerIdentity,
});

await request.waitForConfirmation();
```

### Increase Expected Amount (Payer)

The payer can increase the expected amount (e.g., adding a tip or adjusting for additional services).

```javascript
const updatedRequestData = await request.increaseExpectedAmountRequest(
  '100000000000000000', // Amount to add in base units (e.g., 0.1 ETH)
  {
    type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
    value: payerIdentity,
  }
);

await request.waitForConfirmation();
```

### Reduce Expected Amount (Payee)

The payee can reduce the expected amount (e.g., applying a discount).

```javascript
const updatedRequestData = await request.reduceExpectedAmountRequest(
  '100000000000000000', // Amount to subtract in base units
  {
    type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
    value: payeeIdentity,
  }
);

await request.waitForConfirmation();
```


---

# 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://legacy.docs.request.network/advanced/request-network-sdk/sdk-guides/request-client/updating-a-request.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.
