I have a WebApi project where I have a method that takes a start date and an end date, runs a report, and returns the results. I'm trying to come up with the route for this and so far its looking like
/api/MarketingEmailStatisticsReports/DateRange/{startDate}/{endDate}
Perhaps there is a better route but that really isn't the problem.
I was testing this by simply opening a browser and typing the URL. If I set the startDate and endDates as DateTime fields, I get a 404 Not Found. If I make them strings, I can enter the method but the dates aren't parsable when I attempt to convert them from strings to actual DateTime values.
I realize that if I use "/" characters in the date that will be a problem so I did attempt to use "-" characters as the separator between the month-day-year values.
After looking at some of the Microsoft documentation, I saw how you can put route constraints to check for a DateTime values as well as a regular expression to make sure the value was entered in the correct format. I have taken this advice and am using the following:
[HttpGet]
[ResponseType(typeof(MarketingEmailStatisticsReport))]
[Route("/api/MarketingEmailStatisticsReports/DateRange/{startDate:datetime:regex(^\\d{4}-\\d{2}-\\d{2}$)/{endDate:datetime:regex(^\\d{4}-\\d{2}-\\d{2}$)}")]
public IHttpActionResult Get(DateTime startDate, DateTime endDate)
I get this exception:
ArgumentException: parsing
"^\d{4}-\d{2}-\d{2}$)/{endDate:datetime:regex(^\d{4}-\d{2}-\d{2}$" -
Too many )'s.
This is the URL I was using:
api/MarketingEmailStatisticsReports/DateRange/2017-05-22/2017-05-23
It doesn't look to me that I have too many ")" characters... What do I need to do to get this to work, or should I pass the dates on the querystring instead?
You forgot to close startDate parameter definition:
.../DateRange/{startDate:datetime:regex(^\\d{4}-\\d{2}-\\d{2}$)}/{endDate:datetime...
^
this curly bracket
Related
Please check this image for more details and code its simple code but i am getting datatype mismatch error
https://i.stack.imgur.com/rDYH6.png
This is the common format to get list of records in zoho books module.
<variable> = zoho.books.getRecords(<module_name>, <org_ID>, <search>, <connection>);
module_name: Name of the module
org_id: Your organization id
search: specifies the values based on which the records will be filtered. You can specify an empty string or an empty map for this param, in which case all the records will be fetched
connection: Name of the connection
In order to get list of estimates Please do the following,
response = zoho.books.getRecords("Estimates", "54654632", "", "zbooks");
For further clarification refer this document https://www.zoho.com/deluge/help/books/fetch-records.html
If you have any other queries reach out to us at support#zohobooks.com
You are using single quotes for strings which Deluge intercepts as date or date-time strings. Use double quotes instead.
The error shown on the screenshot is caused by the single quote you're using instead of double quotes (").
You can use as following:
data = zoho.books.getRecords("Estimmates","OrganizationID","Connection");
I am making an Ajax call to ASP.NET MVC endpoint. The url is something like this (Last parameter is null):
/employee/GetAllEmp/connID/Sale Dept/Month/Year/week/null?_dc=1371101563256
Server side:
public ActionResult GetAllEmp(string connID, string deptName, string month, string year, string week, string data)
When my application send request through IE, the endpoint at the server side is not called but when same request is being made through fire fox, system is able to call correct method.
What could be the reason? I googled around but could not find any answer :(
Please provide your suggestion.
Thank you
Based on what parameters your action method expects then /null will be parsed as a string literal rather than true null.
If this data is empty you should skip it completely and make your route accept an optional parameter
What I'm trying to do is to have an api request like /api/calculator?1=7.00&2=9.99&3=5.50&4=45.76 etc. How my controller can grab the request data? The keys/codes of the query string are ints between 1 and 1000. In the query string they can be some of the 1000 codes, not necessarily all of them. The value part is doubles.
The one way I think would work is if I create a model object (ex StupidObject) with 1000 properties (should use properties named like p1, p2,..p1000 for codes now, as ints are not an allowed property name), decorated with ModelBinder. Then for the controller I could have something like GetCalcResult(StupidObject obj){...} But that doesn't seem like an elegant solution :)
I tried controllers like GetCalcResult([FromURI]Dictionary<int, double> dict){...} but dict is always null. Also without the [FromURI] I get an error. Also tried List<KeyValuePair<int, double>> as controller parameter with the same results.
Could anyone point me at the right direction or give me an working example?
One way is to avoid trying to pass the values in as a parameter and simply do
var queryValues = Request.RequestUri.ParseQueryString();
in your action method. QueryValues will be NameValueCollection that you can iterate over to get access to your query parameters.
If you really want to use a parameter, having a parameter of type [FromUri]FormDataCollection might work.
One property of my model is DateTime. I'm working with DateTime format "d.M.yyyy H:mm", i.e. day.month.year. When I pass date like 11.4.2011 (April 11th, 2011) into TryUpdateModel, it comes back as 4.11.2011, i.e. day and month swaps. Is there any way how can I instruct TryUpdateModel to parse datetime value the way I want, not the way system wants?
Thanks,
Antonin
I had the same problem and I discovered that if I use HTTPPost instead of HTTPGet MVC behaves as expected. I don't know why it solves the problem and I am still looking for the full answer to this question.
I have a ruby model that contains a date attribue which I'd like to be able to pass in as a parameter in the format dd/MM/yyyy.
However, my sqlite3 db stores the data in yyyy-MM-dd format so when a date like 20/10/2010 gets passed in, it will not be read to the database.
I am using the Sinatra framework and using haml for the markup creation.
Do I need to write a helper that takes the date string and converts it to the correct format for the db? Or can I set a format type on the models attribute?
Thanks.
You shouldn't need to worry about the database's internal representation of the date; DataMapper is there to do that for you. You just need to make sure you are passing it a valid Date object.
Check out http://ruby-doc.org/core/classes/Date.html for methods available to the Date class. For your example:
require 'date'
mydate = '20/10/2010'
mydate_obj = Date::strptime(mydate, '%d/%m/%Y')
puts "#{mydate_obj}" # prints 2010-10-20
I don't know if this can help, some time ago I had the same problem: I was using Rack::Utils.escape_html(params[:datetime]) to escape html on user input and if I typed a date in a form field like this "25/02/2013" it would be sent to the DataMapper model like this: 16/02/2013 (with escaped html codes) so it was saving it the wrong way (day ended up being the hour or something similar).
Maybe you are also using "escape_html" method in an awkward way?