Error While Updating parse.com Parse Object - javascript

We wrote the parse cloud function to update the object .
Until today morning it was working fine. Now our cloud code is not working . can you please check this ?
Below is our code to update the object which is throwing error
var point = new query(); for this line we are getting error like
TypeError: undefined is not a function
below is our full code
var query = Parse.Object.extend("Merchants");
var point = new query();
point.id = request.params.id;
point.set("keyfield1",request.params.keyfield1);
point.set("keyfield2",request.params.keyfield2);
point.set("keyfield3",request.params.keyfield3);
point.set("keyfield4",request.params.keyfield4);
point.set("keyfield5",request.params.keyfield5);
point.save(null,{
success:function(response)
{
var resp={};
resp.ResponseCode = "1000";
resp.data = response;
response.success(resp);
},
error:function(response)
{
response.error(response.status);
}
});
Can you please help us with this issue.

Try this:
var Merchants = Parse.Object.extend("Merchants");
var merchantQuery = new Parse.Query(Merchants);
merchantQuery.equalTo("<someKey>", <someVal>);
merchantQuery.find().then(...);
Hope it helps

Related

How to get JavaScript output as string in CefSharp?

I am trying to get the output of this javascript string but so far what I have tried did not work
My current code is this. response is blank what I want is 4
var task = chromiumWebBrowser1.EvaluateScriptAsync("2+2");
var response = task.Result;
MessageBox.Show(String.Format("output", response));
Any help would be great.
The EvaluateScriptAsync method returns Task<JavascriptResponse>. You can await the Task to obtain the JavascriptResponse object then get the Result or error.
JavascriptResponse response = await chromiumWebBrowser.EvaluateScriptAsync("1 + 1");
if (response.Success)
{
var onePlusOne = (int)response.Result;
}
else
{
var error = response.Message;
}

Syntax Error with simple google app script api call

I had a syntax error with a simple code line of google sheet app scripts, I am not experienced in app scripts but this is pretty straight forward syntax from any programming language. Kindly show me if I'm missing something?
I tried changing header into 'header' or "header" but syntax error was on it not recognizing the format
function loadInformation(){
//Set up service and check access
var firebaseService = getFirebaseService();
if (firebaseService.hasAccess()) {
//Set up google sheet and header row
var ss = SpreadsheetApp.getActiveSpreadsheet();
var Sheet = ss.getSheetByName("<YOUR SHEETNAME>");
Sheet.clearContents();
Sheet.appendRow([<YOUR SHEET HEADERS>]);
//Set up reference
var databaseURL = "https://xxxxxx.firebaseio.com/";
var ref = "xxxxxx";
var requestURL = databaseURL+ref+".json";
//API Call
var response = UrlFetchApp.fetch(requestURL, {
headers: {
Authorization: 'Bearer ' + firebaseService.getAccessToken()
},
method: 'get'
});
//Parse JSON
var data = JSON.parse(response.getContentText());
//Loop through JSON and append row
for (item in data){
var newRow = [item,];
Sheet.appendRow(newRow);
}
}
} else {
//Show authorization URL to user
var authorizationUrl = firebaseService.getAuthorizationUrl();
showDialog(authorizationUrl);
}
}
Error Result :
Syntax error. (line 20, file "loadInformation") Dismiss
Your "else" is outside the function. Delete the " } " before the "else".
Also, if this line is left like this it will throw another error. Be sure to have the headers actually there:
Sheet.appendRow([<YOUR SHEET HEADERS>]);
like this:
Sheet.appendRow(["a", "b", "c"]);
Like Mark said, your 'else' is outside the function.
And if you change this
Sheet.appendRow([<YOUR SHEET HEADERS>]);
to
Sheet.appendRow(["<YOUR SHEET HEADERS>"]);
the syntax error should go away.

Mailchimp Google sheet issue with the api key

