After getting your API key, the next step is to create users in your Snag system. This guide explains how to use the metadata endpoint to add users and manage their information.
Overview
The POST /api/users/metadatas
endpoint allows you to create or update user objects in Snag’s system. This is essential for migrating users from your existing system or adding new users to your loyalty program.
Only the walletAddress
property is required as this is the unique identifier
for the user being created.
Wallet Address Requirements
A wallet address is required for creating a Snag user. We currently support the following wallet types:
- EVM - Ethereum and EVM-compatible chains (Polygon, BSC, etc.)
- SVM - Solana Virtual Machine
- TON - The Open Network
- SUI - Sui blockchain
- Cosmos - Cosmos ecosystem chains
The wallet address serves as the unique identifier for each user in the Snag
system.
Creating a User
Basic User Creation
Here’s how to create a user with just the required wallet address:
curl -X POST 'https://admin.snagsolutions.io/api/users/metadatas' \
-H 'x-api-key: your-api-key-here' \
-H 'Content-Type: application/json' \
-d '{
"walletAddress": "0x1234567890abcdef1234567890abcdef12345678"
}'
{
"id": "user-123",
"walletAddress": "0x1234567890abcdef1234567890abcdef12345678",
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}
You can also include additional metadata when creating a user:
curl -X POST 'https://admin.snagsolutions.io/api/users/metadatas' \
-H 'x-api-key: your-api-key-here' \
-H 'Content-Type: application/json' \
-d '{
"walletAddress": "0x1234567890abcdef1234567890abcdef12345678",
"discordUser": "discord-user",
"twitterUser": "twitter-user",
"emailAddress": "[email protected]",
"telegramUsername": "telegram-user",
"displayName": "John Doe",
"logoUrl": "https://example.com/avatar.png",
"externalIdentifier": "your-internal-user-id"
}'
{
"id": "user-123",
"walletAddress": "0x1234567890abcdef1234567890abcdef12345678",
"discordUser": "discord-user",
"twitterUser": "twitter-user",
"emailAddress": "[email protected]",
"telegramUsername": "telegram-user",
"displayName": "John Doe",
"logoUrl": "https://example.com/avatar.png",
"externalIdentifier": "your-internal-user-id",
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}
Using the Snag SDK
import SnagSolutions from '@snagsolutions/sdk'
const client = new SnagSolutions({
apiKey: 'your-api-key-here',
})
// Create a basic user
const user = await client.users.createMetadata({
walletAddress: '0x1234567890abcdef1234567890abcdef12345678',
})
// Create a user with metadata
const userWithMetadata = await client.users.createMetadata({
walletAddress: '0x1234567890abcdef1234567890abcdef12345678',
discordUser: 'discord-user',
discordUserId: 'discord-user-id',
twitterUser: 'twitter-user',
twitterUserId: 'twitter-user-id',
telegramUsername: 'telegram-user',
telegramUserId: 'telegram-user-id',
displayName: 'John Doe',
externalIdentifier: 'your-internal-user-id',
})
External Identifier
The externalIdentifier
field allows you to maintain your own user ID system while using Snag. This is particularly useful when migrating from an existing system:
// Map your internal user ID to Snag
const user = await client.users.createMetadata({
walletAddress: '0x1234567890abcdef1234567890abcdef12345678',
externalIdentifier: 'your-internal-user-id-12345',
})
Use the external identifier to maintain a mapping between your internal user
IDs and Snag user IDs for easier integration.
The same endpoint can be used to update existing user metadata. Simply provide the wallet address and the fields you want to update:
// Update user metadata
const updatedUser = await client.users.createMetadata({
walletAddress: '0x1234567890abcdef1234567890abcdef12345678',
displayName: 'Updated Name',
emailAddress: '[email protected]',
})
The endpoint is idempotent - calling it multiple times with the same wallet
address will update the user rather than create duplicates.
Migration Strategy
When migrating users from your existing system:
Prepare your user data
Export your user data and ensure you have wallet addresses for each user.Users without wallet addresses cannot be created in Snag.
Batch process users
Loop through your users and call the metadata endpoint for each one.for (const user of yourUsers) {
await client.users.createMetadata({
walletAddress: user.walletAddress,
externalIdentifier: user.id,
displayName: user.name,
emailAddress: user.email
});
}
Verify migration
Use the GET users endpoint to verify all users were created successfully.
Next Steps
Now that you can create users, learn how to: