Sending Onesignal / gamethrive push on JSON network request

I am trying to send a JSON request to send a push notification using the following code, but I am getting an error for a network response saying "app_id not found". I use Corona, but it does not matter if the JSON format is correct.

local json = require "json"
local function networkListener( event )

    if ( event.isError ) then
        print( "Network error!" )
    else
        print ( "RESPONSE: " .. event.response )
    end
end

        headers = {}
        headers["app_id"] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
        headers["Authorization"] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
        headers["Content-Type"] = "application/json"

        local params = {}

        commands_json =
             {
                ["contents"] = "English Message"
             }        

        postData = json.encode(commands_json)

        local params = {}
        params.header = headers
        params.body = postData

network.request( "https://onesignal.com/api/v1/notifications","POST",networkListener,params)   
+4
source share
2 answers

I could fix it.

function SendJson(url, action, in_json, callback)
  local json = require ( "json" )
  local headers = {}
  headers["Content-Type"] = "application/json"
  headers["Accept-Language"] = "en-US"
 headers["Authorization"] = "Basic  12121321313123" -- put your Rest API

  local params = {}
  params.headers = headers
  params.body = json.encode( in_json )

  network.request ( url, action, callback, params )
end

local function networkListener( event )
  if ( event.isError ) then
    print( "Network error!")
  else
    print ( "RESPONSE: " .. event.response )
  end
end
local jsonToSend = {["app_id"] = "aaaaaa-222-222-33-3333333333", --put yours App ID
                    ["contents"] = {["en"] = "George challenged you to beat his score!"},
                    ["included_segments"] = "All",
                    ["isAndroid"] = true,
                    ["isIos"] = true,}
                    --["include_player_ids"] = ["(RECIPIENT_PLAYER_ID_HERE)"]}


SendJson("https://gamethrive.com/api/v1/notifications", "POST", jsonToSend, networkListener)
+2
source

Do you have Android and Apple setup on your application in the OneSignal control panel? Platforms (isAndroid and isIos) are optional when using include_player_ids.

, , - REST API. include_player_ids, .

. OneSignal POST .

https://onesignal.com/api/v1/notifications" URL- .

+1

All Articles