question

Jonas Johnsson avatar image
Jonas Johnsson asked

http.request Cloud Script

i get this error when i try to use http.request

{
    "code": 200,
    "status": "OK",
    "data":
    {
        "ActionId": "sendPush",
        "Version": 1,
        "Revision": 405,
        "Results": 0,
        "ResultsEncoded": "0",
        "ActionLog": "info : "err": "The best overloaded method match for 'PlayFab.LogicServer.Source.PlayFabAPI.http_request(string, string, string, string, string)' has some invalid arguments"
",
        "ExecutionTime": 0.0700015
    }
}

and my code is

function mySendPushNotification(args){
//using one signal API to send push

var result = 0;

// //send notif to player that must do turn
// var params1 = {};
//
// params1.Recipient = args.Recipient;
// params1.Subject = args.Subject;
// params1.Message = args.Message;
//
// try {
// server.SendPushNotification( params1 );

// }
// catch(err) {
// result = 0;
// }

//get the token from data
var params = {};

params.PlayFabId = args.Recipient;
params.data = {};
params.data = [ "Token" ];

userData = server.GetUserData( params );

if(!isObjectEmpty(userData.Data))
{       
    if ( userData.Data[ "Token" ] != null ) {
        _token = JSON.parse(userData.Data[ "Token" ].Value);
        if (_token.enabled != false ){
            switch(_token.platform) {
                case 0://IOS device
                    //send notif to player that must do turn
                    var params1 = {};

                    params1.Recipient = args.Recipient;
                    params1.Subject = args.Subject;
                    params1.Message = args.Message;

                    try {
                        server.SendPushNotification( params1 );
                        result = 1;
                    }
                    catch(err) {                            
                    }           
                    break;
                case 1:
                    var headers = {};
                    headers["Content-Type"] = "application/json";
                    headers["Authorization"] = "key="+ GCM_key;

                    var _contentBody = {
                        "to" : _token.token,    
                        "data" : {
                           "alert":{
                             "title": "End Turn",
                             "body": "body lalala.",
                             "number": 1
                           },
                           "BaliFied":{
                             "Scene":"GamePlay",
                             "PlayfabId":"PlayfabId",
                             "roomId":"roomId",
                           }
                        }
                      };
                    try{
                        var response = http.request(
                            "https://gcm-http.googleapis.com/gcm/send",
                            "POST",
                            _contentBody,
                            "application/json",
                            headers
                        );
                        result = 1;
                        log.info("response", response);
                    }catch(err) {
                        log.info("err", err.message);
                    };
                    break;
            }
        }else{
        }
    };
};

// var url = "https://onesignal.com/api/v1/notifications";
// //var headers = {};
// var _contentType = "application/json";
// var _type = "application/json";
//

// var _headers = JSON.stringify({
// "Content-Type": "application/json",
// "Authorization": "Basic " + RESTAPIKey
// });
//
// var _contentBody = JSON.stringify({
// "app
id": AppID,
// "contents": {en: args.Message},
// "headings": "BaliFied",
// "included
segments": ["All"]
// });
//

// var response = null;
// //response = http.request(_url, "POST", _contentBody, _type, _headers);
// try{response = http.request(_url,"POST",_contentBody,_type,_headers);
// }catch(err) {
// log.info("err", err.message);
// }
//
// log.info("response", response);
return result;

}

any updates for this cloud script?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jonas Johnsson avatar image
Jonas Johnsson answered

hello breandan/zac
ive replied your email,

thank you

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.