# Inserting data into a data source

### Inserting new data into a CSV Data Source

You can insert new data rows into a CSV data source on the fly within your simulation just as if your API were inserting data into real data source. The data is added for the duration that the service is running. When the service is restarted, the data will revert to what was in the original uploaded CSV.

For illustration we will use this data source called "pets":

| id   | category | name   | status    |
| ---- | -------- | ------ | --------- |
| 1000 | birds    | Archie | available |
| 1001 | dogs     | Zipper | available |
| 1002 | dogs     | Teddy  | sold      |

### Inserting data with {{csvAddRow}}

This method takes an array of strings as a parameter and adds them to the data source. You add to an array using the function {{addToArray}}. In the pets data source example there are 4 columns, and so you need to call it four times to create an array containing 4 strings.

The syntax for adding to, and reading from an array can be read [here](/create-simulations/using-templating-in-simulations/variables-and-arrays.md)

csvAddRow Syntax:

```handlebars
{{csvAddRow 'data-source-name' array-of-values}}
```

Template Example: Add a new dog to the data source

```handlebars
{{ addToArray 'newPet' '1003' false }} 
{{ addToArray 'newPet' 'dogs' false }} 
{{ addToArray 'newPet' 'Violet' false }} 
{{ addToArray 'newPet' 'available' false }}

{{ csvAddRow 'pets' (getArray 'newPet') }}
```

Result:

The new pet will be added to the pets data source in memory for all subsequent calls to the API simulation. It will be modified as follows:

| id   | category | name   | status    |
| ---- | -------- | ------ | --------- |
| 1000 | birds    | Archie | available |
| 1001 | dogs     | Zipper | available |
| 1002 | dogs     | Teddy  | sold      |
| 1003 | dogs     | Violet | available |

###


---

# 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.cloud.hoverfly.io/create-simulations/using-data-sources-in-simulations/inserting-data-into-a-data-source.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.
