This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Vistapool Integration
#1
Hi all,
 
I’m trying to get some vistapool information integrated in my logicmachine. The information is available in json format after a successful login is accomplished on the site. I have tried the following script but can’t get the parameters overview file. Any help/suggestions?
 
http = require('socket.http')
ltn12 = require('ltn12')
json = require('json')
 
user = 'joost@xxxxxx.xxx'
pass = 'xxxxxx'
remember_password = '0'
entrar = 'Enter'
poolid = 'xxxx'
 
resp = {}
url1 = 'http://www.vistapool.es/en/login/login'
url2 = 'http://www.vistapool.es/en/pool/getmainvalues?id=xxxx'
data = [[{
"user": "joost@xxxxxx.xxxx",
"pass": "xxxx",
"remember_password": "0",
"entrar": "Enter"
}]]
 
 
res, err, hdrs = http.request(url1, data)
log(res, err, hdrs)
 
if res then
  tbl = {}
  res, err = http.request({
    url = url2,
    headers = {
      cookie = hdrs['set-cookie']
    },
    sink = ltn12.sink.table(tbl),
  })
 
  if res then
    resp = table.concat(tbl)
    log(resp)
  else
    alert('request 2 failed: ' .. tostring(err))
  end
else
  alert('request 1 failed: ' .. tostring(err))
end
 
I get the following in the log (no error log, no alert info neither)
string: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es_ES" lang="es_ES">
 
 
<!--[if lt IE 9]>
    <link rel="stylesheet" type="text/css" href="sfiles/css/IE.css">
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
    <![endif]-->
 
    <head>
 
        <title>DA-GEN | DA-GEN | Accede a tu cuenta</title>
        <meta http-equiv="charset" content="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="es_ES" />
<meta http-equiv="X-UA-Compatible" content="IE=edge env=best-standards-support" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=yes" />
<meta name="robots" content="index,follow" />
        <link href="/sfiles/css/footable.core.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/footable.standalone.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/bootstrap-select.min.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/bootstrap-formhelpers.min.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/plugins/chosen/chosen.min.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/bootstrap-clockpicker.min.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/bootstrap-datetimepicker-ok.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/bootstrap.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/plugins/daterangepicker/daterangepicker-bs3.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/template.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/custom.css" media="screen" rel="stylesheet" type="..


Thank you for any help/suggestions,
regards,
Joost
Reply
#2
Can you send me login/password via PM?
Reply
#3
(07.09.2020, 07:00)admin Wrote: Can you send me login/password via PM?

Just sent via PM. 
regards,
Joost
Reply
#4
Login part in your example was incorrect. POST data must be encoded correctly.
Code:
user = 'user@example.com'
pass = 'password'
poolid = '123456'

http = require('socket.http')
ltn12 = require('ltn12')
json = require('json')

resp = {}

url1 = 'http://www.vistapool.es/en/login/login'
url2 = 'http://www.vistapool.es/en/pool/getmainvalues?id=' .. poolid

function encodepost(t)
  local res = {}
  local esc = require('socket.url').escape

  for k, v in pairs(t) do
    res[ #res + 1 ] = esc(k) .. '=' .. esc(v)
  end

  return table.concat(res, '&')
end

data = encodepost({
  user = user,
  pass = pass,
  remember_password = '0',
  entrar = 'Enter'
})

res, err, hdrs = http.request(url1, data)
log(res, err, hdrs)

if res then
  tbl = {}
  res, err = http.request({
    url = url2,
    headers = {
      cookie = hdrs['set-cookie']
    },
    sink = ltn12.sink.table(tbl),
  })

  if res then
    resp = table.concat(tbl)
    data = json.pdecode(resp)
    log(data)
  else
    alert('request 2 failed: ' .. tostring(err))
  end
else
  alert('request 1 failed: ' .. tostring(err))
end
Reply
#5
Works like a charm !! thank you very much for the help !

regards,
Joost
Reply


Forum Jump: