Getting 500 error into frisby delete request - jasmine

Hello I am facing 500 error during delete request into frisby. The code is below please correct me if I have done any wrong..!
var frisby = require('frisby');
//get the current UTC time from this URL: (https://currentmillis.com/)
var now = new Date();
var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds())
var currentUTCTime = now_utc.getTime() - (now_utc.getTimezoneOffset() * 60000);
frisby.create('Authentication for Delete Request Valid User Name and Password')
.delete('http://example.com',
{
headers:
{
'Accept':'application/json',
'Auth-Username':'abcd',
'X-Application-Key':'xyzzzz',
'Content-Type':'application/json',
'x-locale':'en_US',
'x-microtime':currentUTCTime, //get the current UTC time
'auth-signature': 'example', // Added new auth-signature for new responses
}
}
)
.expectStatus(200)
.toss()

500 signifies internal server error. Which means your REST call broke something in the server. Please check server logs to see the real issue. There might be some problem server side for this.

Related

How to update an User with useMasterKey in Parse

Issue Description
I'm trying to update an User when another user click on my Xamarin button.
Then, I used Cloud Code to perform this but it doesnt work
My Code
Here is my complete JS code :
Parse.Cloud.beforeSave("Archive", function(request, response) {
Parse.serverURL = 'https://pg-app-0brffxkawi8lqvf2eyc2isqrs66zsu.scalabl.cloud/1/';
var status = request.object.get("status");
if (status == "validated") {
var event = request.object.get("event");
event.fetch({
success: function(myEvent) {
var coinsEvent = myEvent.get("coins");
var user = request.object.get("user");
user.fetch({
success: function(myUser, coinsEvent, user) {
var email = myUser.get("email");
var coinsUser = myUser.get("coins");
myUser.set("coins", coinsUser + coinsEvent);
return myUser.save(null, {useMasterKey:true});
}
});
}
});
}
response.success();
});
I think myUser.save(null, {useMasterKey:true}); should work
I actually have that error :
Dec 24, 2017, 12:27 GMT+1 - ERRORError generating response for [PUT] /1/classes/_User/1GPcqmn6Hd
"Cannot modify user 1GPcqmn6Hd."
{
"coins": 250
}
Environment Setup
Server
parse-server version : v2.3.3
Server: Sashido
Your success branch never calls response.success() which is a problem... though maybe not THE problem.
You are also doing 2 fetches inside a 'beforeSave' function which is not recommended. 'BeforeSave' must happen very quickly and fetches take time. I would consider thinking through other options.
If you really need to do it this way, consider doing a Parse.Query("event") with an include("user") and trigger the query with query.first({useMasterKey:true}).
Are you sure coinsEvent is what you think it is? Fetch only returns the object fetched... not sure that you can curry in other parameters. I would change your final success routine to (double checking that coinsEvent is valid):
success: function(myUser) {
var coinsUser = myUser.get("coins");
myUser.set("coins", coinsUser + coinsEvent);
return myUser.save(null, {useMasterKey:true}).then(_ => response.success());
}

Parse server Having to Logout/Login on each deployment. Session getting destroyed?

Issue Description
Migrated from Parse.com to Parse Server (Sashido hosting). Whenever I deploy my cloud code, I had to logout and login on the client app (iOS) to get results. Without re-logging in, I get empty results. The session token on the client side matches with DB. My request.user prints correctly. Only the queries are not working, no session errors but empty results (array or object). This happens to all queries and it was working fine in Parse.com platform. I have ACLs defined for each row and ACL in request.user is also correct but still no results.
Steps to reproduce
Client iOS code
let configuration = ParseClientConfiguration {
$0.applicationId = PARSE_APPLICATION_ID
$0.clientKey = PARSE_CLIENT_KEY
$0.server = PARSE_SERVER_URL
$0.localDatastoreEnabled = true
}
Parse.initializeWithConfiguration(configuration)
PFUser.enableRevocableSessionInBackground()
Server
Parse.Cloud.define("getPastWalks", function(request, response) {
console.info("user:: " + JSON.stringify(request.user) + JSON.stringify(request.params));
var fromDate = request.params.fromDate;
var toDate = request.params.toDate;
var walk = Parse.Object.extend("Walk");
var pastWalksQuery = new Parse.Query(walk);
pastWalksQuery.greaterThanOrEqualTo("dateAndTime", fromDate);
pastWalksQuery.lessThanOrEqualTo("dateAndTime", toDate);
pastWalksQuery.descending("dateAndTime");
pastWalksQuery.include("service");
pastWalksQuery.limit(request.params.limit);
pastWalksQuery.find().then(function(walks) {
console.info("past walk:: " + JSON.stringify(walks));
response.success(walks);
}, function(error) {
response.error(error);
})
});
Expected Results
The above code should retrieve 'all walks for that particular request.user'.
Actual Outcome
But I am getting empty array. When I logout and login, new session token is generated and it works. Without re-logging, no session token errors, only empty array.
Environment Setup
Server
parse-server version : 2.2.25-1
Localhost or remote server? : Sashido Hosting
Database
MongoDB version: -
Localhost or remote server? : Sashido Hosting
I had to pass sessionToken in the query
pastWalksQuery.find({sessionToken: request.user.getSessionToken()})
https://github.com/ParsePlatform/parse-server/issues/3456

