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, }
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 want to compare two dates in client .one of them is current date that its accuracy depends on user system date accuracy .
I use nuxt.js too .is there any way that I set something in nuxt and get date from nuxt(server) in client.
unfortunately searched alot but find nothing . maybe my search was incorrect .
You could use the nuxtServerInit method and generate a timestamp from here:
In store/index.js:
actions: {
nuxtServerInit ({ commit }) {
commit('setNuxtTime', (new Date()).getTime())
}
}
If the action nuxtServerInit is defined in the store, Nuxt.js will
call it with the context (only from the server-side). It's useful when
we have some data on the server we want to give directly to the
client-side.
https://nuxtjs.org/guide/vuex-store#the-nuxtserverinit-action
Given a VSTS REST API call like this:
https://*account*/*project*/_apis/build/builds?definitions=2&minTime=????queryOrder=startTimeDescending&api-version=4.1
What is the correct datetime format for the minTime value? Everything I have tried either returns all builds, or none, and is not filtering by date. For example, I have tried "31/08/2018", "2018-08-31T12:01:31.450Z", "08/31/2018". The format is not documented anywhere that I can see.
The format for minTime should be YYYY-MM-DD.
So the request URL looks like:
https://marinaliu.visualstudio.com/Git2/_apis/build/builds?definitions=41&queryOrder=queueTimeDescending&minTime=2018-09-01&api-version=4.1
Note: when you specify minTime in the request url, it's not working to specify queryOrder with startTimeDescending. Instead, you can remove &queryOrder=startTimeDescending from url, or you can replace with queueTimeDescending.
&minTime=2022-04-18T00:00:00&maxTime=2022-04-19T23:59:00
This also worked for me with time component in addition to date component.
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 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);