# \_import

Imports a Stock file.

### Parameters

#### map

An array of instructions for importing types of Stock data.

#### rows

An array of all the data of the Stock file.

### Example

```
FM_api('Stocks_import', [
    'map' => '[
               {"from":"ID","to":"id","filter":"","options":"","idx":0},
               {"from":"Name","to":"name","filter":"","options":"","idx":0},
               {"from":"Code","to":"code","filter":"","options":"","idx":0},
               {"from":"Description","to":"description","filter":"","options":"","idx":0},
               {"from":"Supplier","to":"supplier_id","filter":"","options":"","idx":0},
               {"from":"Cost","to":"cost","filter":"","options":"","idx":0},
               {"from":"Price","to":"price","filter":"","options":"","idx":0},
               {"from":"Amount","to":"amount","filter":"","options":"","idx":0},
               {"from":"Notes","to":"notes","filter":"","options":"","idx":0},
               {"from":"Location Tags","to":"location_tags","filter":"","options":"","idx":0},
               {"from":"Nominal Code","to":"nominal_code","filter":"","options":"","idx":0},
               {"from":"Tax Rate","to":"tax_rate","filter":"","options":"","idx":0},
               {"from":"Category","to":"stock_categories","filter":"","options":"","idx":0},
               {"from":"Status","to":"is_archived","filter":"","options":"","idx":0},
               {"from":"Price Bands","to":"price_bands","filter":"","options":"","idx":0},
               {"from":"Manufacturer","to":"manufacturer","filter":"","options":"","idx":0},
               {"from":"EAN/Barcode","to":"barcode","filter":"","options":"","idx":0},
               {"from":"Manufacturer Part No","to":"manufacturer_part_no","filter":"","options":"","idx":0},
               {"from":"Supplier Part No","to":"supplier_part_no","filter":"","options":"","idx":0}
              ]',
    'rows' => '[
                [
                "577389",
                "test name",
                "test code",
                "test description",
                "488043",
                "1.11",
                "1.1200",
                "89",
                "test notes",
                "location_tag location_tag2",
                "12345",
                "99.00",
                "test category",
                "",
                "",
                "test manufacturer",
                "123456",
                "12",
                "34"
                ]
               ]'
        ]
);
```

### Results

#### On Success

```
{"ok":1,"errors":""}
```

#### On Failure

If the "map" parameter is not set:

```
{"error":"missing or invalid parameter: map"}
```

If the "rows" parameter is not set:

```
{"error":"missing or invalid parameter: rows"}
```

If the name of the imported Stock is longer than 80 characters:

```
{"ok":1,"errors":[[0,[{"msg":"Name too long. Max length 80","val":"new nameiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"}]]]}
```

If the name of the imported Stock's manufacturer is longer than 80 characters:

```
{"ok":1,"errors":[[0,[{"msg":"Manufacturer name too long. Max length 80","val":"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"}]]]}
```

If the "rows" parameter is missing an ID, name and code: (Only if all 3 are missing)

```
{"ok":1,"errors":[[0,[{"msg":"Row does not contain ID, name or code","val":""}]]]}
```

If the stock ID within the "rows" parameter does not match an existing Stock:

```
{"ok":1,"errors":["unable to update stock id 123 - invalid id"]}
```


---

# 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://docs.fieldmotion.com/fieldmotion-api-docs/stocks/_import.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.
