Pass sql date from talend to Rest Api - sql

I want to send a post request to the rest API which includes an SQL date format, when I try to send the request with YYYY-MM-DD format, its showing bad request. How to properly send the data.

you can do something like this below,
#PostMapping("/date")
public void date(#RequestParam("date") Date date) {
// ...
}
Explanation: It will pass date from post request.
you can also look at this documentation
I hope, it helps!

Related

How to get the response body of JSON format when using Jenkins rest api to create job?

The .../api/json seems only working for query info with GET method. When I request /createItem?name=xxx or /createItem/api/json?name=xxx with POST method, it always return the response body of HTML。
This is very inconvenient to get error information,for example, when the job already exists,it return like this

How to set http response code in Parse Server cloud function?

A parse server cloud function is defined via
Parse.Cloud.define("hello", function(request, response) {..});
on the response, I can call response.success(X) and response.error(Y), and that sets the http response code and the body of the response.
But how do I define a different code, like created (201)?
And how do I set the headers of the response?
thanks, Tim
You are allowed to return any valid JSON from response.success(). Therefore, you could create an object with fields such as code, message, and value, so you can set the code, give it a string descriptor, and pass back the value you normally would, if there is one. This seems to accomplish what you need, though you will have to keep track of those codes across your platforms. I recommend looking up standard http response codes and make sure you don't overlap with any standards.

How to pas ISO 8601 formatted date value in GET Request

I am working on lob.com letters API. Using Postman application to test the API, facing the following error:
Postman Application to test Lob's API
The parameter "date_created" want date value in ISO 8601. I am passing the value in specified format but api returns the response having error: "date_created must be an object".
Need help!
In pre request script compute current date and set it to environment variable then you can pass it in your request body. A bit of code will look like this:
Pre Request
var date = new Date().toISOString();
postman.setEnvironmentVariable("date",date);
Request Body
// Other attribs....
"date_created" : "{{date}}"

SoftLayer REST API get Bandwidth Data By Date

I have a question regarding the use of the getBandwidthDataByDate request using the SoftLayer REST API.
In the documentation it lists 3 parameters for this request, but it's a GET request. Does anyone know how to make this request and/or have an example?
https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getBandwidthDataByDate/'device_id'.json
I'm not sure where to add the parameters here.(startDateTime, endDateTime, networkType)
And what does the dateTime object look like?
Thanks
This is a POST request, so you need to pass the parameters in "Payload" (I'm using Advanced REST client for Chrome).
Try the following REST request:
https://$user:$apiKey#api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/$device_id/getBandwidthDataByDate
Method: Post (Copy the below code in "Payload")
{
"parameters":[
"2016-03-10T00:00:00",
"2016-03-15T00:00:00",
"public"
]
}
Note: Replace $user, $apiKey and $device_id with your own information
References:
SoftLayer_Virtual_Guest::getBandwidthDataByDate

How to handle json DateTime returned from WCF Data Services (OData)

I believe I am missing something obvious here. When I request a JSON response from an OData service I get a different result for the DateTime properties than I do when I request XML. I'll use the NerdDinner OData feed as an example.
JSON:
http://www.nerddinner.com/Services/OData.svc/Dinners(1)?$format=json
"EventDate": "\/Date(1235764800000)\/"
XML:
http://www.nerddinner.com/Services/OData.svc/Dinners(1)
<d:EventDate m:type="Edm.DateTime">2009-02-27T20:00:00</d:EventDate>
When I do an alert(new Date(1235764800000)) I get this result:
I also get a result of 8PM when I run the same query with LINQPad. Why is the time zone incorrect in the JSON result? It seems to assume that the response is in GMT. Should I handle this on the client (via javascript) or is this something that I can set on the server?
I'm using jQuery on the client and WCF Data Services (and Entity Framework) on the server.
Update:
I am using Datejs on the client side to handle the UTC datetime formatting. I'm wondering if this is the correct way to go about this problem.
function getDateString(jsonDate) {
if (jsonDate == undefined) {
return "";
}
var utcTime = parseInt(jsonDate.substr(6));
var date = new Date(utcTime);
var minutesOffset = date.getTimezoneOffset();
return date.addMinutes(minutesOffset).toString("M/d/yyyy h:mm tt");
}
According to this msdn link, DateTime objects are...
...represented in JSON as "/Date(number
of ticks)/". The number of ticks is a
positive or negative long value that
indicates the number of ticks
(milliseconds) that have elapsed since
midnight 01 January, 1970 UTC.
So you are correct that .NET assumes, but it's UTC instead of GMT (though they are similar). There are some good answers here on SO that give more details and also provide methods for parsing the JSON into a usable date on the client.
As far as converting dates from UTC to a specific time zone, on the server you could use the TimeZoneInfo class which has a ConvertTimeFromUtc method. Or you could write a custom converter that inherits from the JavaScriptConverter class. In javascript, there are the UTC and getTimezoneOffset methods that could be used.
Hope this helps and good luck.
If this may help, I was facing the same problem and I ended to implement something like this, not so elegant but it works.
String.prototype.DateWCF = function(dateformat) {
return new Date(parseInt(this.match(/\/Date\(([0-9]+)(?:.*)\)\//)[1])).format(dateformat);
};
then on $.ajax success:
success: function(data) {
$.each(data, function() {
var hello = this.DateTimeProperty.DateWCF('dd-MM-yyyy'));
});
}
I hope this may be helpful.
This should work just fine:
var date = new Date(parseInt(jsonDate.substr(6)));
The substr function takes out the "/Date(" part, and the parseInt function gets the integer and ignores the ")/" at the end.
For ISO-8601 formatted JSON dates, just pass the string into the Date constructor:
var date = new Date(jsonDate); //no ugly parsing needed; full timezone support
This was already fixed and discussed that a look at this previous post
Using date.js script.Try below
new Date(parseInt(yourDateValue)).toString("ddd, dd-MMM-yyyy, hh:mm:ss")
If you're parsing WCF JSON date responses in Javascript, the Moment.js date framework removes much of the headache: Moment.js - Parsing ASP.NET JSON Dates. It also has some other handy methods.
We produce data.js as a JavaScript client for OData services. If you're working from a Web client, using this library will remove this headache as well as prevent you from running into others.
Data.js handles all of the JSONP and other concerns on your behalf, making requesting and parsing JSON data this easy:
OData.read(
"http://services.odata.org/Northwind/Northwind.svc/Categories",
function (data) {
var html = "";
$.each(data.results, function(l) { html += "<div>" + l.CategoryName + "</div>"; });
$(html).appendTo($("#target-element-id"));
}
);
Try this:
function getDate(datestr) {
return new Date(eval('new ' + datestr.replace(/\//g, '')));
}
This reply might get voted down (!!) but an alternative solution is to just change your WCF Service to return the dates in a more friendly way.
Here's some sample JSON from my WCF service, showing a UpdateDateOriginal value (using the annoying default formatting that WCF has used for my DateTime value), and a friendlier UpdateDate version of the same DateTime value.
I've posted the code to do this in the following article:
Change default date serialization in WCF