Error when calling the ApiMethod with optional parameters - google-app-engine

I have created a ApiMethod and marked couple of arguments as #Nullable. From my client webpage when i am making a request its throwing the below error. It was worked fine when i tested the samples (Greetings.java). But not in my API. Any ideas what I am missing?
{
"error" : {
"message" : "java.lang.IllegalArgumentException",
"code" : 400,
"errors" : [ {
"domain" : "global",
"reason" : "badRequest",
"message" : "java.lang.IllegalArgumentException"
} ]
}
}
Here is my code samples:
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.Named;
import com.google.api.server.spi.config.Nullable;
#ApiMethod(name = "adddetails", path = "admin/adddetails")
public Details addDetails(
#Named("date") long date,
#Named("hours") int hours,
#Named("weekend") #Nullable boolean weekend,
#Named("holiday") #Nullable boolean holiday
Inside my webpage (html page)
var request = api.adddetails({
"date": date.getTime(),
"hours": 0
});
request.execute();
If I ran below lines then the ApiMethod is called without any errors:
var request = api.adddetails({
"date": date.getTime(),
"hours": 0,
"weekend": row.weekend,
"holiday": row.holiday
});
request.execute();
I have checked the myapi.api file and inside that it shows the parameters as "required" : false so that mean i am received the correct api on to client side. But not sure whats going wrong.
I am testing on localhost.

Use Boolean, not boolean for parameters marked Nullable. There should probably be a warning for using it with primitives, which of course, can't be null.

Related

Use data from graphql response in React

I guess this is a simple issue, but I am stuck here for a while, so any advice may be helpful!
I have a react app and I am calling a GraphQL api (with apollo). Inside an arrow function component I have:
const [executeQuery, { data }] = useLazyQuery(GET_ALL_TASKS);
const findId = (step) => {
executeQuery({
variables: {
"query": {
"state": "CREATED",
"taskDefinitionId": "something"
}
}
})
}
The query is successful and in the browser inspect panel I get this as the graphql response:
{
"data" : {
"tasks" : [ {
"id" : "2251",
"name" : "some_name",
"__typename" : "Task"
} ]
}
}
In my code I want to use the retrieved id. How can I isolate the id from the response? When I am trying to access the data I get an undefined error.
Thank you!
Not sure why you are wrapping your executeQuery in a function.
The data will be part of the response so you can get it like this:
const {data, loading} = executeQuery({
variables: {
"query": {
"state": "CREATED",
"taskDefinitionId": "something"
}
}
})
// may also need to check for the error state
if(loading){
console.log("Loading...")
}else{
/// the ids seem to be an array of objects
const ids = data.tasks.map((task)=> task.id)
console.log(ids)
}
For anyone who may have the same problem, I realized it is a caching error happening in apollo client. I couldn't figure out the solution. However, I temporarily solved it by downgrading the apollo client dependency to version 3.2.5

Why is my Model.find().fetch() returning data from Mongodb on the server side but then returning [ ] on the client in Meteor?

I have added console logs in the schema file, and retrieved data from the database by running meteor mongo :
{ "_id" : ObjectId("5f0d8af2b08fc89eadef0dd1"), "title" : "Hello world!" }
{ "_id" : ObjectId("5f0d8af9b08fc89eadef0dd2"), "title" : "Hello world!s" }
{ "_id" : ObjectId("5f0d9449b08fc89eadef0dd3"), "title" : "Hello world!s" }
{ "_id" : ObjectId("5f0f2d7eb08fc89eadef0dd4"), "title" : "Task1" }
and still, the same data is retrieved via the server-side through a console log I added on the subscription function:
Schema.js
if (Meteor.isServer) {
Meteor.publish('tasks', function task() {
console.log(Tasks.find({}).fetch(),' ttttttttttttttttttttttt');
return Tasks.find({}).fetch();
});
}
Then when I try to return the same data in another file, it actually fails to return the data and instead returns this in the console:
[] "These are the results"
Get.js
const getAllTasks=()=>{
sub=Meteor.subscribe('tasks').ready();
const tasks = Tasks.find({}).fetch();
console.log(tasks, 'These are the results');
return tasks
}
Here's my file structure
Question
Please help me figure out what I am potentially doing wrong?
Are you exposing the pub to your client? Download meteor dev tools (I know this is on chrome but not sure of other browsers) and you can see which publications are reaching your client and what in your db the client has access to.

Receiving "Invalid 'changeType'" when subscribing to user created event

I am trying to create a Webhook (aka Subscription) for users who are created, updated, or deleted in Office 365.
With the "changeType": "updated" it works fine but with "changeType": "created" it returns an error:
This is the request:
{
"changeType": "created,updated,deleted",
"notificationUrl": "https://ourLink",
"resource": "users",
"expirationDateTime": "2017-12-16T14:49:57Z",
"clientState": "pe1g9gqiVsE6KnHTUuK9Tts3o660KOAw9YnavVfKhr22I7FlqC0tfMhpayxrqFP4orFPOjK0rppYtDicvxZosbvOEEgfy3YYoM3FGDwLQiW4MAdSCTdQkffuChjmB"
}
Error:
{
"header": 400,
"body": {
"error": {
"code": "InvalidRequest",
"message": "Invalid 'changeType' attribute: 'created'.",
"innerError": {
"request-id": "74454900-d3df-4962-b58e-cfd7ec7454bc",
"date": "2017-12-13T16:49:59"
}
}
}
}
Creating a subscription to a user resource is only available in the Beta API
but according to the documentation, it should work.
Based on the error message and that the User Webhook sample application only handles updated and deleted, this should be the expected behavior.
I'm also unable to find where in the documentation it states that a user resource accepts subscriptions for created. If you could provide a link I will make sure the documentation gets updated.

SalesForce Chatter Rest API - Can not set CreatedDate

I want to set the createdDate for a new feed-element (via SalesForce Rest API).
I tried to do this:
{
"body" : {
"messageSegments" : [
{
"type" : "Text",
"text" : "When should we meet for release planning? "
}]
},
"feedElementType" : "FeedItem",
"subjectId" : "0060Y00000XYZXYZ",
"createdDate ": "2016-10-27T08:01:56.000Z"
}
But I get this error message:
[
{
"errorCode": "JSON_PARSER_ERROR",
"message": "Unrecognized field \"createdDate \" at [line:-1, column:-1]"
}
]
I read that I can set the createdDate via API (https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_feed_element.htm), but I don't find a example or a way to do this.
Also I tried to set the createdDate in a update request, but the same result.
I hope someone can help me. Thanks!

Required String parameter 'licenceplate' is not present"

I checked in different existing questions that was asked for similar problem but I didn't get any help for my problem.
In fact I can't use #RequestBody like in this question or this one.
I'm trying to pas some parameters from Angular controller to a Spring MVC controller, but I'm getting this error message
errorCode:500
message:"Required String parameter 'licenceplate' is not present"
here is my Angular Service:
myApp.httpEnterVehicle = function(levelNumber, placeNumber, licenceplate, placeType) {
return $http.put("/myApp/rest/vehicle/entervehicle", {
params : {
'licenceplate' : licenceplate,
'placeType' : placeType,
'placeNumber' : placeNumber,
'levelNumber' : levelNumber
},
});
};
and nothing was detected on my backend side wich seems to be strange
#RequestMapping(value = "/entervehicle", method = RequestMethod.PUT)
public ResponseEntity<Void> enterNewVehicle(#RequestParam("licenceplate") String licenceplate, #RequestParam("placeType") String placeType, #RequestParam("levelNumber") int levelNumber, #RequestParam("placeNumber") int placeNumber){
....
}
do you have any idea what's going on? I already tried toc check the content of my Angular service param and they are correct :(
You have incorrect put request call, it should look like below
$http.put('url', //1st parameter
{}, //request body
{} //request configuration here
);
If you compare you current put call you can see what wrong thing you were doing. You just need to pass {}(empty object) in request body the pass your config object in place of request body
myApp.httpEnterVehicle = function(levelNumber, placeNumber, licenceplate, placeType) {
return $http.put("/myApp/rest/vehicle/entervehicle",
{}, //added blank object as request body
{
params : {
'licenceplate' : licenceplate,
'placeType' : placeType,
'placeNumber' : placeNumber,
'levelNumber' : levelNumber
},
});
};

Resources