Get a User
In this code snippet you learn how to get a User.
Example
Ensure the following variables are set to your required values using any convenient method:
| Key | Description |
|---|---|
USER_ID | The unique ID of the User. |
Prerequisites
You will need to use an existing Application and have a User in order to be able to get a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
Write the code
Add the following to get-user.sh:
curl "https://api.nexmo.com/v1/users/$USER_ID" \
-H 'Authorization: Bearer '$JWT\
-H 'Content-Type: application/json'Run your code
Save this file to your machine and run it:
Prerequisites
You will need to use an existing Application and have a User in order to be able to get a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
npm install @vonage/server-sdkCreate a file named get-user.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_APPLICATION_PRIVATE_KEY_PATH,
});Write the code
Add the following to get-user.js:
vonage.users.getUser(USER_ID)
.then((user) => console.log(user))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
You will need to use an existing Application and have a User in order to be able to get a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:1.1.2'Create a file named GetUser and add the following code to the main method:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
}Write the code
Add the following to the main method of the GetUser file:
val user = client.users.user(USER_ID).get()Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.users with the package containing GetUser:
Prerequisites
You will need to use an existing Application and have a User in order to be able to get a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:8.15.1'Create a file named GetUser and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the GetUser file:
User user = client.getUsersClient().getUser(USER_ID);Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.users with the package containing GetUser:
Prerequisites
You will need to use an existing Application and have a User in order to be able to get a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
pip install vonageWrite the code
Add the following to get-user.py:
from vonage import Auth, Vonage
from vonage_users import User
client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)
user: User = client.users.get_user(USER_ID)
print(user)Run your code
Save this file to your machine and run it:
Try it out
When you run the code you will get the specified User.