# Address Migration

This guide covers the process of migrating address data using an API. Address migration allows users to import address data into their system from a migration file in CSV, XLS, or JSON format. The column names in the migration file must match the field names listed in the table below.

### Fields and Descriptions

#### User Data

| **Field Names** | **Data Type** | **Required** | **Descriptions**                                       |
| --------------- | ------------- | ------------ | ------------------------------------------------------ |
| user            | string        | true         | Customer Code of the user.                             |
| email           | string        | true         | The email of the user.                                 |
| phone\_number   | string        | false        | The phone number of the address                        |
| first\_name     | string        | true         | First name of the recipient (max 255 characters)       |
| last\_name      | string        | true         | Last name of the recipient (max 255 characters)        |
| title           | string        | false        | The address title (max 128 characters)                 |
| line            | string        | true         | The address line (max 255 characters)                  |
| tax\_office     | string        | false        | For legal entities                                     |
| tax\_no         | sting         | false        | For legal entities                                     |
| country         | sting         | true         | Must match the name in the database case-insensitively |
| city            | sting         | true         | Must match the name in the database case-insensitively |
| township        | string        | true         | Must match the name in the database case-insensitively |
| district        | string        | false        | Must match the name in the database case-insensitively |
| company\_name   | string        | false        | For legal entities                                     |

#### Parameters

| **Parameter**     | **Data Type** | **In** | **Descriptions**                                                  |
| ----------------- | ------------- | ------ | ----------------------------------------------------------------- |
| chanel\_id        | integer       | url    | The id of the shop channel                                        |
| \[api\_token]     | string        | header | The API key of the customer account                               |
| \[files]          | disct         | body   | The dictionary includes the file descriptor or the migration file |
| \[migration\_key] | string        | url    | The type of migration (user, address, order, order\_item etc.)    |

### `POST` Starting the Migration

**Path:** `/api/v1/remote/{channel_id}/migrations/start/{migration_key}`

To start the address migration, send a request to the /api/v1/remote/{channel\_id}/migrations/start/{migration\_key} endpoint and trigger the migration queue. In this case, set the migration key value to "address".

**Request**

```python
import requests
import json

url = "https://{customer_api_url}/api/v1/remote/{channel_id}/migrations/start/{migration_type}/"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"

headers = {
   'content-type': 'application/json',
   'Authorization': 'Token {}'.format(api_token)
}
files = {'file': open('/path/to/file/address.csv','rb')}
response = requests.post(url, headers=headers, files=files)
print(response.text)

```

**Response**

As a result of the request, a response with a 200 OK status code will be recieved, and it will contain the migration ID.

```js
{
  "migration_id":"4d6f7650799f484d875a89adf8d472b8"
}
```

### `GET` Checking Migration Progress

**Path:** `/api/v1/remote/{channel_id}/migrations/{migration_id}/progress/`

This method is used to check the progress of the migration by sending a request to the /api/v1/remote/{channel\_id}/migrations/{migration\_id}/progress/ endpoint, providing the parameters mentioned earlier.

**Request**

```python
import requests

url = "https://{customer_api_url}/api/v1/remote/{channel_id}/migrations/{migration_id}/progress/"
api_token = "f532eXXXXXXXXXXXXXXXXX201XXXXX9332d"

headers = {
   'content-type': 'application/json',
   'Authorization': 'Token {}'.format(api_token)
}

response = requests.get(url, headers=headers)
print(response.text)
```

**Response**

As a result of the request, a response with a 200 OK status code will be recieved, and it will contain the following values in the response body:

```js
{
  "Processed_count": 1000,
  "Error_count": 0,
  "total_count": 1000
}
```


---

# 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://apidocs.akinon.com/commerce/address-migration.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.
