# Job Operations

{% hint style="info" %}
**Good to know:** All job operation interfaces need to use token as the request header.
{% endhint %}

## Creating jobs

### Creating a privacy computing job

<mark style="color:green;">`POST`</mark> `https://www.phoenix.global/sdk/computation/panel/createJobByInput`

Create a privacy computing job. The computation data of the job is input through the keyboard.

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                          | Type         | Description                                                                                                                                                                                          |
| --------------------------------------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| computation<mark style="color:red;">\*</mark> | string       | Computation type. One of "Privacy Comparison", "Matrix Addition", and "Matrix Multiplication"                                                                                                        |
| input<mark style="color:red;">\*</mark>       | string       | Data used for computing, formatted as a matrix，such as "\[\[18,34,18.2]]"                                                                                                                            |
| jobName<mark style="color:red;">\*</mark>     | string       | Job name that cannot be repeated                                                                                                                                                                     |
| parties<mark style="color:red;">\*</mark>     | string array | Computation participants. The current version of the input type job has three parties. Participants need to provide computation data and can view the computation results on the phoenix blockchain. |

{% tabs %}
{% tab title="200: OK Return the id of the new job.  Each job has a unique job id" %}

```json
{
    "code": 200,
    "msg": "success",
    "jobID": "82432641958147347699879957611773176975645610459935361780929612748304054178070"
}
```

{% endtab %}
{% endtabs %}

The usage of curl and golang sdk is as follows:

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location 'https://www.phoenix.global/sdk/computation/panel/createJobByInput' \
--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IkxKTDJAMTYzLmNvbSIsImV4cCI6MTY3ODM0ODkwMX0.OAia1TMt31EOGuvbt5SjspiACNiWfgmDeTVpwG6pP9c' \
--header 'Content-Type: application/json' \
--data-raw '{
  "computation": "Matrix Addition",
  "input": "[[18,34,18.2]]",
  "jobName": "matrix addition job Test",
  "parties": [
    "xxxxxx@gmail.com",
    "xxxxxx@gmail.com",
    "xxxxxx@gmail.com"
  ]
}'
```

{% endtab %}

{% tab title="Golang" %}

```go
import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	token := "xxxxxx"
	reqBody := common.ReqCreateJobByInput{
		JobName:     "matrix addition job Test",
		Parties:     []string{"xxxxxx@gmail.com", "xxxxxx@gmail.com", "xxxxxx@gmail.com"},
		Computation: "Matrix Addition",
		Input:       "[[23,9,1],[23,1,3]]",
	}
	result, err := controllers.CreateJobByInput(reqBody, token)
	......
}
```

{% endtab %}
{% endtabs %}

### Creating a machine learning classification job

<mark style="color:green;">`POST`</mark> `https://www.phoenix.global/sdk/computation/panel/createJobByFile`

Create a machine learning classification job. The participant of the job is the creator.

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                          | Type   | Description                                                                                                                                        |
| --------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| computation<mark style="color:red;">\*</mark> | string | Form data. Computation type. One of "Decision Tree", "Logistic Regression", "SVM" and "Deep Learning MLP"                                          |
| jobName<mark style="color:red;">\*</mark>     | string | Form data. Job name                                                                                                                                |
| featureData<mark style="color:red;">\*</mark> | file   | Form data. Feature dataset in .CSV format, cannot contain special characters                                                                       |
| targetData<mark style="color:red;">\*</mark>  | file   | Form data. Target dataset in .CSV format, cannot contain special characters                                                                        |
| testingData                                   | file   | Form data. Testing dataset in .CSV format, cannot contain special characters. The dimensions of testing dataset and feature dataset should be same |

{% tabs %}
{% tab title="200: OK Return the id of the new job" %}

```json
{
    "code": 200,
    "msg": "success",
    "jobID": "15336929879565052031766977071313450079096374296015479727460579121350576553341"
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**The file format can refer to:** <https://github.com/PhoenixGlobal/Phoenix-Computation-Control-Doc/wiki/Machine-Learning-Job-Guide#6-click-on-upload-a-document>
{% endhint %}

The usage of curl and golang sdk is as follows:

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location 'https://www.phoenix.global/sdk/computation/panel/createJobByFile' \
--header 'token: xxxxxxxxxxxx' \
--form 'computation="Decision Tree"' \
--form 'jobName="decision tree" test"' \
--form 'featureData=@"feature dataset file path"' \
--form 'targetData=@"target dataset file path"' \
--form 'testingData=@"testing dataset file path"'
```

{% endtab %}

{% tab title="Golang" %}

