Giorgio Draghetti
Posts: 0
Joined: Mon Oct 27, 2014 12:13 pm

update device registration from server code

i want to update the push device registration record using server code.
I made many attempt but ... i was not able to write the correct code.
I got the error "No resource method found for POST"

I enclose here the code and the log trace.
Help me please to find where is my error!

code
/*

  • deviceReg_Update
    */

    var responseBody = {},
    requestParams = {},
    paramKeys = request.keys();
    for (var key = 0; key < paramKeys&#46;length; key++) {
    requestParams[paramKeys[key]] = request&#46;get(paramKeys[key]);
    }

    &#47;&#47; Declare database ID and Master key
    var dbId = "554xxxxxxxxxxxx7cb&quot
    var masterKey = "50b4d712-xxxxx-xxxx-xxxx-c6f7d4cf79dc&quot

    &#47;&#47; Get parameters into vars
    var appID = requestParams['appID'];
    var deviceID = requestParams['deviceID'];
    var userID = requestParams['user_id'];

    try {
    &#47;&#47;ricerca deviceID
    var devObj = XHR&#46;send("GET", "https:&#47;&#47;api&#46;appery&#46;io/rest/push/reg/" + deviceID, {
    "headers": {
    "X-Appery-App-Id": appID,
    "Content-Type": "application/json"
    }
    });
    if (devObj&#46;status != 200) {
    throw new Error(devObj&#46;body&#46;code + " - " + devObj&#46;body&#46;description);
    }
    console&#46;log("Original DevObj");
    console&#46;dir(devObj);

    &#47;&#47;update device user_id field
    var newDevObj = XHR&#46;send("POST", "https:&#47;&#47;api&#46;appery&#46;io/rest/push/reg/" + deviceID, {
    "headers": {
    "X-Appery-App-Id": appID,
    "Content-Type": "application/json"
    },
    "body": {
    "user_id": userID
    }
    });
    if (devObj&#46;status != 200) {
    throw new Error(devObj&#46;body&#46;code + " - " + devObj&#46;body&#46;description);
    }

    console&#46;log("ret value from update:");
    console&#46;log(newDevObj);

    } catch (e) {
    console&#46;log(e);
    response&#46;error(devObj&#46;body&#46;code);
    }

    /code

    Image

    Image

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

update device registration from server code

Hello Giorgio,

Please use request method PUT instead of POST

Giorgio Draghetti
Posts: 0
Joined: Mon Oct 27, 2014 12:13 pm

update device registration from server code

true ... thanks a lot... i was so stupid...

Return to “Issues”