Page 1 of 1

Access VICIdial API via Python

PostPosted: Mon Jul 19, 2021 9:08 am
by ABretten
Hey,

Im trying to access the API just using the basic tokens available in the docs here : http://www.vicidial.org/docs/NON-AGENT_API.txt



Im using python 3.8.8 and using this code :


import requests
from requests.auth import HTTPBasicAuth

url = 'http://server/vicidial/non_agent_api.php'
auth =('6666','1234')

requests.get(url,auth=auth)


Im getting the following error :
NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000001CC9B5A7FA0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

Would anyone be able to tell me where im going wrong?

Thanks
Alex

Re: Access VICIdial API via Python

PostPosted: Mon Jul 19, 2021 1:34 pm
by carpenox
not sure if this will help since this is a php derivative but it may get you on the right track: https://github.com/masterfermin02/vicid ... Client.php

Re: Access VICIdial API via Python

PostPosted: Tue Jul 20, 2021 7:58 am
by mjohn425
Hi Alex,

The API that you are trying to use doesn't use Basic auth (i.e auth through the Authorization header) so you won't be able to pass it this way. The API expects the user and password as part of the query string and sometimes a target user depending on the function. In saying that, the getaddrinfo failed is a DNS lookup issue so probably check the value in the url column and check that it's actually pointing to the server. Note: you can test all of them in your browser address bar before moving into python.

Cheers.

Re: Access VICIdial API via Python

PostPosted: Tue Jul 20, 2021 8:22 am
by ABretten
carpenox wrote:not sure if this will help since this is a php derivative but it may get you on the right track: https://github.com/masterfermin02/vicid ... Client.php

Thanks! Checked it out and its helped me understand the API functions.

mjohn425 wrote:Hi Alex,

The API that you are trying to use doesn't use Basic auth (i.e auth through the Authorization header) so you won't be able to pass it this way. The API expects the user and password as part of the query string and sometimes a target user depending on the function. In saying that, the getaddrinfo failed is a DNS lookup issue so probably check the value in the url column and check that it's actually pointing to the server. Note: you can test all of them in your browser address bar before moving into python.

Cheers.


So when it says "server" in the URL, am I meant to be quoting an IP address of the server my company uses? - Iv seen in the non agent docs the following is listed as a sample string : "http://server/vicidial/non_agent_api.php?function=version"

When i try pasting that in my address bar it doesnt return anything!

Re: Access VICIdial API via Python

PostPosted: Tue Jul 20, 2021 9:35 am
by mjohn425
Yep most definitely replacing server with the ip address or if they have a fully qualified domain name chuck that in there instead.