Read Information
In the previous article, I introduced the OAuth2 flow and how to use it to get an access token. In this article, I will show you how to read information of users.
From now on, SDK will be introduced in the following articles. The Mixin team and the community provide various SDKs for developers to use. You can find the SDKs in the SDK page.
Read User's Profile
To obtain the basic personal information of a user, the PROFILE:READ
permission is required.
We can read the user's profile by using the /me
endpoint. /me
is an authenticated endpoint, so we need to obtain an access token first and put it in the HTTP Headers.
Let's send a request:
GET -H "Authorization: Bearer $ACCESS_TOKEN" https://api.mixin.one/me
{
"data": {
"type": "user",
"user_id": "773e5e77-4107-45c2-b648-8fc722ed77f5",
"name": "Team Mixin",
"identity_number": "7000"
}
}
The user_id
field is an unique id for each "Account" or "User" in the entire Mixin Network.
Additionally, if the user is a Mixin Messenger user, you can send messages to them by using POST /messages
with the user_id
field.
Read User's Assets
To obtain the asset balance of a user, the ASSETS:READ
permission is required.
Calling GET /assets
returns assets with a balance greater than 0. When you calls this API with a token which owned by a new user with zero balance, an empty list will be returned.
GET -H "Authorization: Bearer $ACCESS_TOKEN" https://api.mixin.one/assets
{
"data": [
{
"type": "asset",
"asset_id": "3596ab64-a575-39ad-964e-43b37f44e8cb",
"chain_id": "43d61dcd-e413-450d-80b8-101d5e903357",
"fee_asset_id": "43d61dcd-e413-450d-80b8-101d5e903357",
"symbol": "eosDAC",
"name": "eosDAC Community Owned EOS Block Producer ERC20 Tokens",
"icon_url": "https://images.mixin.one/HovctUnrBkLPlDotWvWPsIuFb8qKrLddwF5-f2Fi9q9uO829YB2qGITgOd2YmTMKnGg_z9XrVYzEwFE_rD_REz9C=s128",
"balance": "203.975",
"price_btc": "0",
"price_usd": "0",
"change_btc": "1", // change percent compare to 24 hours before
"change_usd": "2", // change percent compare to 24 hours before
"asset_key": "",
"mixin_id": "b6b8d99b7cecf810980aaeef17a48f82ed573f2552517d4932d195181bc6ba11",
"reserve": "",
"confirmations": 10,
"capitalization": 1000.3,
"liquidity": "",
"deposit_entries": [
{
"destination": "0x2CEab41716F4ce0Db36B6FdABEdc6a0BE5DC442B",
"tag": "",
"properties": "",
},
],
},
...
]
}
The asset_id
field is an unique id for each asset in the entire Mixin Network.
It can be obtained from https://mixin.one/snapshots by searching for asset code such as btc
. You can also deposit the asset into the Mixin Messenger wallet and talk to the bot 7000103061
, then search for and copy asset information.
Read Application's Assets
The Mixin Application is a special type of user. It also has a wallet just like a normal user. You can inspect the assets of the application by visiting "Developers Dashboard - Choosing any app - Clicking the Wallet
tab".
You can also read the assets programmatically by calling the /assets
with the application's access token. The algorithm for generating access token can be found here, but you can also use the SDK to simplify the process.
Here is the example of generating token and reading assets by using the official Go SDK:
import "github.com/MixinNetwork/bot-api-go-client"
import "fmt"
func main() {
ctx := context.Background()
// generate token
token, err := bot.SignAuthenticationToken(
CLIENT_ID,
SESSION_ID,
CLIENT_SECRET,
"GET",
"/assets",
""
)
if err != nil {
fmt.Println(err)
return
}
// query assets
assets, err := bot.AssetList(ctx, token)
if err != nil {
fmt.Println(err)
return
}
for _, a := range assets {
fmt.Println(a.AssetId)
}
}