Lua - making use of the API with Lua code, 301 errors

29 views
Skip to first unread message

Node Central

unread,
Jan 5, 2021, 3:51:54 PM1/5/21
to sipgate API
Hi,

I hope someone can help, I’m trying to make use of the API using the Lua programming language (which I’m learning) - I’ve been successful with other 3rd party apis but not Sipgate .

 With sipgate I get the following errors ., using the code below..

Message/response..
ok      1     
statusCode     301     
statusText     HTTP/1.1 301 Moved Permanently     
headers:     table: 0x2692948     
location     https://api.sipgate.com:80/v2/account/     
connection     close     
content-length     0     

Code used..

local mime = require("mime")
local http = require "socket.http"
local data = ""
local username = "user"
local password = "pass"

local function collect(chunk)
  if chunk ~= nil then
    data = data .. chunk
    end
  return true
end

local ok, statusCode, headers, statusText = http.request {
  method = "GET",
  headers = {
    ["Content-Type"] = "application/json",
    ["authentication"] = "Basic " .. (mime.b64(username ..":" .. password)),
},
  sink = collect
}

--debug - 
print("enc64", mime.b64(username ..":" .. password))
print("ok\t",         ok);
print("statusCode", statusCode)
print("statusText", statusText)
print("headers:", headers)

print("data", data)


Reply all
Reply to author
Forward
0 new messages