I have a field in my Parse object set as Date. The object also has automatically added fields createdAt, updatedAt.
The response from the REST API looks like this
{"results":[
{
"createdAt":"2015-07-22T08:50:29.890Z",
"updatedAt":"2015-07-22T08:50:29.890Z",
"startDate":{"__type":"Date","iso":"2015-08-04T14:00:00.000Z"}
}
]}
All three fields are of type Date. However, their representation varies and it breaks the serializer.
I also noticed that they behave differently in the data browser.
Is this by design or am I doing something wrong?
"startDate": {
"__type": "Date",
"iso": "2015-08-04T14:00:00.000Z"
}
The above format is ISO date format. Parse supports ISO and all JS date formats (like the other ones). While we send data to Parse, it expects the date to be in ISO format.
You can parse the ISO date into JS format like this:
var startDate = new Date(results.startDate.iso);
Related
I want to change the deligatefromdate/deligatetodate in the person object in IBM's Maximo REST API.
If I want to set a date I use this request:
POST maximo/rest/mbo/person/12345/?_format=json&delegatefromdate=2020-12-02
My person object then is returned and the value in delegatefromdate is:
"DELEGATEFROMDATE": {
"content": "2020-12-02T00:00:00+01:00"
}
But now I want to remove the date, I dont want a delegatetodate/delegatefromdate.
I have tried:
POST maximo/rest/mbo/person/63006/?_format=json&delegatefromdate=
Value is not changed
POST maximo/rest/mbo/person/63006/?_format=json
Value is not changed
POST maximo/rest/mbo/person/63006/?_format=json&delegatefromdate=null
Error: Error 400: BMXAA4143E - The date format is not valid. Use the date format defined by your locale, or use the calendar control to enter a date.
POST maximo/rest/mbo/person/63006/?_format=json&delegatefromdate=NULL
Error: Error 400: BMXAA4143E - The date format is not valid. Use the date format defined by your locale, or use the calendar control to enter a date.
POST maximo/rest/mbo/person/63006/?_format=json&delegatefromdate=~null~
Error: Error 400: BMXAA4143E - The date format is not valid. Use the date format defined by your locale, or use the calendar control to enter a date.
POST maximo/rest/mbo/person/63006/?_format=json&delegatefromdate=~NULL~
Error: Error 400: BMXAA4143E - The date format is not valid. Use the date format defined by your locale, or use the calendar control to enter a date.
POST maximo/rest/mbo/person/63006/?_format=json&delegatefromdate=0
Date is set to: "2000-12-01T00:00:00+01:00"
I have tried with and without &addchange=
So my question is, how do I clear this date?
In the GUI I just erase the value and save and it is gone.
IBM has a record of this problem as APAR IV93341: UNABLE TO UPDATE FIELD TO NULL THROUGH THE MAXIMO REST API. Someone found it on Maximo 7.5.0.7, and the APAR fix was included in 7.6.0.8.
I am trying to make a POST request to create a new resource. In the request body it needs time stamp that is current timestamp, how to add the timestamp , how to parameterize it to current timestamp?
If it's a just timestamp you need, just add {{$timestamp}} to the request body as the value.
This would give you a Unix timestamp but if you want to use a specific format - you can use moment to do this.
How do I format {{$timestamp}} as MM/DD/YYYY in Postman?
In jquery do this:
$.post(URL,data,function(result,err){
//do whatever with data
}
In the data variable have data equal to what you need to send. To add the time stamp use
Let ts = new Date(Date.now())
And set data as ts.
{{$timestamp}} works only for Postman.
What should be the format to pass the timestamp directly to a variable of the JSON payload? I have been using Rest assured for api automation. Below is the JSON payload and i need to pass the Current time stamp to the clientTime field
{ "appVersions": { "APK": { "versionCode":4150, "versionName":"2.0.3" } }, "bEnableGlobalPayment":true, "clientTime":1551829145, }
In Postman, the dynamic variable {{$timestamp}} inserts the current Unix Time Stamp into a request. (Represented as the number of seconds since January 1, 1970)
"currentTime": "1510934784"
However, the API I am working with expects timestamps formatted as MM/DD/YYYY.
"currentDate": "11/17/2017"
How do I insert the current date (formatted as MM/DD/YYYY) into my request with Postman?
You could use moment.js with Postman to give you that timestamp format.
You can add this to the pre-request script:
const moment = require('moment');
pm.globals.set("today", moment().format("MM/DD/YYYY"));
Then reference {{today}} where ever you need it.
If you add this to the Collection Level Pre-request Script, it will be run for each request in the Collection. Rather than needing to add it to all the requests individually.
For more information about using moment in Postman, I wrote a short blog post: https://dannydainton.com/2018/05/21/hold-on-wait-a-moment/
Use Pre-request script tab to write javascript to get and save the date into a variable:
const dateNow= new Date();
pm.environment.set('currentDate', dateNow.toISOString());
and then use it in the request body as follows:
"currentDate": "{{currentDate}}"
My solution is similar to Payam's, except I am using
//older code
//postman.setGlobalVariable("currentDate", new Date().toLocaleDateString());
pm.globals.set("currentDate", new Date().toLocaleDateString());
If you hit the "3 dots" on the folder and click "Edit"
Then set Pre-Request Scripts for the all calls, so the global variable is always available.
Any future date in JavaScript (postman test uses JavaScript) can be retrieved as:
var dateNow = new Date();
var twoWeeksFutureDate = new Date(dateNow.setDate(dateNow.getDate() + 14)).toISOString();
postman.setEnvironmentVariable("future-date", twoWeeksFutureDate);
In PostMan we have ->Pre-request Script. Paste the Below snippet.
const dateNow = new Date();
postman.setGlobalVariable("todayDate", dateNow.toLocaleDateString());
And now we are ready to use.
{
"firstName": "SANKAR",
"lastName": "B",
"email": "SANKARB#GMAIL.COM",
"creationDate": "{{todayDate}}"
}
If you are using JPA Entity classes then use the below snippet
#JsonFormat(pattern="MM/dd/yyyy")
#Column(name = "creation_date")
private Date creationDate;
enter image description here
enter image description here
I have a restful class to send JSON string to POST request. Data are store in DB with UTF-8 format. But the non-english characters always display as '??????', it all works fine if I get records form #Model.
Here is the code snap of rest (Using simple JSON to encoding JSON string):
#POST
#Path("/holidaylist")
#Produces(MediaType.APPLICATION_JSON)
public String getHoliday(){
List list = new LinkedList();
// Get list of holidays
List<Holiday> holidays = em.createQuery("SELECT holiday FROM Holiday holiday").getResultList();
Map event;
for(Holiday holiday : holidays){
System.out.println("======== Holiday nameļ¼ " + holiday.getHolidayName());
event = new HashMap();
event.put("id", holiday.getHolidayId());
event.put("title", holiday.getHolidayName());
event.put("start", holiday.getStartDate().toString());
list.add(event);
}
return JSONValue.toJSONString(list);
}
Thanks in advanced.
You need to make sure that you properly handle data encoding all along, starting from the DB and to the front-end. I'm not totally familiar with the SimpleJSON api, but are sure the toJSONString uses UTF-8 encoding? Also, make sure your page where you render t
Solved by using JAXB implementation. Seems simple JSON encoding issue.
Thanks everyone.
My Station is configured to EU Location format for date: dd/mm/yyyy
Everything is working fine expect when I send a date as a parameter via HTTP get:
http://localhost:6105/assignment?date=07/02/2011
This call is received by this code:
public ActionResult Index(DateTime? date = null)
{
}
as date = 2.7.2011
any other date reference in the site is working OK and as expected (dd/mm/yyyy).
How can I resolve this ?
I had the same issue as you and found the solution at this site: Localization of dates in asp.net. The issue is that MVC does not support localization of DateTimes in GET-requests, only in POST-requests. This is by design!
The blog post mentions some javascript-hacks to avoid this issue but I'd change to use culture-invariant dates.
I know it's been 2 years but I used this method :
I pass the parameter as a string and parse it to a DateTime in the backend code :
public ActionResult Index(string date = null)
{
DatetTime realDate;
DateTime.TryParse(date, out realDate)
}