Migrated from Redmine #1283 | Author: Oscar Gutierrez Status: New | Priority: High, I’m very impatient | Created: 2024-09-23
Hi to all,
I am working with Simplybook, using it as a tool to store users that come to read on our library.
As such, I want to export the users that come on a daily basis.
I have managed via API to
-Authenticate using the API Key.
-Gather all bookings avaliable for the day
-For each of the users, ask for the user details.
Unfortunately, I am not geting the firstname amongst the fields that return when i am looking for the users.
THe api operations that i do are the following:
-GetToken
-GetBookings (filtering on today)
-GeClientInfo
All this within the Company Adminstrative Service section.
Am I missing the extra field Firstname? Do i need to use an alternative endpoint to gather this details?
I am going to add code data, though I am aware that you will only look at it if providing the HTTP query.
I am thinking that it might as well help other people that are using PS as method to gather data:
#Connecting to API to gather Token
#using user and Password logon
$loginUrl = "https://user-api.simplybook.me/login"
$companyLogin = ""
$userLogin = ""
$userPassword = ""
$today = (Get-Date).ToString("yyyy-MM-dd")
$loginHeaders = @{"Content-Type" = "application/json; charset=UTF-8"}
# Request body for user token (admin privileges)
$userloginBody = @{"jsonrpc" = "2.0";"method" = "getUserToken";"params" = @($companyLogin, $userLogin, $userPassword);"id"=1}
$userloginBodyJson = $userloginBody | ConvertTo-Json
$userloginToken = (Invoke-RestMethod -Uri $loginUrl -Method Post -Headers $loginHeaders -Body $loginBodyJson -ContentType "application/json").result
# Use the token from Step 1 and request bookings
$BookingsUrl = "https://user-api.simplybook.me/admin/"
$bookingsHeaders = @{"Content-Type"= "application/json; charset=UTF-8";"Accept"= "application/json";"X-Company-Login" = $companyLogin;"X-User-Token"= $userloginToken}
# Correct body for getBookings
$bookingsBody = @{"jsonrpc" = "2.0";"method" = "getBookings";"params" =@(@{"date_from"=$today;"date_to"=$today;"order"="date_start";"booking_type" = "all";});"id"= 1}
$bookingsBodyJson = $bookingsBody | ConvertTo-Json
$bookingsResponse = Invoke-RestMethod -Uri $BookingsUrl -Method Post -Headers $bookingsHeaders -Body $bookingsBodyJson -ContentType "application/json"
$users=$bookingsResponse.result|select id,client,client_id,client_email,code
#trying to access data by using the User, password Token gathering:
#not working
$clientdata=@()
$clientsinfoUrl = "https://user-api.simplybook.me/admin/"
$clientsinfoHeaders = @{"Content-Type"= "application/json; charset=UTF-8";"Accept"= "application/json";"X-Company-Login" = $companyLogin;"X-User-Token"= $userloginToken}
foreach ($user in $users)
{
$clientsinfobody= @{
"jsonrpc" = "2.0"
"method" = "getBookingDetails"
"params" = @($user.Id)
"id" = 1
}
$clientsinfoBodyJson = $clientsinfoBody | ConvertTo-Json -Depth 3 # Depth 3 is used to ensure nested objects are properly converted
$clientinfoResponse = Invoke-RestMethod -Uri $clientsinfoUrl -Method Post -Headers $clientsinfoHeaders -Body $clientsinfoBodyJson -ContentType "application/json"
#getting a 'Access Denied'
$clientdata +=$clientinfoResponse
}
#Trying to acces the data by means of Company name and API Token:
$clientdata=@()
$clientsinfoUrl = "https://user-api.simplybook.me/admin/"
$APIloginUrl = "https://user-api.simplybook.me/login"
$apiKey=''
$APIloginHeaders = @{"Content-Type" = "application/json; charset=UTF-8"}
$APIloginBody = @{"jsonrpc" = "2.0";"method"="getToken";"params"=@($companyLogin, $apiKey);"id"=1}
$APIloginBodyJson = $APIloginBody | ConvertTo-Json
$APIAdmintoken = (Invoke-RestMethod -Uri $APIloginUrl -Method Post -Headers $APIloginHeaders -Body $APIloginBodyJson -ContentType "application/json").result
#trying to access the data using the API, company name token gathering
#not working
$clientsinfoHeaders=@{"Content-Type"="application/json; charset=UTF-8";"X-Company-Login"=$companyLogin;"X-User-Token"=$APIadminToken}
foreach ($user in $users)
{
$clientsinfobody= @{
"jsonrpc" = "2.0"
"method" = "getBookingDetails"
"params" = @($user.Id)
"id" = 1
}
$clientsinfoBodyJson = $clientsinfoBody | ConvertTo-Json -Depth 3 # Depth 3 is used to ensure nested objects are properly converted
$clientinfoResponse = Invoke-RestMethod -Uri $clientsinfoUrl -Method Post -Headers $clientsinfoHeaders -Body $clientsinfoBodyJson -ContentType "application/json"
#getting a 'Access Denied'
$clientdata +=$clientinfoResponse
}
found an issue, but corrected and attempted, and same error .
Here the corrected section:
#Trying to access the data by means of Company name and API Token:
$clientdata=@()
$clientsinfoUrl = "https://user-api.simplybook.me/admin/"
$APIloginUrl = "https://user-api.simplybook.me/login"
$apiKey=''
$APIloginHeaders = @{"Content-Type" = "application/json; charset=UTF-8"}
$APIloginBody = @{"jsonrpc" = "2.0";"method"="getToken";"params"=@($companyLogin, $apiKey);"id"=1}
$APIloginBodyJson = $APIloginBody | ConvertTo-Json
$APIAdmintoken = (Invoke-RestMethod -Uri $APIloginUrl -Method Post -Headers $APIloginHeaders -Body $APIloginBodyJson -ContentType "application/json").result
#trying to access the data using the API, company name token gathering
#not working
$clientsinfoHeaders=@{"Content-Type"="application/json; charset=UTF-8";"X-Company-Login"=$companyLogin;"X-Token"=$APIadminToken}
foreach ($user in $users)
{
$clientsinfobody= @{
"jsonrpc" = "2.0"
"method" = "getBookingDetails"
"params" = @($user.Id)
"id" = 1
}
$clientsinfoBodyJson = $clientsinfoBody | ConvertTo-Json -Depth 3 # Depth 3 is used to ensure nested objects are properly converted
$clientinfoResponse = Invoke-RestMethod -Uri $clientsinfoUrl -Method Post -Headers $clientsinfoHeaders -Body $clientsinfoBodyJson -ContentType "application/json"
#getting a 'Access Denied'
$clientdata +=$clientinfoResponse
}
Hi To all,
I have accepted the fact that i could not get the first name in the request.
As such, i will work with other information in order to export data, and maintain unicity with the things that i will export.
Thanks to all for the assistance.