I am using Google App Engine with Cloud Endpoints for a simple Android application. In the backend I have the following API method, deployed to GAE:
#ApiMethod(name = "getGroupInfo", path = "groups")
public GroupInfo getGroupInfo(#Named("session") String sessionString, #Named("groupID") String groupID)
throws ForbiddenException
{
Logger.getAnonymousLogger().warning("Session string is: " + sessionString);
Logger.getAnonymousLogger().warning("GroupID is: " + groupID); }
The problem is that when I call the method from the Android client, arguments are passed in reverse order to the method: the string I pass as the first argument in client is group ID in server backend, and the other way around.
Any help would be appreciated, thank you!
AS you can read here [1]:
Method parameters in the generated client library are in alphabetical order, regardless of the original order in the backend method. As a result, you should be careful when editing your methods, especially if there are several parameters of the same type. The compiler will not be able to catch parameter-ordering errors for you.
[1] https://cloud.google.com/solutions/mobile/google-cloud-endpoints-for-android/
Related
I am very much new to android and I was studying the Retrofit 2 for networking, to send the Get why we are use the Query parameter?
It is not necessary to send Query Parameters with GET requests. It is something related to how the end point is configured on the API you are trying to consume.
While designing APIs especially GET methods certain parameters can be kept optional by specifying them as query parameters.
#GET("location")
Response getUser(#QueryParam("name") String name);
can be called by both
/location
/location?name=test
Query Parameter is not merely confined to GET requests. It can be used with other methods too e.g., DELETE, etc.
This is a concept related to HTTP methods
Retrofit uses annotations to translate defined keys and values into appropriate format. Using the #Query("key") String value annotation will add a query parameter with name key and the respective string value to the request url (of course you can use other types than string :)).
Actually, there are APIs with endpoints allowing you to pass (optionally) multiple query parameters. You want to avoid a service method declaration like the one below with “endless” options for request parameters:
public interface NewsService() {
#GET("/news")
Call<List<News>> getNews(
#Query("page") int page,
#Query("order") String order,
#Query("author") String author,
#Query("published_at") Date date,
…
);
}
You could call the .getNews service method with null values for each of the parameters to make them optional. Retrofit will ignore null values and don’t map them as query parameters. However, there is a better solution to work with complex API endpoints having various options for query parameters. Don’t worry, Retrofit got you covered!
You can explore more from the given link below:-
https://futurestud.io/tutorials/retrofit-2-add-multiple-query-parameter-with-querymap
Lets say you have following api to call:
https://api.themoviedb.org/3/movie/now_playing/api_key=1
So for you to pass the value for "api_key" dynamically, you should use #Query("api_key") as:
#GET("movie/now_playing")
Call<MovieData> getMovieData(#Query("api_key") String apiKey);
So here is a simple way to understand it for those that might want to use Retrofit query. Please check as follows ....
If you specify #GET("Search?one=5"), then any #Query("two") must be appended using &, producing something like Search?one=5&two=7.
If you specify #GET("Search"), then the first #Query must be appended using ?, producing something like Search?two=7.
That's how Retrofit works.
When you specify #GET("Search?"), Retrofit thinks you already gave some query parameter, and appends more query parameters using &.
Remove the ?, and you will get the desired result.
enter String BASE_URL = "https://api.test.com/";
String API_KEY = "SFSDF24242353434";
#GET("Search") //i.e https://api.test.com/Search?
Call<Products> getProducts(
#Query("one") String one,
#Query("two") String two,
#Query("key") String key
)
Result:
https://api.test.com/Search?one=Whatever&two=here&key=SFSDF24242353434
I had to call api endpoints on this query url /api/AssignedStaffClassSection/?StaffId=3071 I tried this way but failed.
Option 1 using #Query parameter
#GET(WebSchoolApi._SAPI + "/AssignedStaffClassSection/")
Call<StaffAssignedClassSectionModel> getAssignedClassSection(#Query("StaffId") String staffId);
Option 2 using #Path parameter
#GET(WebSchoolApi._SAPI + "/AssignedStaffClassSection/?StaffId={staffId}")
Call<StaffAssignedClassSectionModel> getAssignedClassSection(#Path("staffId") String _staffid);
Is there any mistake that I made over?
Thank your for your help.
For GET request you mast to use:
example.com/api/AssignedStaffClassSection/?StaffId=3071
Correct:
#GET(WebSchoolApi._SAPI + "/AssignedStaffClassSection/")
Call<StaffAssignedClassSectionModel> getAssignedClassSection(#Query("StaffId") String staffId);
You should to use #Path for
example.com/api/AssignedStaffClassSection/3071/StaffId
And it will looks like:
#GET(WebSchoolApi._SAPI + "/AssignedStaffClassSection/{staffId}/StaffId")
Call<StaffAssignedClassSectionModel> getAssignedClassSection(#Path("staffId") String _staffid);
Crash may produce if you use wrong tool.
I am making an android application on crm module of odoo 10 and I want to create quotation in odoo through my application and I am passing this various arguments to ORecordValues and after that I am calling the createRecord().So when I am clicking on save button I am calling python api and python api is giving me this error.
Database fetch misses ids (u'1') and has extra ids (1), may be caused by a type incoherence in a previous request
This is my code for inserting record in odoo.
ORecordValues values = new ORecordValues();
values.put("partner_id",resPartnerArrayList.get(idc).get_id());//parter id
values.put("date_order", binding.qOrderDate.getText().toString());
if(!expDate.isEmpty())
{
values.put("validity_date",
binding.qExpirationDate.getText().toString());
}
if(!paymentTerms.isEmpty())
{
values.put("payment_term_id",paymentTermArrayList.get(idP).get_id());//payment term id
}
if(!binding.qUntaxedAmount.getText().toString().isEmpty())
{
values.put("amount_untaxed",binding.qUntaxedAmount.getText().toString());
}
if(!binding.qTotal.getText().toString().isEmpty())
{
values.put("amount_total", binding.qTotal.getText().toString());
}
if(!binding.qTaxes.getText().toString().isEmpty())
{
values.put("amount_tax", binding.qTaxes.getText().toString());
}
return odoo.createRecord("sale.order", values);
I think you trying to pass unicode value to Many2one field. Perform a type conversion. I think in your case its payment_term_id.
Hope it will help you.
I found the Solution that work for me. I got error because i was passing the String in partner_id which odoo is taking as unicode so i parse the type of it and changed it like this. it worked for me.
values.put("partner_id",resPartnerArrayList.get(idc).get_id())
to
values.put("partner_id", Integer.parseInt
(resPartnerArrayList.get(idc).get_id()));
What is the way to send queries to Parse Server with Retrofit, rest api.
I found something like that:
trying to retrieve one object based on conditions values using Android REST API
But i don't understand how can I configure it for my kind queries in android:
#GET("classes/Mentor")
Call<OneMentorResponse> getMentor(#Query("where")
String where, #Header("X-Parse-Session-Token") String token);
pass a HashMap to query.
HashMap<String,String> sendKey=new HashMap<>;
sendKey.put("yourKey","yourValue");
yourApiInterface.getMentor(new JSONObject(sendKeyValue).toString()).new CallBack<OneMentorResponse response>{}
and implement the response and failure methods.
and also pass your header the way you are doing it.
I am new to this stuff, so I hope my question makes sense..
Basically what I want to be able to do is GET and POST data to the Google App Engine server I am running. Then, I want to be able to retrieve that same data from other devices that are accessing the server.
So let's say a user runs my app, enters in a String: "blue", and through some API that I define in an endpoint, my app takes that String and sets a GLOBAL variable that exists on my server equal to that string. ( String color = "blue" )
Then, if another user opens my app, I want him/her to be able to see color = "blue" because it has been set by another user, and if this other user wants to change the color to color = "pink", then it will change across all devices again!
So, I know how to create an API / API method, as described in the Cloud-endpoints tutorial. Example :
public class MyEndpoint {
#ApiMethod(name = "sayHi")
public MyBean sayHi(#Named("name") String name) {
MyBean response = new MyBean();
response.setData("Hi, " + name);
return response;
}
}
But how would I go about achieving what I have described above?
You cannot set "global" variables on GAE as your instances are constantly being created and destroyed to manage user traffic.
You'll have to use a shared instance like Memcache (volatile) or datastore (persistent) to reuse values across instances