12

Using Postman and the following code in pre-query script

   const moment = require('moment');
   pm.globals.set("timestamp", moment().format("YYYY-MM-DDTHH:MM:SSZ"));

I get as a response

Request signature is too far in the past and has expired. Timestamp date: 2019-11-30T10:11:10+00:00

In body I am using {{timestamp}}.

I need timestamp in ISO8601 format.

If I use

    {{$timestamp}}

it returns a Linux date of 1575110444 which is correct today at 10:41

Rhothgar
  • 121
  • 1
  • 1
  • 5

2 Answers2

29

It seems there is now an $isoTimestamp variable available out of the box

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
12

Check this out postman inbuilt variables

{{$timestamp}} is postman's inbuilt dynamic variables which will return always unix timestamp. what you can do is rename the variable you setting -

const moment = require('moment');
pm.globals.set("timestamp1", moment().format("YYYY-MM-DDTHH:mm:ssZ"));

and use it {{timestamp1}}

Notice the $ sign in the inbuilt variable.

check this thread for more info

Update

From June 2020 onwards there is inbuilt variable provided for this as $isoTimestamp- for more details refer the documentation - https://learning.postman.com/docs/writing-scripts/script-references/variables-list/#common

Dev
  • 2,739
  • 2
  • 21
  • 34
  • Thanks for your answer that resolved that issue. I had supposed that the $ might mean it was Linux syntax but I'm no expert and I didn't want to assume. Now onto a signature issue. I'm new to all this so am doing stacks of research to try and self-teach before bombarding others with my problems. – Rhothgar Nov 30 '19 at 15:13
  • 1
    Also, I've now shortened it to const moment = require('moment'); pm.globals.set("timestamp", moment().format()); and it still seems to work fine! – Rhothgar Nov 30 '19 at 15:15
  • 1
    Shouldn't the format be "YYYY-MM-DDTHH:mm:ssZ" instead? – Sue Maurizio Jul 01 '20 at 14:54