Fetching user information from the Chattz API is pretty simple. This endpoint allows you to retrieve a user’s profile, including their username, first name, last name, profile picture, and banner.
Endpoint:
GET https://chattz.net/api/v1/users?user_id={user_id}Parameters:
user_idoruser_ids: (Required) The ID(s) of the user(s) whose data you want to retrieve.
Note: You can only fetch data from a user whose profile visibility is set to “Everyone”
Example Request:
To fetch details for the user with ID 1:
https://chattz.net/api/v1/users?user_id=1Example Response:
[
{
"username": "john_doe",
"first_name": "John",
"last_name": "Doe",
"bio": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"profile_picture": "https://chattz.net/chattz-uploads/john_doe.jpg",
"banner": "https://chattz.net/chattz-uploads/john_banner.jpg"
}
]What You Get:
username: The user’s unique username.first_name: The user’s first name.last_name: The user’s last name.bio: The user’s “about me” displayed on their profile.profile_picture: A URL to the user’s profile picture.banner: A URL to the user’s banner image.
Common Use Cases:
- Displaying a user’s profile on your site.
- Integrating user data into your app or third-party platform.
JavaScript Example to Fetch User Information:
function fetchUserInfo(userId) {
const apiUrl = `https://chattz.net/api/v1/users?user_id=${userId}`;
fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error('User not found or API error');
}
return response.json();
})
.then(data => {
if (data.length === 0) {
console.log("User not found.");
} else {
const user = data[0];
const username = user.username;
const firstName = user.first_name;
const lastName = user.last_name;
const profilePicture = user.profile_picture;
const banner = user.banner;
console.log(`
Username: ${username}
First Name: ${firstName}
Last Name: ${lastName}
Profile Picture: ${profilePicture}
Banner: ${banner}
`);
}
})
.catch(error => {
console.log("An error occurred: " + error.message);
});
}
fetchUserInfo(1); // Replace 1 with the user ID you want to queryExample Output (console):
Username: johndoe
First Name: John
Last Name: Doe
Profile Picture: https://chattz.net/uploads/profile/johndoe.jpg
Banner: https://chattz.net/uploads/banner/johndoe-banner.jpg