All the variables are returning correct values but the the urlfetch response returns 403 or 401 (access denied).
First log output:
var payload = {
"apikey": API_KEY,
"filters": {
"sendtime_start": REPORT_START_DATE,
"sendtime_end": REPORT_END_DATE
}
};
Logger.log(payload );
Second log output:
var params = {
"method": "POST", //what MC specifies
"muteHttpExceptions": true,
"payload": payload,
"limit": 100
};
Logger.log(params);
Third log output:
var apiCall = function(endpoint) {
//issue with syntax here?
var apiResponse = UrlFetchApp.fetch(automationsList, params);
var json = JSON.parse(apiResponse);
Logger.log(apiResponse);
return json;
};
Automation API Call that is not working:
var automations = apiCall(automationsList);
var automationsData = automations.data;
for (var i = 0; i < automationsData.length; i++) {
// are these response parameters? are these specific values getting pulled from MC - these are the type of values i want?
var a = automationsData[i];
var aid = a.id; // identifies unique campaign *** does this have anything to do with the call function above - it used to be as cid b/c this was for campaigns before??
var emails_sent = a.emails_sent;
var recipients = a.recipients;
var report_summary = a.report_summary;
var settings = a.settings;
if (send_time) {
var r = apiCall(reports, cid); // why does this have cid? but the other one didn't??
var emails_sent = r.emails_sent;
var opens = r.opens;
var unique_opens = r.unique_opens;
var clicks = r.clicks;
var unique_clicks = r.unique_clicks;
var open_rate = (unique_opens / emails_sent).toFixed(4);
var click_rate = (unique_clicks / emails_sent).toFixed(4);
}
The for loop is not even gets executed because I get following error for automationsData:
TypeError: Cannot read property "data" from undefined. (line 82, file "Code")
The apiResponse there is somehow not working, any help is appreciated.
The problem is in how you set up your project in the Developers Console. Try to follow again the process here for you to verify if you already do it in the correct way.
You can also check the solution here in this SO question, he/she explained it here, why he/she get the same 401 and 403 error that you get.
As it turns out, I was using v3.0 for the Mailchimp api whereas I needed to use 2.0.

Object handling in Chrome/FF?

I have this code:
$('.gBook').click(function(){
var values = [];
var getDiff = $('#totalPrice').attr("data-value");
var i = 0;
$('td[data-check="true"]').each(function(){
var valueToPush = { };
valueToPush["price"] = $(this).attr("data-price");
valueToPush["id"] = $(this).attr("data-id");
valueToPush["diff"] = getDiff;
values.push(valueToPush);
i++;
});
var arrayToSend = {values};
$.post( '<?php echo PATH;?>ajax/updateRoom.php',arrayToSend, function(data){
if(data != "ERROR"){
$('#all-content').html(data).css("overflow-y","auto");
}else{
alert("ERROR");
}
});
});
In Chrome, this line gives an error var arrayToSend = {values}; (Uncaught SyntaxError: Unexpected token }) In Firefox everything is fine.
I guess it's because of the rather "loose" error handling of FF, but how am I doing it correctly?
I tried to initialize the object with var arrayToSend = new Object(); before the $.each, but that gives an empty array after POST.
Where is my mistake?
try this
var arrayToSend = {optionsChosen:values};
Then in php or whatever you use for data handling look for the POST variable optionsChosen.
What you did was try to make an Object with parameter array = nothing
You basically did this in your code. It doesn't take an expert to see whats wrong with this statement.
arrayToSend = new function() {
this.(new Array(1,2,3)); // This is cringeworthy if you see it like this.
}
In the example I gave it translates to this:
arrayToSend = new function() {
this.optionsChosen = new Array(1,2,3);
}

Cannot access children of JSON object

I have a JSON object musicianobj, an example of which I have pasted below:
{
id: "451026389391"
name: "John Frusciante"
type: "profile"
url: "http://open.spotify.com/artist/XXXXXXXXXXXXXX"
}
I got this from the Facebook API using the Javascript SDK. I can run console.log(musicianobj); which successfully prints the object to the log in Chrome, but console.log(musicianobj.name);, console.log(musicianobj[1]);, and console.log(musicianobj["name"]); all return undefined for no apparent reason. Any ideas?
Edit: code below.
var playFriendsTrack = function(friend){
FB.api("/"+friend+"/music.listens", function(data) {
var songname = data.data[0].data.song.title;
var artistname = "";
FB.api(data.data[0].data.song.id,function(trackdata){
var musicianobj = trackdata.data.musician;
console.log(musicianobj);
console.log(musicianobj["name"]); // Doesn't work
console.log(musicianobj.name); // Doesn't work
artistname = musicianobj[1]; // Doesn't work
});
if(artistname.length <= 0){
alert("Error! Please try another friend.")
}
}
);}
Have you decoded it? It seems it is still a string.
musicianobj = JSON.parse(musicianobj);
console.log(musicianobj.name); // Now this should work
Got it working! I had to put a [0] after musicianobj. Apparently I don't know JSON as much as I'd like to. The working code is pasted below:
var playFriendsTrack = function(friend){
FB.api("/"+friend+"/music.listens", function(data) {
var songname = data.data[0].data.song.title;
var artistname = "";
FB.api(data.data[0].data.song.id,function(trackdata){
var musicianobj = trackdata.data.musician;
console.log(musicianobj);
console.log(musicianobj[0]["name"]);
console.log(musicianobj[0].name);
artistname = musicianobj[0].name;
});
if(artistname.length <= 0){
alert("Error! Please try another friend.")
}
}
);}

Categories

Resources