Most of the Capture API only requires the user token and does not acquire any API key. You can signin with email or wallet to acquire the Capture Token. Here are examples to login and get your API tokens
The process of logging in with the integrity wallet involves a few steps that must be followed in order. These steps are outlined below:
Make a GET request to the login-web3 endpoint, including the wallet address as a query parameter. This request will retrieve a message that needs to be signed.
Using client-side code, sign the message with the wallet. This can be done with a library such as MetaMask, for example.
Send a POST request to the same endpoint, including the address and signature in the request body.
In the response, retrieve the authorization token.
Here is an example to login with your integrity wallet:
consturl=`https://api.numbersprotocol.io/api/v3/auth/token/login-web3/`;// Request the user's address from their wallet using the 'eth_requestAccounts' methodconstaddress= (awaitethereum.request({ method:'eth_requestAccounts' }))[0];// Send a GET request to the server to receive the message to be signedlet getResponse =awaitfetch(`${url}?address=${address}`));// Get the message to be signed from the responselet message = (awaitgetResponse.json()).message;// Sign the message with the user's walletlet signature =awaitethereum.request({method:'personal_sign', params: [address, message]});// Send a POST request to the server with the address and signature to retrieve the auth tokenlet postResponse =awaitfetch(`${endpoint}`, { method:'POST', body:JSON.stringify({address, signature}), headers: {'Content-type':'application/json'}});// Get the auth token from the responselet authToken = (awaitpostResponse.json()).auth_token;
Verify Capture Token
The /v3/auth/users/me/ endpoint is an authentication endpoint that allows for the validation of a user's Capture token.
By making a request to this endpoint with a valid token included in the headers, the user is able to verify their token and access the resources or services that are protected by the token. This endpoint is useful for ensuring that a user is authorized to access certain content or perform certain actions on a website or application. Additionally, this endpoint could also be used to check the validity of a token during a user's session.
The following sample code can be used to validate the Capture Token.
import requests# Replace $USER_CAPTURE_TOKEN with the actual tokenheaders ={"Authorization":"token $USER_CAPTURE_TOKEN"}response = requests.get("https://api.numbersprotocol.io/api/v3/auth/users/?show_num_balance=true", headers=headers)# You can check the status code of the responseprint(response.status_code)# And access the response bodyprint(response.json()['results'][0])
constaxios=require("axios");// Replace $USER_CAPTURE_TOKEN with the actual tokenconstheaders= {"Authorization":"token $USER_CAPTURE_TOKEN"};axios.get("https://api.numbersprotocol.io/api/v3/auth/users/?show_num_balance=true", {headers: headers}).then(response => {console.log(response.status);console.log(response.data.results[0]); }).catch(error => {console.log(error); });
The response.data.results[0] is the JSON object containing the user information. Following is an example of a JSON object returned by an API endpoint. The object contains information about a user, including their address, username, email, language, and wallet information. The user_wallet field contains various wallet addresses and their corresponding NUMs. The referrer field is the username of the user who referred the current user, and referral_code is the code that the current user can give to others for referral. The referee_count is the number of users that joined using the current user's referral code. The joined_at field is the date and time when the user created their account.
{"address":"0x8212099e5aF75e555A3E63da77a99CcC9527aCC1" # integrity wallet and also the ID of this user"username": "string", # username for the user, unique in the network"email":"[email protected]", # email address of the user"language":"en", # language preference of the user"user_wallet": {"asset_wallet":"string", # wallet address for the user's assets"asset_wallet_num":"string", # NUM balance in the asset wallet"integrity_wallet":"string", # wallet address for the user's integrity"integrity_wallet_num":"string", # NUM balance in the integrity wallet"points":"string", # Capture Credits in the user account },"referrer":"string", # user who referred the current user"referral_code":"string", # referral code assigned to the current user"referee_count":"string", # number of users that joined using the current user's referral code"joined_at":"2023-01-22T08:36:58Z" # date and time when the user created their account ...}