> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.wbudget.app/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.wbudget.app/_mcp/server.

# Editar item da oportunidade

PUT https://wbudget.app/api/v1/api/v1/budgets/{id}/items/{itemId}
Content-Type: application/json

Edita uma linha de item da oportunidade.

**Autenticação:** Bearer Token da API WBudget. O acesso aos dados respeita as permissões do usuário.

Esta operação substitui os dados da linha: envie todos os valores que deseja manter, obtidos na listagem de itens. itemId identifica a linha da oportunidade; item identifica o produto ou serviço. Retorna o objeto de itens atualizado.

### Parâmetros de caminho

| Campo    | Tipo    | Obrigatório | Descrição                    |
| -------- | ------- | ----------- | ---------------------------- |
| `id`     | integer | Sim         | ID da oportunidade.          |
| `itemId` | integer | Sim         | ID da linha da oportunidade. |

### Corpo da requisição

| Campo          | Tipo    | Obrigatório | Descrição                                                                                                                            |
| -------------- | ------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `item`         | integer | Não         | ID do produto ou serviço vinculado à linha.                                                                                          |
| `qty`          | number  | Não         | Quantidade; padrão 1.                                                                                                                |
| `value`        | number  | Não         | Preço unitário; padrão 0.                                                                                                            |
| `description`  | string  | Não         | Descrição; padrão vazio.                                                                                                             |
| `order`        | integer | Não         | Ordem da linha; padrão 0.                                                                                                            |
| `discount`     | number  | Não         | Desconto monetário da linha, não percentual. Ex.: qty=2, value=100 e discount=10 resultam em 190 antes de outros ajustes comerciais. |
| `group`        | string  | Não         | Grupo da linha.                                                                                                                      |
| `title`        | string  | Não         | Título da linha.                                                                                                                     |
| `cost`         | number  | Não         | Custo, conforme permissões.                                                                                                          |
| `tax`          | number  | Não         | Tributo conforme a configuração comercial.                                                                                           |
| `metadata`     | object  | Não         | Campos personalizados da linha.                                                                                                      |
| `changed_cols` | string  | Não         | Campos alterados, separados por vírgula; padrão value,qty,discount.                                                                  |

### Exemplo de JSON enviado

```json
{
  "item": 501,
  "qty": 2,
  "value": 100,
  "description": "Serviço de implantação",
  "order": 1,
  "discount": 10,
  "group": "Serviços",
  "title": "Implantação",
  "cost": 0,
  "tax": 0,
  "metadata": {},
  "changed_cols": "value,qty,discount"
}
```

### Resposta

HTTP **200**. Os exemplos usam dados fictícios e mostram os campos principais; outros campos podem acompanhar a resposta. Campos sem valor podem ser nulos.

Campos principais de `data`:

| Campo                 | Tipo            | Descrição                                                   |
| --------------------- | --------------- | ----------------------------------------------------------- |
| `items`               | array\<object>  | Linhas da proposta.                                         |
| `items[].id`          | integer         | ID da linha usado em itemId.                                |
| `items[].item`        | integer         | ID do produto ou serviço.                                   |
| `items[].name`        | string          | Nome do produto ou serviço.                                 |
| `items[].qty`         | number          | Quantidade.                                                 |
| `items[].value`       | number          | Preço unitário.                                             |
| `items[].discount`    | number          | Desconto monetário da linha.                                |
| `items[].total_value` | number          | Valor total da linha.                                       |
| `items[].include`     | integer         | 1 inclui a linha no total.                                  |
| `items[].active`      | integer         | 1 indica linha ativa.                                       |
| `items[].item_type`   | string          | Tipo, como product ou service.                              |
| `items[].item_unit`   | string          | Unidade do item.                                            |
| `items[].description` | string          | Descrição; pode conter texto formatado serializado em JSON. |
| `items[].metadata`    | object ou array | Campos personalizados.                                      |
| `items_active_value`  | number          | Soma dos valores das linhas ativas incluídas no total.      |
| `items_total_time`    | number          | Soma de horas dos serviços com unidade hour.                |

```json
{
  "data": {
    "items": [
      {
        "id": 5001,
        "item": 501,
        "name": "Implantação",
        "qty": 2,
        "value": 100,
        "discount": 10,
        "total_value": 190,
        "active": 1,
        "include": 1,
        "item_type": "service",
        "item_unit": "un",
        "description": null,
        "metadata": []
      }
    ],
    "items_active_value": 190,
    "items_total_time": 0
  }
}
```

### Erros específicos

| HTTP | Código                   | Situação                           |
| ---- | ------------------------ | ---------------------------------- |
| 400  | `BUDGET_ITEM_SET_FAILED` | Não foi possível atualizar o item. |

Consulte a introdução da collection para o formato de erros e a configuração das variáveis.

Reference: https://developers.wbudget.app/w-budget/oportunidades/editar-item-da-oportunidade

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Path parameters

- `id` (string, required) — ID da oportunidade.
- `itemId` (string, required) — ID da linha da oportunidade.

### Body (application/json)

This endpoint expects an object.

- `item` (integer, required)
- `qty` (integer, required)
- `value` (integer, required)
- `description` (string, required)
- `order` (integer, required)
- `discount` (integer, required)
- `group` (string, required)
- `title` (string, required)
- `cost` (integer, required)
- `tax` (integer, required)
- `metadata` (object, required)
- `changed_cols` (string, required)

## Response

### 200

OK

