Live Helper Chat support forum.. Forum is locked. New place for questions - Github Discussions

You are not logged in.

Announcement

#1 2020-08-07 11:21:23

JoeBunting
New member
Registered: 2020-08-07
Posts: 9

REST API - Retrieve chat

Hello,

I am trying to use to REST API, for a mobile app. Can initiate chats and add messages to them from the mobile app user.

However, when I try to retrieve either the chat or its messages I get ...

request ... restapi/fetchchat?chat_id=22

response ...
{
    "error": true,
    "result": "Could not find chat by chat_id in archive!"
}

Prior to that I have initated a new chat

request ...

{
  "ignore_required": true,
  "ignore_bot": false,
  "department": [
    1
  ],
  "vid": "mobi1213",
  "fields": {
    "Question": "Can you see this from the API ?",
    "Username": "Mobile - Jack",
    "AcceptTOS": true,
    "r": "Mobile App",
    "user_timezone": 0
  }
  ]   
}

response ...


    "error": false,
    "result": {
        "id": 22,
        "nick": "Mobile - Jack",
        "status": 0,
        "status_sub": 0,
        "status_sub_sub": 0,
        "time": 1596798566,
        "user_id": 0,
        "sender_user_id": 0,
        "hash": "caa99b28f1471bc01f2aad6d31d13c95a21b434f",
        "ip": "151.230.236.126",
        "referrer": "",
        "dep_id": 1,
        "email": "",
        "user_status": 0,
        "support_informed": "",
        "country_code": "gb",
        "country_name": "United Kingdom",
        "phone": "",
        "user_typing": 0,
        "user_typing_txt": "",
        "operator_typing": 0,
        "has_unread_messages": 0,
        "last_user_msg_time": 0,
        "last_msg_id": 121,
        "mail_send": 0,
        "lat": "",
        "lon": "",
        "city": "",
        "additional_data": "[{\"h\":true,\"identifier\":\"age\",\"key\":\"Age\",\"value\":18}]",
        "session_referrer": "Mobile App",
        "wait_time": 0,
        "chat_duration": 0,
        "priority": 0,
        "online_user_id": 24,
        "lsync": 1596798566,
        "transfer_if_na": 0,
        "transfer_timeout_ts": 0,
        "transfer_timeout_ac": 0,
        "transfer_uid": 0,
        "pnd_time": 1596798566,
        "cls_time": 0,
        "auto_responder_id": 0,
        "user_tz_identifier": "Atlantic/Azores",
        "na_cb_executed": 0,
        "nc_cb_executed": 0,
        "fbst": 0,
        "operator_typing_id": 0,
        "chat_initiator": 0,
        "chat_variables": "",
        "remarks": "",
        "operation": "",
        "operation_admin": "",
        "screenshot_id": 0,
        "unread_messages_informed": 0,
        "reinform_timeout": 0,
        "last_op_msg_time": 0,
        "has_unread_op_messages": 0,
        "unread_op_messages_informed": 0,
        "user_closed_ts": 0,
        "unanswered_chat": 1,
        "product_id": 0,
        "usaccept": 0,
        "status_sub_arg": "",
        "tslasign": 0,
        "chat_locale": "",
        "chat_locale_to": "",
        "uagent": "PostmanRuntime/7.26.2",
        "anonymized": 0,
        "invitation_id": 0,
        "device_type": 0,
        "gbot_id": 0,
        "updateIgnoreColumns": [],
        "department": {
            "id": 1,
            "name": "Department",
            "email": "",
            "priority": 0,
            "sort_priority": 0,
            "department_transfer_id": 0,
            "transfer_timeout": 0,
            "identifier": "",
            "xmpp_recipients": "",
            "xmpp_group_recipients": "",
            "mod_start_hour": -1,
            "mod_end_hour": -1,
            "tud_start_hour": -1,
            "tud_end_hour": -1,
            "wed_start_hour": -1,
            "wed_end_hour": -1,
            "thd_start_hour": -1,
            "thd_end_hour": -1,
            "frd_start_hour": -1,
            "frd_end_hour": -1,
            "sad_start_hour": -1,
            "sad_end_hour": -1,
            "sud_start_hour": -1,
            "sud_end_hour": -1,
            "inform_delay": 0,
            "inform_options": "",
            "inform_close": 0,
            "online_hours_active": 0,
            "disabled": 0,
            "hidden": 0,
            "inform_unread": 0,
            "inform_unread_delay": 0,
            "na_cb_execute": 0,
            "nc_cb_execute": 0,
            "active_balancing": 0,
            "max_active_chats": 0,
            "max_timeout_seconds": 0,
            "attr_int_1": 0,
            "attr_int_2": 0,
            "attr_int_3": 0,
            "visible_if_online": 0,
            "inform_close_all": 0,
            "inform_close_all_email": "",
            "pending_max": 0,
            "pending_group_max": 0,
            "exclude_inactive_chats": 0,
            "max_ac_dep_chats": 0,
            "active_chats_counter": 14,
            "delay_before_assign": 0,
            "pending_chats_counter": 7,
            "closed_chats_counter": 0,
            "assign_same_language": 0,
            "product_configuration": "",
            "bot_configuration": "",
            "delay_lm": 0,
            "is_overloaded": false,
            "bot_configuration_array": []
        },
        "additional_data_array": []
    }
}

So I am fairly sure the chat_id is 22, but no matter what retrieval I try to do it always says the chat is not found in the archive.

Any help or advice would be welcomed !

Thanks, Joe.

Offline

#2 2020-08-07 12:46:36

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: REST API - Retrieve chat

Here all works... Not much i can do.

Offline

#3 2020-08-07 12:48:59

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: REST API - Retrieve chat

