> For the complete documentation index, see [llms.txt](https://docs.collibra.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.collibra.com/data-quality-self-hosted/apis/rest/code-migration-using-product-apis.md).

# Code Migration using Product APIs

> This document describes the process of migrating Collibra Data Quality code across environments using Product APIs. It supports both pushdown and pullup datasets.

{% hint style="info" %}
You must be logged in to Collibra Data Quality & Observability in order to access the Swagger API. Open Swagger from either the Admin Console or by clicking the <img src="https://4121921244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWCrP7Albs8DfJjIQxUxw%2Fuploads%2Fgit-blob-39c048f0a0fd523de366bc25fcba766802df466c%2Fquestion-large%402x.png?alt=media" alt="" data-size="line"> icon in the upper right corner of the page.
{% endhint %}

The migration process consists of the following steps:

{% stepper %}
{% step %}
Get definitions from the source environment
{% endstep %}

{% step %}
Update payloads for the target environment
{% endstep %}

{% step %}
Post definitions to target environment
{% endstep %}

{% step %}
Run job using the definition
{% endstep %}
{% endstepper %}

The following sections describe these steps in more detail.

## Get definitions from the source environment

Use the following endpoints to get the data that you want to migrate.

### Get dataset definitions

`GET /v3/datasetDefs/{dataset}`

This endpoint returns the dataset definition for the specified dataset.

### Get rules

`GET /v3/rules`

This endpoint returns definitions of all the custom rules associated with the dataset specified.

## Update payloads for the target environment

After retrieving the dataset and rules definitions, copy them to a text editor. You can then prepare them for use as payloads in the subsequent POST endpoints.

{% hint style="info" %}
The following table provides the minimum number of properties to be updated. For a comprehensive list, create a sample dataset in the target environment using the UI and compare the JSON definitions.
{% endhint %}

### Dataset payload

In the dataset payload, update the following fields for the target environment:

<table><thead><tr><th width="152">Field</th><th>Description</th></tr></thead><tbody><tr><td>host</td><td>Change to the host name of the target environment. Use the endpoint <code>v2/getremotehost</code> if necessary.</td></tr><tr><td>user</td><td>The Collibra DQ user that will be used to run the newly migrated datasets.</td></tr><tr><td>agentId</td><td>Change the id and uuid values under agentId to match the target environment. Use the endpoint <code>v2/getagents</code> if necessary. For pushdown job migration, this value should remain 0.</td></tr><tr><td>lib</td><td>Verify that the library specified matches the target environment.</td></tr><tr><td>master</td><td>Verify that the master URL (specified under <code>spark</code>) matches the target environment.</td></tr></tbody></table>

### Rules payload

In the rules payload, verify that the userNM aligns with the target environment. Update the payload for each rule that you want to migrate.

## Post definitions to target environment

Use the payloads with following endpoints to migrate code to the target environment.

### Post dataset definitions

`POST /v3/datasetDefs`

### Post rules

`POST /v3/rules/{dataset}`

This endpoint can accept multiple rule definitions (i.e., an array of rules). If the rule already exists, the endpoint will overwrite the rule with the new values.

## Run job

After migrating the datasets and rules, use the following endpoint to run the job:

`POST /v3/jobs/run`

Provide the following parameters:

| Parameter  | Type               | Description                                                                                                                     |
| ---------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| dataset    | string             | Specify the name of the dataset that you created.                                                                               |
| runDate    | string($date-time) | Specify the run date.                                                                                                           |
| runDateEnd | string($date-time) | Required only for datasets that have a date range.                                                                              |
| agentName  | string             | Specify the agentName. Use the endpoint `v2/getagents` if necessary to obtain the agentName. Required only for Pullup datasets. |

You can check the status of the job from the [Jobs page](/data-quality-self-hosted/core-concepts/explorer/managing-the-jobs-page.md).
