# POST /foreign/import

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the foreign group.

Queue the import of a hosting account archive

- Who may call it: administrator, reseller
- Token scope, any of: users, all
- Answers: 202 Accepted

Returns 202 with the queued foreign-import job in job. The job checks for blocking conflicts and missing requirements before creating the account or restoring data. Use POST /foreign/inspect to preview those checks. The import uses the original account name unless you supply as. It preserves the login password when the archive has a SHA-512 crypt hash. The web interface replaces that hash on the first successful login. SFTP and FTP continue to accept the same password.

The import restores domains, subdomains, and aliases with their document roots and PHP versions. It unpacks the home directory with tar running as the customer. With the default paths value of rewrite, it updates references to the old home directory in .htaccess, .user.ini, and php.ini. Use leave to retain those references. The job lists files that still refer to the old home directory. It restores DNS zone records and updates records that point to the source server's IP address to point to this server's IP address.

The import loads database dumps into MariaDB as supplied and restores database users and grants. Use skip_databases to omit up to 100 databases by their names in the archive. The import also omits users associated only with skipped databases. The job log and import result identify the skipped databases. The import restores unexpired certificates that cover their domains. UrbeStack treats free certificates as its own and paid certificates as customer-provided. It restores FTP accounts, SSH keys, and cron jobs, and reports any FTP accounts skipped because FTP is unavailable.

The import restores mailboxes with their password hashes and quotas, forwarders, the default email address, autoresponders, DKIM keys under their original selectors, and webmail address books and identities. It applies the account's filters to every domain and restores each mailbox's own filters. It converts filters using heuristics and reports any it skips. It applies the account's hourly mail limit separately to each domain and routes mail for domains with external MX records to the servers those records specify. If the destination email address is available, the source account's own mailbox becomes a regular mailbox at <name>@<main domain>. Use default_mailbox to set a different local part.

The job logs each step, updates its progress percentage as steps finish, and runs one rebuild at the end. It stops at the first failure, reports which steps completed, and leaves any partially imported account in place.

Administrators and resellers need a token with the users scope. Other roles receive 403. Administrators provide an absolute server path in file. Resellers provide a path starting with /, which represents their home directory, and must own the archive. UrbeStack creates the account under the reseller, subject to their limits. Reseller paths are limited to 4096 characters and 255 characters per component. The API returns 400 for a missing or invalid file value, including reseller paths with control characters or a .. component. It also returns 400 for a paths value other than rewrite or leave, an invalid default_mailbox, or a malformed skip_databases list or name. UrbeStack converts default_mailbox to lowercase and accepts 1 to 64 ASCII letters, digits, periods, underscores, or hyphens, with a letter or digit at each end. Each name in skip_databases must contain 1 to 64 ASCII letters, digits, or underscores.

## As a command

- [urbestack-foreign-import](https://urbestack.com/docs/commands/urbestack-foreign-import.md): Imports a hosting account into UrbeStack from a pkgacct archive or a full backup downloaded from the customer's panel on the source server.

## Request body

JSON, the type [ForeignImportRequest](https://urbestack.com/docs/api/types/ForeignImportRequest.md).

- `file` (string, up to 4096 characters, required): Path to the archive. Administrators use an absolute path on the server. Resellers specify the path from the root of their home directory, for example /uploads/cpmove-ana.tar.gz.
- `as` (Username): Username to assign to the imported account. Defaults to the username in the archive.
- `default_mailbox` (string, matching ^[a-z0-9]([a-z0-9._-]{0,62}[a-z0-9])?$): Local part under the main domain for the source account's default mailbox, found at the top of mail/. Defaults to the account's username. If the email address is already in use, the mailbox stays in the home directory and the import report identifies it.
- `paths` (string, one of rewrite, leave): The value rewrite replaces the old home directory path with the new one in .htaccess, .user.ini and php.ini files. The value leave preserves the home directory contents and lists files that reference the old path. Any affected password-protected directory still references a missing password file.
- `skip_databases` (array of string, matching ^[A-Za-z0-9_]{1,64}$): Names of databases to omit from the import, for example to resolve a name conflict on this server. For each omitted database, UrbeStack skips its dump and any database user assigned solely to it. The import check, job log and job result record the omissions.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/foreign/import" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "as": "alice",
    "default_mailbox": "text",
    "file": "urbestack-panel-20260909T101500Z.json.enc",
    "paths": "rewrite",
    "skip_databases": [
      "text"
    ]
  }'
```

Response, 202 Accepted:

```
{
  "job": {
    "created_at": "2026-09-09T10:15:00Z",
    "created_by": 1,
    "created_by_name": "text",
    "dismissed_at": "text",
    "finished_at": "2026-09-09T10:15:04Z",
    "id": 1,
    "lane": "short",
    "log": "",
    "params": {},
    "progress": 100,
    "result": {},
    "started_at": "2026-09-09T10:15:01Z",
    "status": "queued",
    "type": "rebuild",
    "usual_seconds": 1
  }
}
```

## Errors

- 400: <what> climbs out of the home with ..
- 400: <what> has a name over 255 characters
- 400: <what> holds a control character
- 400: <what> is required
- 400: <what> is too long
- 400: <what> must start with /, which is the home
- 400: A new job is queued or running
- 400: Invalid <what>: 
- 400: Invalid username: 2 to 32 lowercase letters, digits or underscores, starting with a letter
- 400: Job parameters must be an object
- 400: The archive is named by its absolute path on the server
- 400: Unknown job type
- 400: Username '<value>' is reserved
- 400: default_mailbox is the local part of an address under the main domain
- 400: file is required
- 400: paths is rewrite or leave
- 400: skip_databases is a list of database names
- 400: skip_databases names databases as the archive names them
- 401: Authentication required
- 403: Insufficient privileges
- 404: User '<user>' not found