Api is done such way it tries to load chat first from normal table and then looks in archive table. So chat does not exists or you making call to wrong api/server

Offline

#4 2020-08-07 13:05:28

JoeBunting
New member
Registered: 2020-08-07
Posts: 9

Re: REST API - Retrieve chat

Thanks for your help Remdex, so far as I can see a chat with that id does exist in the lh_chat table, and I use the API to list chats it also appears in that so I think it does exist so far as I can tell. I can also pose as an operator and see the chat and post messages to it. Also the widget api fetchmessages can retrieve data for that chat as well

Could there by any server related config which would affect this, I am using the bitnami azure vm ?

Offline

#5 2020-08-07 13:06:53

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: REST API - Retrieve chat

For me it just sounds you are making request to wrong server...

Offline

#6 2020-08-07 13:32:25

JoeBunting
New member
Registered: 2020-08-07
Posts: 9

Re: REST API - Retrieve chat

Thanks for the very quick response, its the same server, I have only one of them and using postman I am literally leaving the server related part of the URL alone and just fiddling with the stuff after /restapi to make different calls.

I have just double and triple checked, the server is the same one to initiate the chat and from where i try to retrieve chat from. Puzzling !

Would turning on the debug setting help with this kind of issue ?

Offline

#7 2020-08-07 14:17:09

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: REST API - Retrieve chat

Request has to be like this. chat_id is get variable. You did not pasted how your curl request looks like. Most likely you are sending it as post. Please refer to https://api.livehelperchat.com/#/chat/g … _fetchchat


curl -X GET "https://demo.livehelperchat.com/restapi … oups=false" -H "accept: application/json" -H "authorization: Basic YWRtaW46ZGVtbw=="

Offline

#8 2020-08-07 14:41:43

JoeBunting
New member
Registered: 2020-08-07
Posts: 9

Re: REST API - Retrieve chat

So this is what I am sending

[== Undefined ==]
curl -X GET "http://<URL>/restapi/fetchchat?chat_id=7&department_groups=false" -H "accept: application/json" -H "authorization: Basic <BLAH>"

The server replies

[== Undefined ==]
<b>Notice</b>:  Undefined index: chat_id in <b>/opt/bitnami/apps/livehelperchat/htdocs/cache/compiledtemplates/4b1822b81ce258f7a37e5b2ee65c3c81.php</b> on line <b>2</b><br />
<br />
<b>Notice</b>:  Undefined index: chat_id in <b>/opt/bitnami/apps/livehelperchat/htdocs/cache/compiledtemplates/4b1822b81ce258f7a37e5b2ee65c3c81.php</b> on line <b>2</b><br />
{"error":true,"result":"Could not find chat by chat_id in archive!"}

If I just list chats, I can see that chat

[== Undefined ==]
            "id": 7,
            "nick": "Visitor",
            "status": 1,
            "status_sub": 0,
            "status_sub_sub": 0,
            "time": 1596810989,
            "user_id": 3,
            "sender_user_id": 0,
            "hash": "9a93f32d3221a2b0ed00d9d67c8056c20c826698",

And if I use the widget api I can see this

[== Undefined ==]
{
    "status": 1,
    "status_sub": 0,
    "op": "",
    "uw": false,
    "msop": 0,
    "lmsop": 3,
    "ott": false,
    "vtm": 1,
    "message_id": 54,
    "messages": "<div class=\"message-row response\" id=\"msg-52\" data-op-id=\"0\"><div class=\"msg-date\">15:36:29</div><span class=\"usr-tit vis-tit\" title=\"Edit nick\"  role=\"button\">\n    <i title=\"Visitor\" class=\"material-icons chat-operators mi-fs15 mr-0\">face</i>\n    <span class=\"user-nick-title\">Visitor</span>\n</span>                \r\n                                                <div class=\"msg-body\">\n        hello, i would like to chat    </div>\n    \r\n                    \r\n                \r\n                            </div>\r\n\t \r\n\r\n\r\n\r\n\r\n\r\n\t\t        <div class=\"message-row message-admin operator-changes\" id=\"msg-54\" data-op-id=\"3\" title=\"15:37:42\">\r\n                <span class=\"usr-tit op-tit\">\n            <i title=\"Developer\" class=\"material-icons chat-operators mi-fs15 mr-0\">account_box</i>\n        <span class=\"op-nick-title\">Developer</span>\n    </span>\r\n                \r\n                                                        <div class=\"msg-body\">\n        Well hello visitor    </div>\n    \r\n                        \r\n                \r\n                            </div>"
}

Offline

#9 2020-08-07 14:48:04

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: REST API - Retrieve chat

I know the problem. You are using bitnami and long time ago i reported that get variables are not working in their preconfigured env. Please update nginx config from official version

Offline

#10 2020-08-07 14:53:58

JoeBunting
New member
Registered: 2020-08-07
Posts: 9

Re: REST API - Retrieve chat

Ah, yes I had a problem with bitnami stripping out authorization headers as well, probably this is a similar thing.

Will fix that and try again, it does make sense - the only things not working are where its a query parameter.

Thanks very much :-)

Offline

#11 2020-08-07 15:21:18

JoeBunting
New member
Registered: 2020-08-07
Posts: 9

Re: REST API - Retrieve chat

In case anyone else has this issue with Bitnami, I changed the rewrite rule in /opt/bitnami/apps/livehelperchat/conf/htaccess.conf

from

[== Undefined ==]
RewriteRule ^(.*)?$ index.php?/$1 [L]

to

[== Undefined ==]
RewriteRule ^(.*)?$ index.php?/$1 [L,QSA]

That did the trick, thanks again Remdex.

Offline

Board footer