# Steps to tokenize a property and make tokens available for investor
When property is added in listings, it should be tokenize and generated tokens should have owner of admin or as per in database , should be role of 5 and 6.
Tokenize_Property Table:
dbo.tokens
In above table, we will be generating tokens for property and will be assigning tokens to user who has role 5 and 6.
Endpoint to tokenize property:
```
/api/v1/tokens/tokenizeProperty
```
```
{
"property_id": "b222f9ae-0f8e-416b-84e8-b83188187a0a",
"property_add_date": "2023-01-01T00:00:00.000",
"nft_token_count": 145,
"token_price": 1000,
"property_value": 433078,
"debt_value": 288078,
"subscriberUID": "51bf515c-c14c-47a0-9693-087cc495178b",
"primaryRestriction": 360,
"secondryRestriction": 180
}
```
Here in above api, property_id taken from table:
spv table as property has been added in database with unique id.
subscriberUID is user with role of 5 and 6
To make a user of role 5 and 6 , we need to hit api of
```
user/approveSubscriber
```
```
{
"subscriberUID": "51bf515c-c14c-47a0-9693-087cc495178b",
"cashAccountBalance": 500000,
"subscriberType":"admin",
"orgType": "tirios",
"approval_date":"2021-10-19T05:53:39.569"
}
```
by above body, user of subscriberUID will be admin.
After the token has been added, invester can invest token in property if available tokens is greater than 0.
Available tokens are calculated by,
find all tokens in tokens table owned by user having role 5 and 6
then substract this token with token held by tirios,
then substract by token count that has payment pending
then substract by token count that has only request the token and not sign doc signed.
```
" select (coalesce(t.max_available, 0) - s.tirios_held_tokens - coalesce(pay.payment_pending,0) - coalesce(pen.pending,0)) as avaliable_tokens "
+ " from spv s "
+ " left outer join "
+ " (select t.property_spv_id, coalesce(count(DISTINCT t.token_id), 0) as max_available from tokens t "
+ " left outer join subscriber s on t.current_subscriber_id = s.subscriber_id "
+ " left outer join users u on s.subscriber_id = u.subscriber_id "
+ " left outer join user_role ur on u.user_id = ur.user_id "
+ " where ur.role_id in (5,6) GROUP BY t.property_spv_id) t on s.property_spv_id = t.property_spv_id "
+ " left outer join "
+ " (select property_spv_id, coalesce(sum(number_of_tokens), 0) as payment_pending from token_purchase_request "
+ " where request_status_id in (5) GROUP BY property_spv_id) pay on s.property_spv_id = pay.property_spv_id "
+ " left outer join "
+ " (select property_spv_id, coalesce(sum(number_of_tokens), 0) as pending from token_purchase_request "
+ " where request_status_id in (1) and created_on > DATEADD(minute, :pendingTokenTimeLimit, CURRENT_TIMESTAMP) "
+ " GROUP BY property_spv_id) pen on s.property_spv_id = pen.property_spv_id "
+ " where s.property_spv_id = :propertySpvId ";
```
Basically above query is used to find available tokens in propery if user can invest or not.
For user to invest tokens in property, property should have contract template associated with it.
Table for contract template is named as:
contract_templates.