# Withdrawals (deprecated)

{% hint style="danger" %}
These endpoints are deprecated and will be discontinued by November 1st. Please make sure you migrate your implementation to the new [withdrawals flow](https://developers.publicmint.io/api/funding/withdrawing).
{% endhint %}

The following endpoints are used to insert and retrieve entries representing `withdrawals` from the database.

{% tabs %}
{% tab title="WITHDRAWALS ENDPOINTS" %}

```
POST /withdrawals
POST /withdrawals/:id/submit
GET /withdrawals/:id
GET /withdrawals
```

{% endtab %}
{% endtabs %}

## The `withdrawal` object

The `withdrawal` object represents a request for withdrawing fiat from the blockchain. You can create or retrieve an `identityId`'s withdrawals via request to the API. Or, if you manage multiple identities in the network, you can also retrieve a list of withdrawals for all of them.

Withdrawals are identified by a unique, random `id`, and relate to a user's `identityId`.

{% tabs %}
{% tab title="WITHDRAWAL OBJECT" %}

```javascript
{
    "id": "2642dedd-4fa0-40bf-8b15-7c0513bcdb38",
    "identityId": "e65dde2c-4379-42c7-a665-3f476cebb691",
    "transactionReference": "0xf6cce2d20d2714fa7be8e1bb8b8cf0abbb12ca3d34d000073742a4da954c1be5",
    "blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
    "amount": null,
    "currency": "USD",
    "transactionHash": null,
    "transferInformation": {
        "transferType": "wire",
		    "bankAccountName": "Jonh do bank",
		    "bankAccountNumber": "1321312312321312",
		    "routingNumber": "123456789"
    },
    "status": "prepared",
    "createdAt": "2020-02-19T11:43:04.553Z",
    "updatedAt": "2020-02-19T11:43:04.553Z"
}
```

{% endtab %}
{% endtabs %}

## POST /withdrawals

<mark style="color:green;">`POST`</mark> `[ENVIRONMENT HOSTNAME]/withdrawals`

This endpoint allows you to add a new `withdrawal` to the database. If all the params are valid, a new record will be inserted in the database with the `withdrawal` information. \
\
**This will return a transaction reference that needs to be provided to the transaction when performing the burn token action in the blockchain.**

#### Request Body

| Name                | Type   | Description                                       |
| ------------------- | ------ | ------------------------------------------------- |
| blockchainAddress   | string | Address where the money will be withdrawn         |
| currency            | string | Currency of the funds to withdraw                 |
| identityId          | string | Id of the identity associated to the request      |
| transferInformation | object | Object containing the information of the transfer |

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

```
{
    "id": "2642dedd-4fa0-40bf-8b15-7c0513bcdb38",
    "identityId": "e65dde2c-4379-42c7-a665-3f476cebb691",
    "transactionReference": "0xf6cce2d20d2714fa7be8e1bb8b8cf0abbb12ca3d34d000073742a4da954c1be5",
    "blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
    "amount": null,
    "currency": "USD",
    "transactionHash": null,
    "transferInformation": {
        "transferType": "wire",
		    "bankAccountName": "Jonh do bank",
		    "bankAccountNumber": "1321312312321312",
		    "routingNumber": "123456789"
    },
    "status": "prepared",
    "paymentDetails": null,
    "transactionNumber": null,
    "specialType": null,
    "createdAt": "2020-02-19T11:43:04.553Z",
    "updatedAt": "2020-02-19T11:43:04.553Z"
}
```

{% endtab %}

{% tab title="403 Response given when the identity is not yet approved." %}

```
{
    "code": "identity_not_approved",
    "status": 403
}
```

{% endtab %}
{% endtabs %}

#### **Example Call**

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

```javascript
POST [ENVIRONMENT HOSTNAME]/withdrawals

{
	"blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
	"currency": "USD",
	"identityId": "e65dde2c-4379-42c7-a665-3f476cebb691",
	"transferInformation": {
		"transferType": "wire",
		"bankAccountName": "Jonh do bank",
		"bankAccountNumber": "1321312312321312",
		"routingNumber": "123456789"
	}
}
```

{% endtab %}

{% tab title="Curl" %}

```
curl -X POST \
  [ENVIRONMENT HOSTNAME]/withdrawals \
  -H 'Content-Type: application/json' \
  -H 'apikey: {INSERT API KEY HERE}' \
  -d '{
    "blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
    "currency": "USD",
    "identityId": "e65dde2c-4379-42c7-a665-3f476cebb691",
    "transferInformation": {
	     "transferType": "wire",
		   "bankAccountName": "Jonh do bank",
		   "bankAccountNumber": "1321312312321312",
		   "routingNumber": "123456789"
	  }
}'
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": "2642dedd-4fa0-40bf-8b15-7c0513bcdb38",
    "identityId": "e65dde2c-4379-42c7-a665-3f476cebb691",
    "transactionReference": "0xf6cce2d20d2714fa7be8e1bb8b8cf0abbb12ca3d34d000073742a4da954c1be5",
    "blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
    "amount": null,
    "currency": "USD",
    "transactionHash": null,
    "transferInformation": {
        "transferType": "wire",
		    "bankAccountName": "Jonh do bank",
		    "bankAccountNumber": "1321312312321312",
		    "routingNumber": "123456789"
    },
    "status": "prepared",
    "createdAt": "2020-02-19T11:43:04.553Z",
    "updatedAt": "2020-02-19T11:43:04.553Z"
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
On the **Sandbox** environment, you can use the [settle withdrawal ](https://developers.publicmint.io/sandbox#settle-withdrawal)endpoint to simulate and settle the withdrawal request you created.
{% endhint %}

## POST /withdrawals/:id/submit

<mark style="color:green;">`POST`</mark> `[ENVIRONMENT HOSTNAME]/withdrawals/:id/submit`

This method can be used to submit a withdrawal **after the tokens were burned in the blockchain.** This endpoint receives the **transactionHash** of the burn operation has a body parameter. This will be used to check if the transaction operation matches the data provided when creating the withdrawal request.\ <br>

#### Path Parameters

| Name | Type   | Description                   |
| ---- | ------ | ----------------------------- |
| id   | string | Withdrawal id to be submitted |

#### Request Body

| Name            | Type   | Description                            |
| --------------- | ------ | -------------------------------------- |
| transactionHash | string | Transaction hash of the burn operation |

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

```
{
    "id": "37e2b53c-f938-4dce-90ef-7614f7e338f5",
    "identityId": "80d82e03-527e-46ff-b5a2-6e5d7d34115c",
    "transferType": "wire",
    "transactionReference": "0x8722597478bb2ab2964576b9509941269642c2d960ac7bc452cd8cd5f9e64f2e",
    "blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
    "amount": "10",
    "currency": "USD",
    "transactionHash": "0xfa7102053dceb6cdc59b1580706a9fec7b14333d30d041ad4f03b0d8359f63c8",
    "transferMethodId": null,
    "status": "submitted",
    "paymentDetails": null,
    "transactionNumber": null,
    "specialType": null,
    "createdAt": "2020-02-19T17:20:35.948Z",
    "updatedAt": "2020-02-19T17:23:21.068Z"
}
```

{% endtab %}
{% endtabs %}

#### **Example Call**

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

```javascript
POST [ENVIRONMENT HOSTNAME]/withdrawals/37e2b53c-f938-4dce-90ef-7614f7e338f5/submit
```

{% endtab %}

{% tab title="Curl" %}

```
curl --location --request POST 'localhost:3000/withdrawals/37e2b53c-f938-4dce-90ef-7614f7e338f5/submit' \
--header 'Content-Type: application/json' \
--header 'apikey: {{INSERT YOUR API KEY HERE}}' \
--data-raw '{
	"transactionHash": "0xfa7102053dceb6cdc59b1580706a9fec7b14333d30d041ad4f03b0d8359f63c8"
}'
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": "37e2b53c-f938-4dce-90ef-7614f7e338f5",
    "identityId": "80d82e03-527e-46ff-b5a2-6e5d7d34115c",
    "transferType": "wire",
    "transactionReference": "0x8722597478bb2ab2964576b9509941269642c2d960ac7bc452cd8cd5f9e64f2e",
    "blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
    "amount": "10",
    "currency": "USD",
    "transactionHash": "0xfa7102053dceb6cdc59b1580706a9fec7b14333d30d041ad4f03b0d8359f63c8",
    "transferMethodId": null,
    "status": "submitted",
    "createdAt": "2020-02-19T17:20:35.948Z",
    "updatedAt": "2020-02-19T17:23:21.068Z"
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
On the **Sandbox** environment, you can use the [settle withdrawal ](https://developers.publicmint.io/sandbox#settle-withdrawal)endpoint to simulate and settle the withdrawal request you created.
{% endhint %}

## GET /withdrawals/:id

<mark style="color:blue;">`GET`</mark> `[ENVIRONMENT HOSTNAME]/withdrawals/:id`

This endpoint retrieves a single `withdrawal` that you've created by its specific `id` attribute.

#### Path Parameters

| Name | Type   | Description                        |
| ---- | ------ | ---------------------------------- |
| id   | string | Id of the withdrawal to be fetched |

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

```
{
    "id": "6f0c5931-326d-431a-87b8-5368dcdf6d61",
    "identityId": "28961623-68b4-4fe3-bb16-9636eac5aab2",
    "transferInformation": {
        "transferType": "wire",
        "bankAccountName": "Jonh do bank",
		    "bankAccountNumber": "1321312312321312",
		    "routingNumber": "123456789"
    },
    "transactionReference": "0xd570c59208bd0cd8b5f29d7df86015aa31e0c978e38b6695cf309e0bd77e2764",
    "blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
    "amount": null,
    "currency": "USD",
    "transactionHash": null,
    "status": "prepared",
    "paymentDetails": null,
    "transactionNumber": null,
    "specialType": null,
    "createdAt": "2020-02-18T14:41:01.757Z",
    "updatedAt": "2020-02-18T14:41:01.757Z"
}
```

{% endtab %}
{% endtabs %}

####

#### Example Call

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

```javascript
GET [ENVIRONMENT HOSTNAME]/withdrawals/6f0c5931-326d-431a-87b8-5368dcdf6d61
```

{% endtab %}

{% tab title="Curl" %}

```
curl -X GET \
  [ENVIRONMENT HOSTNAME]/withdrawals/6f0c5931-326d-431a-87b8-5368dcdf6d61 \
  -H 'apikey: {INSERT API KEY HERE}'
  
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": "6f0c5931-326d-431a-87b8-5368dcdf6d61",
    "identityId": "28961623-68b4-4fe3-bb16-9636eac5aab2",
    "transferInformation": {
        "transferType": "wire",
        "bankAccountName": "Jonh do bank",
		    "bankAccountNumber": "1321312312321312",
		    "routingNumber": "123456789"
    },
    "transactionReference": "0xd570c59208bd0cd8b5f29d7df86015aa31e0c978e38b6695cf309e0bd77e2764",
    "blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
    "amount": null,
    "currency": "USD",
    "transactionHash": null,
    "status": "prepared",
    "createdAt": "2020-02-18T14:41:01.757Z",
    "updatedAt": "2020-02-18T14:41:01.757Z"
}
```

{% endtab %}
{% endtabs %}

## GET /withdrawals

<mark style="color:blue;">`GET`</mark> `[ENVIRONMENT HOSTNAME]/withdrawals/`

This endpoint returns a list of all `withdrawals` submitted by you.\
\&#xNAN;*This endpoint supports pagination.*

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

```
{
    "total": 1,
    "data": [
        {
            "id": "6f0c5931-326d-431a-87b8-5368dcdf6d61",
            "identityId": "28961623-68b4-4fe3-bb16-9636eac5aab2",
            "transferInformation": {
                "transferType": "wire",
                "bankAccountName": "Jonh do bank",
		            "bankAccountNumber": "1321312312321312",
		            "routingNumber": "123456789"
            },
            "transactionReference": "0xd570c59208bd0cd8b5f29d7df86015aa31e0c978e38b6695cf309e0bd77e2764",
            "blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
            "amount": null,
            "currency": "USD",
            "transactionHash": null,
            "status": "prepared",
            "createdAt": "2020-02-18T14:41:01.757Z",
            "updatedAt": "2020-02-18T14:41:01.757Z"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

####

#### Example call

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

```javascript
GET [ENVIRONMENT HOSTNAME]/withdrawals

// PAGINATED

GET [ENVIRONMENT HOSTNAME]/withdrawals?page[number]=1&page[size]=1
```

{% endtab %}

{% tab title="Curl" %}

```
curl -X GET \
  [ENVIRONMENT HOSTNAME]/withdrawals \
  -H 'apikey: {INSERT API KEY HERE}'
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "total": 1,
    "data": [
        {
            "id": "6f0c5931-326d-431a-87b8-5368dcdf6d61",
            "identityId": "28961623-68b4-4fe3-bb16-9636eac5aab2",
            "transferInformation": {
                "transferType": "wire",
                "bankAccountName": "Jonh do bank",
		            "bankAccountNumber": "1321312312321312",
		            "routingNumber": "123456789"
            },
            "transactionReference": "0xd570c59208bd0cd8b5f29d7df86015aa31e0c978e38b6695cf309e0bd77e2764",
            "blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
            "amount": null,
            "currency": "USD",
            "transactionHash": null,
            "status": "prepared",
            "createdAt": "2020-02-18T14:41:01.757Z",
            "updatedAt": "2020-02-18T14:41:01.757Z"
        }
    ]
}
```

{% endtab %}
{% endtabs %}
