# Address

## CreateAddress

<mark style="color:green;">`POST`</mark> `https://api.opentact.org/rest/address`

This will create an address

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |
| X-Auth-Token | string | JWT              |

#### Request Body

| Name         | Type    | Description                                                                   |
| ------------ | ------- | ----------------------------------------------------------------------------- |
| name         | string  | `<= 24 characters`                                                            |
| is\_physical | boolean | Default: `"true"`                                                             |
| is\_billing  | boolean | Default: `"true"`                                                             |
| is\_shipping | boolean | Default: `"true"`                                                             |
| address1     | string  | `<= 255 characters`                                                           |
| address2     | string  | `<= 255 characters`                                                           |
| zip\_code    | string  | `<= 12 characters`                                                            |
| city         | string  | `<= 255 characters`                                                           |
| country      | string  | <p><code><= 2 characters</code><br>a2 field from a DICTCountry dictionary</p> |

{% tabs %}
{% tab title="200 This is a sample 200:OK response" %}

```javascript
{
  "success": true,
  "payload": {
    "created_on": "2019-08-24T14:15:22Z",
    "modified_on": "2019-08-24T14:15:22Z",
    "uuid": "string",
    "name": "string",
    "is_physical": true,
    "is_billing": true,
    "is_shipping": true,
    "address1": "string",
    "address2": "string",
    "zip_code": "string",
    "city": "string",
    "country": {
      "created_on": "2019-08-24T14:15:22Z",
      "modified_on": "2019-08-24T14:15:22Z",
      "name": "string",
      "a2": "st",
      "a3": "str",
      "n": 1
    },
    "user": {
      "created_on": "2019-08-24T14:15:22Z",
      "modified_on": "2019-08-24T14:15:22Z",
      "uuid": "string",
      "email": "string",
      "password": "string",
      "phone_number": "string",
      "first_name": "string",
      "last_name": "string",
      "avatar": "string",
      "gender": "Agender",
      "dob": "2019-08-24T14:15:22Z",
      "role": "Admin",
      "gmail_user_id": "string",
      "facebook_user_id": "string",
      "apple_user_id": "string",
      "wechat_user_id": "string",
      "deleted_on": "2019-08-24T14:15:22Z",
      "token": "string",
      "account": {}
    },
    "account": {
      "created_on": "2019-08-24T14:15:22Z",
      "modified_on": "2019-08-24T14:15:22Z",
      "uuid": "string",
      "name": "string",
      "email": "string",
      "level": "ServiceAccount",
      "balance": 0,
      "class4_id": 0,
      "deleted_on": "2019-08-24T14:15:22Z",
      "time_zone": {},
      "users": [],
      "admin": {},
      "messaging_profile_default": {},
      "messaging_profiles": [],
      "addresses": []
    },
    "created_by": {
      "created_on": "2019-08-24T14:15:22Z",
      "modified_on": "2019-08-24T14:15:22Z",
      "uuid": "string",
      "email": "string",
      "password": "string",
      "phone_number": "string",
      "first_name": "string",
      "last_name": "string",
      "avatar": "string",
      "gender": "Agender",
      "dob": "2019-08-24T14:15:22Z",
      "role": "Admin",
      "gmail_user_id": "string",
      "facebook_user_id": "string",
      "apple_user_id": "string",
      "wechat_user_id": "string",
      "deleted_on": "2019-08-24T14:15:22Z",
      "token": "string",
      "account": {}
    },
    "modified_by": {
      "created_on": "2019-08-24T14:15:22Z",
      "modified_on": "2019-08-24T14:15:22Z",
      "uuid": "string",
      "email": "string",
      "password": "string",
      "phone_number": "string",
      "first_name": "string",
      "last_name": "string",
      "avatar": "string",
      "gender": "Agender",
      "dob": "2019-08-24T14:15:22Z",
      "role": "Admin",
      "gmail_user_id": "string",
      "facebook_user_id": "string",
      "apple_user_id": "string",
      "wechat_user_id": "string",
      "deleted_on": "2019-08-24T14:15:22Z",
      "token": "string",
      "account": {}
    }
  }
}
```

{% endtab %}

{% tab title="201 " %}

```javascript
{
  "success": true,
  "payload": {
    "created_on": "2019-08-24T14:15:22Z",
    "modified_on": "2019-08-24T14:15:22Z",
    "uuid": "string",
    "name": "string",
    "is_physical": true,
    "is_billing": true,
    "is_shipping": true,
    "address1": "string",
    "address2": "string",
    "zip_code": "string",
    "city": "string",
    "country": {},
    "user": {},
    "account": {},
    "created_by": {},
    "modified_by": {}
  }
}
```

{% endtab %}

{% tab title="401 " %}

```javascript
{
"success": false,
"message": "string",
"status": 0
}
```

{% endtab %}

{% tab title="404 " %}

