OneSignal notification example code that are provided here include languages such as Node.js, C#, Python, PHP, Java, Ruby, Perl…, but there’s no Lua.
So here it is, the Lua version for Corona SDK (including a listener):
local json = require "json"
local function listener(e)
if e.isError then
print("Network Error: ", e.response)
else
print("Response: ", e.response)
end
end
local headers = { ["Content-Type"] = "application/json;charset=utf-8", ["Authorization"] = "Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj" }
local body = { ["app_id"] = "5eb5a37e-b458-11e3-ac11-000c2940e62c", ["included_segments"] = "All", ["data"] = {["foo"] = "bar"}, ["contents"] = {["en"] = "English Message"} }
network.request("https://onesignal.com/api/v1/notifications", "POST", listener, { headers=headers, body=json.encode(body) })
2 replies on “Lua code for OneSignal notification”
Hi,
Thanks for the code.
I always get the following error even though I have set everything right:
RESPONSE: {“errors”:[“app_id not found. You may be missing a Content-Type: application/json header.”]}
Any idea why I’m getting that error?
Sorry I don’t have an answer but googled “app_id not found. You may be missing a Content-Type: application/json header.” and found some solutions that may be useful for you.