ygorsm | 2023-12-06 23:35:01 UTC | #1
Dears, good evening.
I have some questions regarding the creation of Telephones from the tab ("Phone Management" on the platform) via API. From the documentation I followed this instruction https://developer.genesys.cloud/telephony/create-phone#save-the-new-phone
I even managed to create a WebRTC phone, I managed to link it to a WebRTC person, but what I need is, via API, to go to the user and add a default phone for him and that's what I'm having difficulty with, because in the documentation I didn't find anything related to make PUT on 'phones'. I need to know which URL I should use to link a phone to a user
Thanks in advance!
Smith_Warren | 2023-12-08 20:19:24 UTC | #2
Forgive me if I've misread your question, but it sounds like you're looking for something in the StationsAPI to select the users phone. I can't recall exactly, but you'd first get the station by user id:
get_stations
Then you use:
putuserstationdefaultstationstation_id
Hope this at leasts points in the right direction.
ygorsm | 2023-12-11 16:32:06 UTC | #3
So I tried using PUT /api/v2/users/{userId}/station/defaultstation/{stationId}
However, when collecting the phone ID I created and putting it into the stationId variable, a station with that ID is not found. I don't know if the problem is with the way I'm creating the phone and that's resulting in the error.
This is the code I'm using to • Create a user • Add it to a permissions group • Create a Phone/station • Add phone/station to user
import base64, requests, sys, os import pandas as pd import json
URL = 'https://login.sae1.pure.cloud/oauth/token' clientid = 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxx' clientsecret = 'xxxxxxxxxxxxxxxxxxxxxx' credentials = f'{clientid}:{clientsecret}' encoded_credentials = base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': f'Basic {encodedcredentials}' } requestbody = {'granttype': 'clientcredentials'}
loginresponse = requests.post(URL, headers=headers, data=requestbody)
Verificar se a solicitação foi bem-sucedida
if loginresponse.statuscode == 200:
Exibir o token de acesso
accesstoken = loginresponse.json().get('access_token')
print(f'Token de Acesso: {access_token}')
Leitura do arquivo CSV
csvfilepath = r'C:\Users\ygorsm.DOMAIN\Downloads\genesys\usuarios.csv' df = pd.readcsv(csvfile_path, delimiter=';', header=None, skiprows=1, names=['Nome', 'Email'])
Iteração sobre as linhas do DataFrame
for index, row in df.iterrows(): name = row['Nome'] # Substitua 'Nome' pelo nome da coluna correspondente ao nome email = row['Email']
if pd.notna(name) and pd.notna(email): print(f'\nCriando usuário para {name} ({email})...')
POST USERS
URLPOSTUSERS = 'https://api.sae1.pure.cloud/api/v2/users'
headerspost = { 'Content-Type': 'application/json', 'Authorization': f'Bearer {accesstoken}' }
requestbodypost = { "name": name, "email": email, "divisionId": "e3b68a69-eee1-412d-bf48-b6a1cf888721", "state": "active" }
user_id = None
try: usersresponse = requests.post(URLPOSTUSERS, headers=headerspost, json=(requestbodypost))
if usersresponse.statuscode == 200: print(f'O usuário {name} foi criado com sucesso!')
Transformar em json
usersresponsejson = usersresponse.json() userid = usersresponsejson['id']
ADICIONAR AS PERMISSÕES PADRÃO PARA OS USUARIOS
URLPUTUSERSROLES = f'https://api.sae1.pure.cloud/api/v2/users/{userid}/roles' requestbodyput = ["a33cbea6-8780-4051-9547-f6be91383ce0", "c37a7c3f-6da0-4401-be45-b51c4c3db5e1"]#GRUPOS: AGENTE, EMPLOYEE
usersresponseput = requests.put(URLPUTUSERSROLES, headers=headerspost, json=(requestbodyput))
if usersresponseput.status_code == 200: print(f'Usuário foi adicionado ao grupo de permissões padrão com sucesso!')
elif usersresponse.statuscode == 400: print(f'O usuário já existe!')
except requests.exceptions.RequestException as e: print(f'Erro na solicitação: {e}')
#
CRIAR RAMAL
URLPOSTPHONE = 'https://api.sae1.pure.cloud/api/v2/telephony/providers/edges/phones'
requestbodypostphone = { "name": f"{name}WebRTC", "edgeGroup": { "id": "2afbcc3a-6c04-46f5-9d3d-23cf1eb83104" }, "site": { "id": "b687b7fc-4d6c-499f-bf9c-bb5f6dd632cf" }, "phoneBaseSettings": { "id": "98d5df0d-e2e1-4882-a86f-966c74130253" }, "lines": [ { "name":"", "lineBaseSettings": { "id":"fb4c5887-c0b3-4256-8864-d023565b2cdf", "name":"WebRTC1", }, "properties": { "stationlabel": { "type": "string", "value": { "default": 'PureCloud WebRTC Softphone', "instance": 'PureCloud WebRTC Softphone' } } }, "loggedInUser":{ "id": userid, "name": name }, "defaultForUser": { "id": userid, "name": name }, }, ], "status": { "operationalStatus": "OPERACIONAL" }, "webRtcUser": { "id": user_id, "name": name }, }
try: phoneresponse = requests.post(URLPOSTPHONE, headers=headerspost, json=requestbodypost_phone)
if phoneresponse.statuscode == 200: print(f'O ramal foi criado com sucesso!')
phoneresponsejson = phoneresponse.json() print(phoneresponsejson) phoneid = phoneresponsejson['id'] print(phone_id)
ATRELAR RAMAL AO USUARIO / Pessoa conectada / Padrão para pessoa
phoneId = phoneid URLPUTUSERSPHONE = f'https://api.sae1.pure.cloud/api/v2/users/{userid}/station/defaultstation/{phoneid}' print(URLPUTUSERS_PHONE)
try: phoneresponseput = requests.put(URLPUTUSERSPHONE, headers=headerspost) print(phoneresponseput.json())
if phoneresponseput.status_code == 200: print(f'O Ramal foi adicionado ao usuário com sucesso!')
else: print("ERRO", phoneresponseput.json()) except Exception as error: print(error)
elif phoneresponse.statuscode == 400: print(f'O ramal já está associado ao usuario!') print(phone_response.json()) except Exception as e: print(e)
else: print(f'Nome ou e-mail inválido para a linha {index}. Ignorando...')
else:
Exibir mensagem de erro se a solicitação falhar
print(f'Erro na solicitacao: {loginresponse.statuscode} - {login_response.text}')
Smith_Warren | 2023-12-11 18:21:21 UTC | #4
ygorsm, post:3, topic:23561
the phone ID I created and putting it into the stationId variable
These are not the same thing... first get the stationID by the phone's webRtcUser. GET /api/v2/stations
ygorsm | 2023-12-12 14:48:00 UTC | #5
The problem is that when I do a GET in /api/v2/stations, all WebRTC appear except the WebRTC phone that I created via API, (For example: userteste07WebRTC) but in the web interface, I can find this WebRTC phone, only via API that doesn't. Did I make a mistake when creating the WebRTC phone?
ygorsm | 2023-12-13 14:13:25 UTC | #6
Hello Smith_Warren.
Thank you very much for your support, I managed to collect the WebRTC ID information, my code was not showing all the information in the correct paginations. I managed to add a default station for the user.
Hug, Ygor
Smith_Warren | 2023-12-13 15:43:35 UTC | #7
Good job!! thanks for letting me know that you got it working.
system | 2024-01-13 15:43:51 UTC | #8
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 23561