```javascript
{
"success": false,
"message": "string",
"status": 0
}
```

{% endtab %}
{% endtabs %}

### Code Example

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

```bash
curl -X POST "https://api.opentact.org/rest/address" \
-H  "accept: application/json" -H "X-Auth-Token: JWT_TOKEN" \
-H  "Content-Type: application/json" \
-d "{\"name\":\"string\",\"is_physical\":true,\"is_billing\":true,\"is_shipping\":true,\"address1\":\"string\",\"address2\":\"string\",\"zip_code\":\"string\",\"city\":\"string\",\"country\":\"string\"}"
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
include('vendor/rmccue/requests/library/Requests.php');
Requests::register_autoloader();
$headers = array(
    'accept' => 'application/json',
    'X-Auth-Token' => 'JWT_TOKEN',
    'Content-Type' => 'application/json'
);
$data = '{"name":"string","is_physical":true,"is_billing":true,"is_shipping":true,"address1":"string","address2":"string","zip_code":"string","city":"string","country":"string"}';
$response = Requests::post('https://api.opentact.org/rest/address', $headers, $data);

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
    'accept': 'application/json',
    'X-Auth-Token': 'JWT_TOKEN',
    'Content-Type': 'application/json',
}

data = '{"name":"string","is_physical":true,"is_billing":true,"is_shipping":true,"address1":"string","address2":"string","zip_code":"string","city":"string","country":"string"}'

response = requests.post('https://api.opentact.org/rest/address', headers=headers, data=data)

```

{% endtab %}

{% tab title="Javascript" %}

```javascript
var fetch = require('node-fetch');

fetch('https://api.opentact.org/rest/address', {
    method: 'POST',
    headers: {
        'accept': 'application/json',
        'X-Auth-Token': 'JWT_TOKEN',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({"name":"string","is_physical":true,"is_billing":true,"is_shipping":true,"address1":"string","address2":"string","zip_code":"string","city":"string","country":"string"})
});

```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"strings"
)

func main() {
	client := &http.Client{}
	var data = strings.NewReader(`{"name":"string","is_physical":true,"is_billing":true,"is_shipping":true,"address1":"string","address2":"string","zip_code":"string","city":"string","country":"string"}`)
	req, err := http.NewRequest("POST", "https://api.opentact.org/rest/address", data)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("accept", "application/json")
	req.Header.Set("X-Auth-Token", "JWT_TOKEN")
	req.Header.Set("Content-Type", "application/json")
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	bodyText, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", bodyText)
}

```

{% endtab %}
{% endtabs %}

## GetAddressListByAccount

<mark style="color:blue;">`GET`</mark> `https://api.opentact.org/rest/address/{account}`

This will return an address related to an account

#### Headers

| Name         | Type   | Description |
| ------------ | ------ | ----------- |
| X-Auth-Token | string | JWT         |

{% tabs %}
{% tab title="200 This is a sample 200:OK response" %}

```javascript
{
  "success": true,
  "payload": [
    {
      "created_on": "2019-08-24T14:15:22Z",
      "modified_on": "2019-08-24T14:15:22Z",
      "uuid": "string",
      "name": "string",
      "is_physical": true,
      "is_billing": true,
      "is_shipping": true,
      "address1": "string",
      "address2": "string",
      "zip_code": "string",
      "city": "string",
      "country": {},
      "user": {},
      "account": {},
      "created_by": {},
      "modified_by": {}
    }
  ]
}
```

{% endtab %}

{% tab title="404 " %}

```javascript
{
"success": false,
"message": "string",
"status": 0
}
```

{% endtab %}
{% endtabs %}

### Code Example

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

```bash
curl -X GET "https://api.opentact.org/rest/address/account" \
-H  "accept: application/json" -H "X-Auth-Token: JWT_TOKEN" 
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
include('vendor/rmccue/requests/library/Requests.php');
Requests::register_autoloader();
$headers = array(
    'accept' => 'application/json',
    'X-Auth-Token' => 'JWT_TOKEN'
);
$response = Requests::get('https://api.opentact.org/rest/address/account', $headers);

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
    'accept': 'application/json',
    'X-Auth-Token': 'JWT_TOKEN',
}

response = requests.get('https://api.opentact.org/rest/address/account', headers=headers)

```

{% endtab %}

{% tab title="Javascript" %}

```javascript
var fetch = require('node-fetch');

fetch('https://api.opentact.org/rest/address/account', {
    headers: {
        'accept': 'application/json',
        'X-Auth-Token': 'JWT_TOKEN'
    }
});

```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

func main() {
	client := &http.Client{}
	req, err := http.NewRequest("GET", "https://api.opentact.org/rest/address/account", nil)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("accept", "application/json")
	req.Header.Set("X-Auth-Token", "JWT_TOKEN")
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	bodyText, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", bodyText)
}

```

{% endtab %}
{% endtabs %}
