Getting started
From LIVECHAT Developer Zone Wiki
This is a section where you will find instructions how to use server API methods.
Contents |
WSDL
First you have to get Livechat.wsdl file from https://www.livechatinc.com/download/serverapi/Livechat.wsdl. It is Livechat Server API description file needed to generate proxy class implementation to allow using methods provided by API.
C++ proxy generation with gsoap
Gsoap binaries consist of two files:
- wsdl2h - application needed to generate header file with definition of API methods
- soapcpp2 - gsoap compiler needed to compile header file with definitions of API methods. The result of compilation are source files with implementation of methods available on API server.
Here is an instruction how to generate proxy class to access to Livechat Server API.
Generating header file api_server.h: You can generate header file directly from http://www.livechatinc.com/download/serverapi/Livechat.wsdl or you can download this file and generate header file from wsdl on your machine. To generate header file api_server.h from wsdl placed on our site call:
wsdl2h -o api_server.h http://www.livechatinc.com/download/serverapi/Livechat.wsdl
To generate header fle api_server.h from wsdl placed on your machine call:
wsdl2h -o api_server.h Livechat.wsdl
where Livechat.wsdl is file name of our wsdl file including path to this file.
Compiling header file api_server.h to proxy class: To compile header file call:
soapcpp2 -C -i -Igsoap\import api_server.h
where gsoap\import is path to import directory of gsoap library. Proxy class files will be created in current directory. If you want the files to be created in other directory call:
soapcpp2 -C -i -dapidir -Igsoap\import api_server.h
where apidir is a path to destination directory of created proxy class files.
Authorization
To use methods of Livechat Server API you have to authorize and get unique Session ID that is valid 10 minutes since correct authorization.
To authorize yourself you have to call authorize method of Livechat Server API. Here is an example using generated proxy class with gsoap.
LivechatProxy proxy; ///< Proxy object to API server
std::string SessionID; ///< Session ID filled after correct authorization
// SSL initialize
/// Initialize ssl context
if (soap_ssl_client_context(&proxy,
SOAP_SSL_NO_AUTHENTICATION,
NULL, /* keyfile: required only when client must authenticate to server (see SSL docs on how to obtain this file) */
NULL, /* password to read the key file */
NULL, /* cacert file to store trusted certificates (needed to verify server) */ NULL, /* capath to direcoty with trusted certificates */
NULL /* if randfile!=NULL: use a file with random data to seed randomness */
))
{
soap_print_fault(&proxy, stderr);
return false;
}
proxy.soap_endpoint = "https://api.livechatinc.net"; ///< Server API address
// Authorizing user "sample@livechatinc.com" with password "samplepassword"
int authRet = proxy.authorize("sample@livechatinc.com", "samplepassword", SessionID);
if (authRet == SOAP_OK)
{
// Authorization OK
printf("Authorization OK. SessionID: %s\n\n", SessionID.c_str());
}
else if (authRet == SOAP_SVR_FAULT)
{
// Authorization error
printf("Authorization error: %s\n\n", proxy.soap_fault_string());
}
else
{
// Connection error
printf("Error while trying to call authorize method\n\n");
}
// Now we can use other methods using SessionID
Code example - adding new contact
Now if you have authorized yourself, you can call other methods using your unique SessionID. Here is an example of adding new contact using proxy class generated with gsoap. It adds private contact to licence 1111 and returns new contact ID to contactID parameter.
std::string contactID;
int ret = proxy.addContact(livechatID, SessionID, 1111, true, contactID);
if (ret == SOAP_OK)
{
if (contactID.empty())
{
printf ("addContact failed, no new contactID\n\n");
}
else
{
// Method call OK
printf("New contact ID: %s\n\n", contactID.c_str());
}
}
else if (ret == SOAP_SVR_FAULT)
{
// Not authorized
printf("Authorization error: %s\n\n", proxy.soap_fault_string());
}
else
{
// Conection error
printf("Error while trying to call addContact method\n");
}
API reference
Api reference is available here: Server API reference.