- `data` (object, required)
  - `items` (list of object, required)
    - `id` (integer, required)
    - `item` (integer, required)
    - `name` (string, required)
    - `qty` (integer, required)
    - `value` (integer, required)
    - `discount` (integer, required)
    - `total_value` (integer, required)
    - `active` (integer, required)
    - `include` (integer, required)
    - `item_type` (string, required)
    - `item_unit` (string, required)
    - `metadata` (list of any, required)
    - `description` (any, optional)
  - `items_active_value` (integer, required)
  - `items_total_time` (integer, required)

## Errors

### 400 Bad Request Error

Bad Request

- `error` (object, required)
  - `message` (string, required)
  - `code` (string, required)

## Examples

**Request**

```json
{
  "item": 501,
  "qty": 2,
  "value": 100,
  "description": "Serviço de implantação",
  "order": 1,
  "discount": 10,
  "group": "Serviços",
  "title": "Implantação",
  "cost": 0,
  "tax": 0,
  "changed_cols": "value,qty,discount"
}
```

**Response**

```json
{
  "data": {
    "items": [
      {
        "id": 5001,
        "item": 501,
        "name": "Implantação",
        "qty": 2,
        "value": 100,
        "discount": 10,
        "total_value": 190,
        "active": 1,
        "include": 1,
        "item_type": "service",
        "item_unit": "un",
        "metadata": []
      }
    ],
    "items_active_value": 190,
    "items_total_time": 0
  }
}
```

**SDK Code**

```python Oportunidades_Editar item da oportunidade_example
import requests

url = "https://wbudget.app/api/v1/api/v1/budgets/1001/items/5001"

payload = {
    "item": 501,
    "qty": 2,
    "value": 100,
    "description": "Serviço de implantação",
    "order": 1,
    "discount": 10,
    "group": "Serviços",
    "title": "Implantação",
    "cost": 0,
    "tax": 0,
    "changed_cols": "value,qty,discount"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.json())
```

```javascript Oportunidades_Editar item da oportunidade_example
const url = 'https://wbudget.app/api/v1/api/v1/budgets/1001/items/5001';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"item":501,"qty":2,"value":100,"description":"Serviço de implantação","order":1,"discount":10,"group":"Serviços","title":"Implantação","cost":0,"tax":0,"changed_cols":"value,qty,discount"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Oportunidades_Editar item da oportunidade_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://wbudget.app/api/v1/api/v1/budgets/1001/items/5001"

	payload := strings.NewReader("{\n  \"item\": 501,\n  \"qty\": 2,\n  \"value\": 100,\n  \"description\": \"Serviço de implantação\",\n  \"order\": 1,\n  \"discount\": 10,\n  \"group\": \"Serviços\",\n  \"title\": \"Implantação\",\n  \"cost\": 0,\n  \"tax\": 0,\n  \"changed_cols\": \"value,qty,discount\"\n}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Oportunidades_Editar item da oportunidade_example
require 'uri'
require 'net/http'

url = URI("https://wbudget.app/api/v1/api/v1/budgets/1001/items/5001")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"item\": 501,\n  \"qty\": 2,\n  \"value\": 100,\n  \"description\": \"Serviço de implantação\",\n  \"order\": 1,\n  \"discount\": 10,\n  \"group\": \"Serviços\",\n  \"title\": \"Implantação\",\n  \"cost\": 0,\n  \"tax\": 0,\n  \"changed_cols\": \"value,qty,discount\"\n}"

response = http.request(request)
puts response.read_body
```

```java Oportunidades_Editar item da oportunidade_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://wbudget.app/api/v1/api/v1/budgets/1001/items/5001")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"item\": 501,\n  \"qty\": 2,\n  \"value\": 100,\n  \"description\": \"Serviço de implantação\",\n  \"order\": 1,\n  \"discount\": 10,\n  \"group\": \"Serviços\",\n  \"title\": \"Implantação\",\n  \"cost\": 0,\n  \"tax\": 0,\n  \"changed_cols\": \"value,qty,discount\"\n}")
  .asString();
```

```php Oportunidades_Editar item da oportunidade_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://wbudget.app/api/v1/api/v1/budgets/1001/items/5001', [
  'body' => '{
  "item": 501,
  "qty": 2,
  "value": 100,
  "description": "Serviço de implantação",
  "order": 1,
  "discount": 10,
  "group": "Serviços",
  "title": "Implantação",
  "cost": 0,
  "tax": 0,
  "changed_cols": "value,qty,discount"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Oportunidades_Editar item da oportunidade_example
using RestSharp;

var client = new RestClient("https://wbudget.app/api/v1/api/v1/budgets/1001/items/5001");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"item\": 501,\n  \"qty\": 2,\n  \"value\": 100,\n  \"description\": \"Serviço de implantação\",\n  \"order\": 1,\n  \"discount\": 10,\n  \"group\": \"Serviços\",\n  \"title\": \"Implantação\",\n  \"cost\": 0,\n  \"tax\": 0,\n  \"changed_cols\": \"value,qty,discount\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Oportunidades_Editar item da oportunidade_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "item": 501,
  "qty": 2,
  "value": 100,
  "description": "Serviço de implantação",
  "order": 1,
  "discount": 10,
  "group": "Serviços",
  "title": "Implantação",
  "cost": 0,
  "tax": 0,
  "changed_cols": "value,qty,discount"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://wbudget.app/api/v1/api/v1/budgets/1001/items/5001")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```