# Create Account

{% hint style="info" %}
When creating the account you can submit as many or as few `profileFields` as you need at the time of Account creation. [More information](https://docs.sendwyre.com/v3/docs/account-resource#section-fields)
{% endhint %}

## Create Account

<mark style="color:green;">`POST`</mark> `https://api.sendwyre.com/v3/accounts`

#### Request Body

| Name              | Type    | Description                                                                                                                                                             |
| ----------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type              | string  | the type of account, currently `INDIVIDUAL` is the only supported value                                                                                                 |
| country           | string  | the country of the account holder. For individuals, this is the country of residence. (Currently we only support US accounts)                                           |
| profileFields     | array   | An array of the Fields submitted at the time of Account creation. You can submit as many or as few fields as you need at the time of Account creation. More information |
| referrerAccountId | string  | Supply your own Account ID when creating noncustodial accounts. This field is used to track which account referred the new account into our system                      |
| subaccount        | boolean | When `true`, the newly created account will be a custodial subaccount owner by the caller. Otherwise, the account will be a standalone non-custodial account.           |
| disableEmail      | boolean | if `true` prevents all outbound emails to the account                                                                                                                   |

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

```
{
  "id" : "AC-U4BWHGZDG6W",
  "status" : "PENDING",
  "type" : "INDIVIDUAL",
  "country" : "US",
  "createdAt" : 1541789972000,
  "depositAddresses" : {
    "ETH" : "0x98B031783d0efb1E65C4072C6576BaCa0736A912",
    "BTC" : "14CriXWTRoJmQdBzdikw6tEmSuwxMozWWq"
  },
  "totalBalances" : { 
    "BTC" : 1.0000000,
    "ETH" : 0.1000000000000000000
  },
  "availableBalances" : { 
    "BTC" : 1.0000000,
    "ETH" : 0.1000000000000000000
  },
  "profileData" : [ {
    "fieldId" : "individualCellphoneNumber",
    "fieldType" : "CELLPHONE",
    "value" : null,
    "note" : "Must be verified by user.",
    "status" : "OPEN"
  }, {
    "fieldId" : "individualEmail",
    "fieldType" : "EMAIL",
    "value" : "johnnyquest22@yolo.com",
    "note" : "Must be verified by user.",
    "status" : "OPEN"
  }, {
    "fieldId" : "individualLegalName",
    "fieldType" : "STRING",
    "value" : "Johnny Quest",
    "note" : null,
    "status" : "PENDING"
  }, {
    "fieldId" : "individualDateOfBirth",
    "fieldType" : "DATE",
    "value" : null,
    "note" : null,
    "status" : "OPEN"
  }, {
    "fieldId" : "individualSsn",
    "fieldType" : "STRING",
    "value" : null,
    "note" : null,
    "status" : "NULL"
  }, {
    "fieldId" : "individualResidenceAddress",
    "fieldType" : "ADDRESS",
    "value" : {
        "street1": "1 Market St",
        "street2": "Suite 402",
        "city": "San Francisco",
        "state": "CA",
        "postalCode": "94105",
        "country": "US"
    },
    "note" : null,
    "status" : "PENDING"
  }, {
    "fieldId" : "individualGovernmentId",
    "fieldType" : "DOCUMENT",
    "value" : [],
    "note" : null,
    "status" : "OPEN"
  }, {
    "fieldId" : "individualSourceOfFunds",
    "fieldType" : "PAYMENT_METHOD",
    "value" : null,
    "note" : "Payment method not yet submitted",
    "status" : "OPEN"
  } ]
}
```

{% endtab %}
{% endtabs %}

## Examples

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

```
{
  "type":"INDIVIDUAL",
  "country": "US",
  "subaccount": true,
  "profileFields":[
    {
      "fieldId": "individualLegalName",
      "value": "Johnny Quest"
    },
    {
      "fieldId": "individualEmail",
      "value": "JohnnyQuest22@yolo.com"
    },
    {
      "fieldId": "individualResidenceAddress",
      "value": {
        "street1": "1 Market St",
        "street2": "Suite 402",
        "city": "San Francisco",
        "state": "CA",
        "postalCode": "94105",
        "country": "US"
      }
    }
  ]
}
```

{% endtab %}

{% tab title="Python" %}

```
'''
This is a Python 3.7 Module that creates a Wyre Account
using secret key authentication.

You can only use this module for creating INDIVIDUAL accounts
if you already have a business account set up.

If you do not have a business account with a secretKey/ApiKey, 
go through the signup process for a test account here: https://www.testwyre.com/
'''

# You can file account_validation_helpers file here: https://github.com/nickolasteixeira/Wyre_API/blob/master/account_validation_helpers.py
# This file helps for validating entries from users.
# Currently this process is a command line interface program
import account_validation_helpers as avh
import hashlib
import hmac
import json
import os
import requests
import time
import urllib.parse


class WyreApi:
    ACCOUNT_ID = os.getenv("ACCOUNT_ID")
    API_KEY = os.getenv("WYRE_APIKEY")
    SEC_KEY = os.getenv("WYRE_TOKEN")
    API_VER3 = "/v3"
    API_ACCOUNT_PATH = "/accounts"
    API_URL = "https://api.testwyre.com"
    # These are the object attributes that you'll want to fill in before sending the request to Wyre's API. Feel free to add more if you want a thorough onboarding process for your users
    # Reference for more fields: https://docs.sendwyre.com/docs/account-resource#section-field-ids
    OBJ_ATTRS = ('type', 'country', 'individualLegalName',
                 'individualEmail', 'individualCellphoneNumber')
    # 'individualResidenceAddress', 'individualDateOfBirth', 'individualSsn')

    '''
        This method initializes all the OBJ_ATTRS above to this class object.
        It takes in a createObj object if you want to pass one in, if not,
        you'll go through the fillInfo method process below.
    '''

    def __init__(self, createObj=None):
        if not createObj:
            createObj = WyreApi.OBJ_ATTRS

        self.fillInfo(createObj)





    '''
        This method loops through each OBJ_ATTR tuple above in the class 
        attributes and set's an the obj attributes to the newly created WyreAPI 
        object. It also goes through and validates each entry from the user.
        You can find the avh validateEntry and printAccountSetup methods
        here: https://github.com/nickolasteixeira/Wyre_API/blob/master/account_validation_helpers.py
    '''

    def fillInfo(self, createObj):
        avh.printAccountSetup()
        # loop through all the obj_attrs and initialize them to the obj

        for attr in createObj:
            setattr(self, attr, self.validateEntry(attr))

        avh.printCreateAccount()





    '''
        This method validates all entries from the users. It first finds the 
        validation function based on the attribute being passed and then calls 
        that function to validate the user's entry
        You can find the switchCase function here: https://github.com/nickolasteixeira/Wyre_API/blob/master/account_validation_helpers.py 
    '''

    def validateEntry(self, attr):
        # finds the function to use based on the object attr
        # from the account_validation_helpers.py file
        func = avh.switchCase(attr)
        # validates the text input with the function assigned to the
        # obj attribute from OBJ_ATTRS (Class attribute)
        text = func(self, attr)
        # returns the text to then get set to the specific attribute of the obj
        return text





    '''
        This method calculates the auth signature hash required for secret key 
        authentication
    '''

    def calc_auth_sig_hash(self, url_body):
        # calculates a signature per Wyre API:
        # https://docs.sendwyre.com/docs/authentication#secret-key-signature-auth
        message, secret = bytes(
            url_body, 'utf-8'), bytes(WyreApi.SEC_KEY, 'utf-8')
        newhash = hmac.new(secret, message, hashlib.sha256)
        return newhash.hexdigest()






    '''
        This method calculates a timesteamp required for the secret key 
        authentication
    '''

    def calcTimeStamp(self):
        # creates a timestamp to the millisecond
        return str(round(time.time() * 1000))





    '''
        This method creates an account and sends a request to Wyre's API
        API Endpoint:https://api.sendwyre.com/v3/accounts
    '''

    def createAccount(self):
        # additional timesteamp for the URL per Wyre Specs on the documentation
        # https://docs.sendwyre.com/docs/authentication#secret-key-signature-auth
        params = {
            "timestamp": self.calcTimeStamp()
        }
        # Data for the post request to create the account
        # These are fields required to create an "INDIVIDUAL" account
        # https://docs.sendwyre.com/docs/account-resource#section-field-ids
        post_data = {
            "type": self.type,
            "country": self.country,
            "subaccount": True,
            "profileFields": [
                {"fieldId": "individualLegalName",
                            "value": self.individualLegalName},
                {"fieldId": "individualEmail",
                            "value": self.individualEmail},
                {"fieldId": "individualCellphoneNumber",
                            "value": self.individualCellphoneNumber},
                # {"fieldId": "individualResidenceAddress", "value": self.individualResidenceAddress},
                # {"fieldId": "individualDateOfBirth", "value": self.individualDateOfBirth},
                # {"fieldId": "individualSsn", "value": self.individualSsn}
            ]}
        # concatinating the URL to then create a Signature hash
        url = WyreApi.API_URL + WyreApi.API_VER3 + WyreApi.API_ACCOUNT_PATH + \
            "?" + urllib.parse.urlencode(params, encoding='utf-8')
        # headers needed to authorize the post request
        # https://docs.sendwyre.com/docs/authentication#secret-key-signature-auth
        headers = {
            'X-API-Key': WyreApi.API_KEY,
            'X-API-Signature': self.calc_auth_sig_hash(url + json.dumps(post_data))
        }
        # sending a request with the post data, timestamp and signed headers
        response = requests.post(url, headers=headers, json=post_data)
        if response.status_code == 200:
            # print success message
            return json.loads(response.text)
        else:
            print(response.text)




if __name__ == "__main__":
    # =========== Creating an account =========== #
    account = WyreApi()
    # You can either pass in an iterable with the
    # required obj attributes. Ex below:
    # createObj = ('type', 'country', 'individualLegalName', 'individualEmail')
    # account = WyreApi(createObj)

    # Or you can create an account without passing in an argument
    new_account = account.createAccount()
    if new_account:
      print(new_account)
```

{% endtab %}

{% tab title="cURL" %}

```
################### Generate a secrey key ###################
# First generate your own secret key/Api, if you do not already have one.
# If you do not have a business account with a secretKey/ApiKey, 
# go through the signup process for a test account here: https://www.testwyre.com/

# If you do, skip down to Create a Wyre Account in this view. 


################### Create a Wyre Account ###################
# After receiving your secret key, your next step should be create an account.
# In this example below, I'm using the test env. When you are ready, use the production url: https://api.sendwyre.com

# Feel free to input your own account object below. 

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR-BEARER-TOKEN" \
-d '{"type":"INDIVIDUAL","country": "US","subaccount": true,"profileFields":[{"fieldId": "individualLegalName","value": "YOUR_NAME"},{"fieldId": "individualEmail","value": "YOUREMAIL@EMAIL.com"},{"fieldId": "individualResidenceAddress","value": {"street1": "1 Market St","street2": "Suite 402","city": "San Francisco","state": "CA","postalCode": "94105","country": "US"}}]}' \
https://api.testwyre.com/v3/accounts
```

{% endtab %}
{% endtabs %}
