Set function from API does not work

Forum for questions and support relating to the 1.28.x releases only.
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi Asker,
1st of your command created coockies.txt and second command produced this output:

Code: Select all

{
    "version": "1.28.102",
    "apiversion": "1.28.102.1"
}
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

Okay great. This is with OPT_AUTH enabled correct?
If so, your API security is working fine
marcolino7 wrote:Hi Asker,
1st of your command created coockies.txt and second command produced this output:

Code: Select all

{
    "version": "1.28.102",
    "apiversion": "1.28.102.1"
}
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi asker,
thanks for help.
Now I still need your help, to configure my Home Automation software to access the API with Authentication.
I use curl to access the ZM API, now i need to add authentication.
How can I perform this? which curl command I should use?

Thanks
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

You use curl for the APIs exactly like you did above

Step 1) You need to authenticate with ZM

Code: Select all

curl -c cookies.txt -d  "username=xxxx&password=yyyy&action=login&view=console"  http://yourZMIP/zm/index.php
Step 2) Use the authentication information along with your desired API. Example

Code: Select all

curl -b cookies.txt http://yourZMIP/zm/api/monitors.json


You use authentication by reusing the cookie state from step 1 in step 2.

You don't need to repeat Step 1 for each Step 2.
PHP has a timeout after which the cookie auth becomes invalid. I have a timer
that re-does the login (step 1) every 5 minutes. 10 minutes might be fine too (PHP has a default session timeout, the value of which I have forgotten)


marcolino7 wrote:Hi asker,
thanks for help.
Now I still need your help, to configure my Home Automation software to access the API with Authentication.
I use curl to access the ZM API, now i need to add authentication.
How can I perform this? which curl command I should use?

Thanks
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi Asker,
I tried to create a cron job executed every 5 minutes, but cookies.txt was not created.
Do you have any suggestion?

Regards
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

marcolino7 wrote:Hi Asker,
I tried to create a cron job executed every 5 minutes, but cookies.txt was not created.
Do you have any suggestion?

Regards
Make sure you specify a path for cookies.txt so you know where it is being created and its writable
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

HI asker,
path where script is executed is writable. I'll try to add an explicit path to file.

Marco
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

HI asker,
thanks for help, now coockies' generation is working.
wihtin next hours I'll finish the configuration and integration with OpenHab.

Regards

Marco

PS I would like to give a try to znNinja, where can I download the beta?

M.
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi asker,
today I did an apt-get upgrade on my ubuntu, and this updated my zoneminder installation.
Now zoneminder ask me for a recapta, but the API key is invali and I cannot login.

Can you help me?

Regards
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi asker,
I fixed recaptha upgrading the database, but now api is not working.

I did test with curl, coockies.txt is created but when i try to get version i got this:

Code: Select all


{
    "success": false,
    "data": {
        "name": "Not Authenticated",
        "message": "Not Authenticated",
        "url": "\/zm\/api\/host\/getVersion.json",
        "exception": {
            "class": "NotFoundException",
            "code": 404,
            "message": "Not Authenticated",
            "trace": [
                "#0 [internal function]: AppController->beforeFilter(Object(CakeEvent))",
                "#1 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Event\/CakeEventManager.php(244): call_user_func(Array, Object(CakeEvent))",
                "#2 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Controller\/Controller.php(674): CakeEventManager->dispatch(Object(CakeEvent))",
                "#3 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Routing\/Dispatcher.php(187): Controller->startupProcess()",
                "#4 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Routing\/Dispatcher.php(165): Dispatcher->_invoke(Object(HostController), Object(CakeRequest))",
                "#5 \/usr\/share\/zoneminder\/www\/api\/app\/webroot\/index.php(108): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))",
                "#6 {main}"
            ]
        },
        "queryLog": {
            "default": {
                "log": [
                    {
                        "query": "SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config`   WHERE `Config`.`Name` = 'ZM_OPT_USE_AUTH'    LIMIT 1",
                        "params": [],
                        "affected": 1,
                        "numRows": 1,
                        "took": 0
                    },
                    {
                        "query": "SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config`   WHERE `Config`.`Name` = 'ZM_OPT_USE_AUTH'    LIMIT 1",
                        "params": [],
                        "affected": 1,
                        "numRows": 1,
                        "took": 0
                    }
                ],
                "count": 2,
                "time": 0
            }
        }
    }
}
Same behaviour in Browser, API never authenticate. Please help.

Marco
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

If you upgraded, the changes you made to core.php were deleted. You need to redo this as per the guide

Code: Select all

 Configure::write('Session', array(
                'defaults' => 'php',
               'cookie'=>'ZMSESSID'
       ));
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi asker,
I just tried, but result is the same.

Marco
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

I just updated to 106 as well, so I know it works.

Do this: go to

http://server/zm/api/

and please post a screenshot
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi,
in browser now works, after authenticating with ZM, cake PHP is working and I can get API version.

I still have issue runnin API's call from curl

Marco
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

Hi, you really need to provide more details when you post. Just saying not working gives me no idea and I have to guess.

Please explore these options and if please post details (including exact commands you tried) if you want more help

For example:

a) You said "now it works in browser" -- how did it start working? What did you do?
b) Please post the exact curl command sequence you are trying
c) Did you verify cookies.txt is created? Did you verify it contains ZMSESSID when you cat it?
d) Please post the exact browser URL you tried (and which works)

When you respond, you should also ack/nack each step I post, not just a summary 'its working' or 'its not working'

thx
marcolino7 wrote:Hi,
in browser now works, after authenticating with ZM, cake PHP is working and I can get API version.

I still have issue runnin API's call from curl

Marco
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Locked