Push via parse server cloud code: Url not found

After working with Parse for a considerable time on multiple project I recently started moving data to a local Parse server and writing a sample app to get familiar with the system. I managed to get most working so far including Push using het Parse Dashboard.
Unfortunately I can't seem to get Parse Push to work using cloud code.
This is my code:
Parse.Cloud.define('push', function(req, res) {
var logMessage = "Push test";
console.log(logMessage);
var pushQuery = new Parse.Query(Parse.Installation);
Parse.Push.send({
where: pushQuery,
data: {
alert: 'Test'
}
}, {
useMasterKey: true,
success: function() {
// Push sent, send re
res.success('Push Sent');
var logMessage = "Push Sent!";
console.log(logMessage);
},
error: function(error) {
res.error(error)
var logMessage = error;
console.log(logMessage);
// There was a problem :(
}
});
var logMessage = "Push should be sent.";
console.log(logMessage);
});
Unfortunately no push is sent and the following error message is returned:
{
code: 107,
message: 'Received an error with invalid JSON from Parse: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL /push was not found on this server.</p>\n<hr>\n<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address>\n</body></html>\n' }
It seems to indicate the push request is sent to the /push directory of the main server, however I have no clue how I can change this to the appropriate location and I presumed parse-server would automatically choose the right path.
I hope someone might know how to fix this because I'm out of ideas at the moment..
For all that deal with this same issue, here is the solution.
Thanks to Anbarasi for the correct answer. My server settings were incorrect. Upon changing the server URL to the correct settings (address + port) everything started working!

reCAPTCHA timing out on verify

Having made no changes (but also not tested this in a couple months), my reCAPTCHA code is timing out when trying to verify the user response (both on localhost and on our DEV server). The IP is rotating in the error message (216.58.218.228:443, 172.217.1.4:443, others). I would normally think that this is a firewall issue - I can't telnet to the IP/Port combinations in the error messages - but I can pull up https://www.google.com/recaptcha/api/siteverify in a browser and get an error response back quickly. Any ideas on what might be going on?
Code I normally use:
// Prepare input.
var input = new NameValueCollection
{
{ "response", captcha },
{ "secret", _settings.SecretKey }
};
// Make call.
byte[] response;
using (WebClient client = new WebClient())
{
response = client.UploadValues(_settings.VerificationUrl, Http.Verbs.POST, input);
}
// Parse response.
var body = Encoding.UTF8.GetString(response);
var result = JsonConvert.DeserializeObject<VerificationResponse>(body);
return result.Success;
Attempt at verifying through GET (as recommended here):
using (WebClient client = new WebClient())
{
var response = client.DownloadString($"https://www.google.com/recaptcha/api/siteverify?secret={_settings.SecretKey}&response={captcha}");
}
Example full error message:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 216.58.218.228:443

DoubleClick Search API 403 Errors when making request

private async Task Run()
{
//setting up OAuth 2.0 authentication
ClientSecrets secret = new ClientSecrets
{
ClientId = <My ID Here>,
ClientSecret = <My Secret Here>
};
UserCredential credentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(secret, new[] { Scope }, "user", CancellationToken.None);
//create the service
service = new DoubleclicksearchService(new BaseClientService.Initializer()
{
HttpClientInitializer = credentials,
ApplicationName = <My Application Name Here>
});
//make request to download keywords; response variable will hold Id of generated report
Report response = await service.Reports.Request(CreateRequestBody()).ExecuteAsync();
Console.WriteLine("Created Report: ID={0}", response.Id);
}
First time user of the DoubleClick Search API. The above code is my snippet attempting to make a keyword report request. Each run however, the service.Reports.Request line throws an exception. Specifically the error is:
"Google.Apis.Requests.RequestError\r\nForbidden [403]\r\nErrors [\r\n\tMessage[Forbidden] Location[ - ] Reason[forbidden] Domain[global]\r\n]\r\n"
Any ideas what's going on here? If I make the call without the ExecuteAsync() part it works fine, but then I can't get at the Id of the submitted report.
For those interested, it appears ExecuteAsync was the wrong method to use here. The retrieval of the Report object that contains the ID of the report being generated is not created asynchronously, I believe. When I changed the last bit of code to
//make request to download keywords; response variable will hold Id of report to be generated
var request = service.Reports.Request(CreateRequestBody());
response = request.Execute();
Console.WriteLine("Report being generated. Report ID: {0}", response.Id);
it worked as expected.

Resources