Get Basic User Information
curl --request GET \
--url https://accounts.mubarokah.com/api/user \
--header 'Authorization: <authorization>'const options = {method: 'GET', headers: {Authorization: '<authorization>'}};
fetch('https://accounts.mubarokah.com/api/user', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://accounts.mubarokah.com/api/user"
headers = {"Authorization": "<authorization>"}
response = requests.get(url, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://accounts.mubarokah.com/api/user",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.get("https://accounts.mubarokah.com/api/user")
.header("Authorization", "<authorization>")
.asString();package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://accounts.mubarokah.com/api/user"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": 123,
"name": "<string>",
"email": "<string>",
"profile_picture": "<string>",
"username": "<string>",
"gender": "<string>"
}User API
Get Basic User Information
API reference for fetching basic profile information of the authenticated user (/api/user).
GET
/
api
/
user
Get Basic User Information
curl --request GET \
--url https://accounts.mubarokah.com/api/user \
--header 'Authorization: <authorization>'const options = {method: 'GET', headers: {Authorization: '<authorization>'}};
fetch('https://accounts.mubarokah.com/api/user', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://accounts.mubarokah.com/api/user"
headers = {"Authorization": "<authorization>"}
response = requests.get(url, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://accounts.mubarokah.com/api/user",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.get("https://accounts.mubarokah.com/api/user")
.header("Authorization", "<authorization>")
.asString();package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://accounts.mubarokah.com/api/user"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": 123,
"name": "<string>",
"email": "<string>",
"profile_picture": "<string>",
"username": "<string>",
"gender": "<string>"
}Get Basic User Information
This endpoint retrieves basic profile information for the user associated with the provided access token.WhatsApp Registration & Null Emails
Users who register via WhatsApp may not have an email address associated with their account initially. In such cases, the
Users who register via WhatsApp may not have an email address associated with their account initially. In such cases, the
email field will be null.Best Practice for Developers:- Always check if the
emailfield isnullbefore using it. - Use
idormubarokah_id(available in User Details) as the primary identifier in your database. - Provide a fallback mechanism or prompt the user to complete their profile if an email is required by your application.
Authorization Headers
string
required
The Bearer token for authentication. Example:
Bearer {YOUR_ACCESS_TOKEN}string
default:"application/json"
Specifies the desired response format.
Required Scope
view-user
view-user scope during the OAuth authorization flow to access this endpoint. If the access token does not have this scope, a 403 Forbidden error will be returned.
Request Examples
JavaScript/Node.js
const getUserInfo = async (accessToken) => {
try {
const response = await fetch('https://accounts.mubarokah.com/api/user', {
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Accept': 'application/json'
}
});
if (!response.ok) {
const error = await response.json();
throw new Error(`HTTP ${response.status}: ${error.message || response.statusText}`);
}
return await response.json();
} catch (error) {
console.error('Failed to fetch user info:', error);
throw error;
}
};
// Usage example
const accessToken = 'your_access_token_here';
getUserInfo(accessToken)
.then(user => {
console.log('User info:', user);
console.log(`Welcome, ${user.name}!`);
})
.catch(error => {
console.error('Error:', error.message);
});
Python
import requests
import json
def get_user_info(access_token):
"""Fetch basic user information from Mubarokah ID API."""
url = 'https://accounts.mubarokah.com/api/user'
headers = {
'Authorization': f'Bearer {access_token}',
'Accept': 'application/json'
}
try:
response = requests.get(url, headers=headers)
response.raise_for_status() # Raises an HTTPError for bad responses
return response.json()
except requests.exceptions.HTTPError as e:
if response.status_code == 401:
raise Exception("Token expired or invalid")
elif response.status_code == 403:
raise Exception("Insufficient scope: view-user required")
else:
raise Exception(f"HTTP {response.status_code}: {response.text}")
except requests.exceptions.RequestException as e:
raise Exception(f"Request failed: {str(e)}")
# Usage example
access_token = "your_access_token_here"
try:
user_info = get_user_info(access_token)
print(f"Welcome, {user_info['name']}!")
print(f"Email: {user_info['email']}")
except Exception as error:
print(f"Error: {error}")
PHP
<?php
function getUserInfo($accessToken) {
$url = 'https://accounts.mubarokah.com/api/user';
$options = [
'http' => [
'header' => [
"Authorization: Bearer $accessToken",
"Accept: application/json"
],
'method' => 'GET'
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
throw new Exception('Failed to fetch user information');
}
$httpCode = intval(substr($http_response_header[0], 9, 3));
if ($httpCode === 401) {
throw new Exception('Token expired or invalid');
} elseif ($httpCode === 403) {
throw new Exception('Insufficient scope: view-user required');
} elseif ($httpCode !== 200) {
throw new Exception("HTTP $httpCode: Request failed");
}
return json_decode($result, true);
}
// Usage example
$accessToken = 'your_access_token_here';
try {
$userInfo = getUserInfo($accessToken);
echo "Welcome, {$userInfo['name']}!\n";
echo "Email: {$userInfo['email']}\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
?>
cURL
# Basic request
curl -X GET "https://accounts.mubarokah.com/api/user" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Accept: application/json"
# With error handling and formatting
curl -X GET "https://accounts.mubarokah.com/api/user" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Accept: application/json" \
-w "HTTP Status: %{http_code}\n" \
-s | jq '.'
Successful Response (200 OK)
A successful request returns a JSON object containing the user’s basic profile information. Response Fields:number
required
The unique identifier for the user.
string
required
The full name of the user.
string
The primary email address of the user. Note: This field may be
null if the user registered via WhatsApp and has not yet linked an email address.string
URL to the user’s profile picture. May be
null.string
The user’s chosen username. Defaults to a unique string or
null if not set.string
The gender of the user (e.g., “male”, “female”, “other”). May be
null.Example Successful Response
{
"id": 12345,
"name": "Ahmad Mubarak",
"email": "ahmad.mubarak@example.com",
"profile_picture": "https://accounts.mubarokah.com/storage/avatars/12345.jpg",
"username": "ahmadmubarak",
"gender": "male"
}
Error Responses
Common Error Responses
- 401 Unauthorized
- 403 Forbidden
- 429 Too Many Requests
Cause: Access token is missing, invalid, or expired.Or for expired tokens:Resolution: Refresh the access token or re-authenticate the user.
{
"message": "Unauthenticated."
}
{
"error": "token_expired",
"error_description": "The access token provided has expired.",
"message": "The access token provided has expired."
}
Cause: Access token is valid but lacks the required Resolution: Ensure your application requests the
view-user scope.{
"error": "insufficient_scope",
"error_description": "The request requires higher privileges than provided by the access token.",
"message": "Invalid scope(s) provided."
}
view-user scope during OAuth authorization.Cause: Rate limit exceeded for API requests.Resolution: Implement rate limiting in your application and respect the
{
"error": "rate_limit_exceeded",
"message": "Too many requests. Please try again later.",
"retry_after": 60
}
retry_after value.Rate Limiting
This endpoint is subject to rate limiting:- Limit: 100 requests per minute per access token
- Reset: Rate limit resets every minute
- Headers: Check
X-RateLimit-RemainingandX-RateLimit-Resetresponse headers
Testing the Endpoint
Using the API Playground
You can test this endpoint directly using the API playground above. Make sure you have:- A valid access token with
view-userscope - The token is not expired
- Your application is properly registered
Integration Testing Script
// Complete integration test
const testUserInfoEndpoint = async () => {
const testCases = [
{
name: 'Valid token with view-user scope',
token: 'valid_token_here',
expectedStatus: 200
},
{
name: 'Expired token',
token: 'expired_token_here',
expectedStatus: 401
},
{
name: 'Token without view-user scope',
token: 'limited_scope_token_here',
expectedStatus: 403
}
];
for (const testCase of testCases) {
try {
console.log(`Testing: ${testCase.name}`);
const result = await getUserInfo(testCase.token);
if (testCase.expectedStatus === 200) {
console.log('✅ Success:', result);
console.log(`User: ${result.name} (${result.email})`);
}
} catch (error) {
console.log(`❌ Expected error for ${testCase.name}:`, error.message);
}
}
};
// Run tests
testUserInfoEndpoint();
Was this page helpful?