```go
import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	token := "xxxxxx"
	params := common.ReqCreateJobByFile{
		JobName:     "decision tree test",
		Computation: "Decision Tree",
	}
	featureFileName := "feature dataset file name"
	targetFileName := "target dataset file name"
	testingFileName := "testing dataset file name"
	result, err := controllers.CreateJobByFile(params, featureFileName, targetFileName, testingFileName, token)
	......
}
```

{% endtab %}
{% endtabs %}

### Creating a machine learning clustering job

<mark style="color:green;">`POST`</mark> `https://www.phoenix.global/sdk/computation/panel/createJobByFile`

Create a machine learning clustering job, which only needs to upload a feature dataset file.

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                          | Type   | Description                                                                                             |
| --------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------- |
| computation<mark style="color:red;">\*</mark> | string | Form data. Computation type. One of "Birch Clustering", "K-Means Clustering", and "Spectral Clustering" |
| jobName<mark style="color:red;">\*</mark>     | string | Form data. Job name                                                                                     |
| featureData<mark style="color:red;">\*</mark> | string | Form data. Feature dataset in .CSV format, cannot contain special characters                            |

{% tabs %}
{% tab title="200: OK Return the id of the new job" %}

```json
{
    "code": 200,
    "msg": "success",
    "jobID": "15336929879565052031766977071313450079096374296015479727460579121350576553341"
}
```

{% endtab %}
{% endtabs %}

The usage of curl and golang sdk is as follows:

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location 'https://www.phoenix.global/sdk/computation/panel/createJobByFile' \
--header 'token: xxxxxx' \
--form 'computation="Birch Clustering"' \
--form 'jobName="birch clustering job test"' \
--form 'featureData=@"feature dataset path"'
```

{% endtab %}

{% tab title="Golang" %}

```go
import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	token := "xxxxxx"
	params := common.ReqCreateJobByFile{
		JobName:     "birch clustering job",
		Computation: "Birch Clustering",
	}
	featureFileName := "titanic_x.csv"
	result, err := controllers.CreateJobByFile(params, featureFileName, "", "", token)
	......
}
```

{% endtab %}
{% endtabs %}

## Filling data

### Filling in the computation data for the job of input type

<mark style="color:green;">`POST`</mark> `https://www.phoenix.global/sdk/computation/panel/fillData`

Fill data for job of input type. The user who fills in the data must be a participant of the job.

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                    | Type   | Description                                                               |
| --------------------------------------- | ------ | ------------------------------------------------------------------------- |
| input<mark style="color:red;">\*</mark> | string | Data used for computing, formatted as a matrix，such as "\[\[18,34,18.2]]" |
| jobID<mark style="color:red;">\*</mark> | string | The job id returned when creating a job                                   |

{% tabs %}
{% tab title="200: OK Return success message" %}

```json
{
    "code": 200,
    "msg": "fill success"
}
```

{% endtab %}
{% endtabs %}

The usage of curl and golang sdk is as follows:

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location 'https://www.phoenix.global/sdk/computation/panel/fillData' \
--header 'token: xxxxxx' \
--header 'Content-Type: application/json' \
--data '{
  "input": "[[1,2,3.2]]",
  "jobID": "xxxxxx"
}
'
```

{% endtab %}

{% tab title="Golang" %}

```go
import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	token := "xxxxxx"
	reqBody := common.ReqFillData{
		JobID: "xxxxxx",
		Input: "[[2,9,1],[3,1,3]]",
	}
	result, err := controllers.FillData(reqBody, token)
	......
}
```

{% endtab %}
{% endtabs %}

## Deleting job

### Deleting job by job id

<mark style="color:green;">`POST`</mark> `https://www.phoenix.global/sdk/computation/panel/deleteJobByUser`

Delete a job according to job id. Only the creator has permission to delete

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                    | Type   | Description                             |
| --------------------------------------- | ------ | --------------------------------------- |
| jobID<mark style="color:red;">\*</mark> | string | The job id returned when creating a job |

{% tabs %}
{% tab title="200: OK Return success message" %}

```json
{
    "code": 200,
    "msg": "delete success"
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location 'https://www.phoenix.global/sdk/computation/panel/deleteJobByUser' \
--header 'token: xxxxxx' \
--header 'Content-Type: application/json' \
--data '{
  "jobID": "xxxxxx"
}
'
```

{% endtab %}

{% tab title="Golang" %}

```go
import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	token := "xxxxxx"
	reqBody := common.ReqDeleteJobByUser{
		JobID: "xxxxxx",
	}
	result, err := controllers.DeleteJobByUser(reqBody, token)
	......
}
```

{% endtab %}
{% endtabs %}


---

# 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://computation-sdk.phoenix.global/reference/api-reference/job-operations.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.
