> For the complete documentation index, see [llms.txt](https://docs.scraperapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scraperapi.com/ai-parser/endpoints/update-a-parser.md).

# Update a Parser

Modifiy an existing parser's fields. Some changes generate a new version asynchronously, others are applied immediately.

```bash
PATCH https://aiparser.scraperapi.com/parsers/{parser_id}/{version}
```

#### **When to use this endpoint**

You have an existing parser, ran a few `/parse` calls, but the output isn't quite right:

* A field you want is missing → use `add_fields`.
* A field is being extracted wrong → use `modify_fields` with clearer description.
* A field name is awkward → use `rename_fields`.
* A field is no longer relevant → use `remove_fields`.

You can do any combination in a **single** request

**Request body**

```json
{
  "api_key": "API_KEY",
  "add_fields": [
    { "name": "products.discount", "description": "Discount percentage as a number", "type": "number" }
  ],
  "modify_fields": [
    { "name": "price", "description": "Price in USD as a number, no currency symbol", "type": "number" }
  ],
  "rename_fields": [
    { "name": "products.name", "new_name": "products.title" }
  ],
  "remove_fields": ["obsolete_field"]
}
```

Only `api_key` is required. Include *only* the operations you need.

**Response**

<table><thead><tr><th width="153.44451904296875">Status</th><th width="413.2962646484375">When</th><th>Body</th></tr></thead><tbody><tr><td><code>200 OK</code></td><td>Only <code>rename_fields</code> and/or <code>remove_fields</code> were sent - changes apply immediatelly.</td><td>New version number</td></tr><tr><td><code>202 Accepted</code></td><td><code>add_fields</code> or <code>modify_fields</code> were sent - a new version is generating asynchronously.</td><td>New version number</td></tr></tbody></table>

{% hint style="info" %}
After a `202`, poll `GET /parsers/{id}` until status is `FINISHED` before parsing with the new version.
{% endhint %}

#### **Step-by-step Example**

Suppose you create a parser and you get `version: 0`, but notice that the price field is being returned as string that includes the `$` symbol. Here's how you would clean up the field and update the parser, so the price is returned in a more usable numeric format:

```bash
# Run the parser first
curl "https://aiparser.scraperapi.com/parse/<PARSER_ID>?api_key=API_KEY&url=URL"
# { "price": "$1,212.02" } - string with currency symbol

# PATCH with a clearer description
curl -X PATCH https://aiparser.scraperapi.com/parsers/<PARSER_ID> \
  -H "Content-Type: application/json" \
  -d '{
    "api_key": "API_KEY",
    "modify_fields": [
      { "name": "price", "description": "Price in USD as a number, excluding currency symbols and commas", "type": "number" }
    ]
  }'
# 202 Accepted - { "version": 1 }

# Wait for FINISHED status
curl "https://aiparser.scraperapi.com/parsers/<PARSER_ID>/1?api_key=API_KEY"

# Re-run with the new version
curl "https://aiparser.scraperapi.com/parse/<PARSER_ID>/1?api_key=API_KEY&url=URL"
# { "price": 1212.02 } - now returned as number
```

**Field definition reference**

Each entry in `add_fields` and `modify_fields` supports

<table><thead><tr><th width="173.74078369140625">Property</th><th width="117.8885498046875">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td>Yes</td><td>Field name. Use dot notation for nested fields (e.g. <code>products.images.url</code>)</td></tr><tr><td><code>description</code></td><td>Yes</td><td>Field description. The more specific - the better the results.</td></tr><tr><td><code>type</code></td><td>No</td><td><code>string</code>, <code>number</code> or <code>array</code>.</td></tr><tr><td><code>selector</code></td><td>No</td><td>CSS or XPATH selector.</td></tr></tbody></table>

{% hint style="success" %}
`selectors` are optional, but they often produce more reliable results.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://docs.scraperapi.com/ai-parser/endpoints/update-a-parser.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.
