admin管理员组

文章数量:1356940

Using below snippet:

var timestamp = $.now().toString();
postman.setEnvironmentVariable("timestamp", timestamp);
postman.setEnvironmentVariable("apikey", obfuscateApiKey('yourapikey', timestamp));

Getting error: There was an error in evaluating the Pre-request Script: ReferenceError: $ is not defined

Not good in JavaScript, need to check.

Using below snippet:

var timestamp = $.now().toString();
postman.setEnvironmentVariable("timestamp", timestamp);
postman.setEnvironmentVariable("apikey", obfuscateApiKey('yourapikey', timestamp));

Getting error: There was an error in evaluating the Pre-request Script: ReferenceError: $ is not defined

Not good in JavaScript, need to check.

Share Improve this question edited Dec 15, 2017 at 15:55 Stefan 2,0682 gold badges36 silver badges55 bronze badges asked Dec 15, 2017 at 15:15 Niati AroraNiati Arora 1292 gold badges3 silver badges8 bronze badges 2
  • Sounds like you need to include jquery. Also, not sure this has anything to do with java... – user184994 Commented Dec 15, 2017 at 15:17
  • Do you mean Postman, the API testing app? What do you do exactly? Seems to me that you're just missing a lib like jQuery that defines the $ – Stefan Commented Dec 15, 2017 at 15:18
Add a ment  | 

3 Answers 3

Reset to default 3

try

var timestamp = (new Date).getTime().toString(); instead of var timestamp = $.now().toString();

Postman doesn't use jQuery, but you can use a cutdown version of it called CheerioJS, see the documentation here.

It doesn't support now() but from the jQuery documentation for now():

The $.now() method is a shorthand for the number returned by the expression (new Date).getTime()

So you can just use the standard javascript here.

See this postman blog post for more info on using CheerioJS within postman.

You could achieve this without the need to use CheerioJS in Postman.

You could use the built-in {{$timestamp}} global variable that gets created at runtime but that only seems to work in URL, Headers etc.

So you could just do this, for example:

var timestamp = (new Date).getTime().toString()
postman.setEnvironmentVariable("apikey", obfuscateApiKey('yourapikey', 
timestamp))

本文标签: javascriptPostman giving error for prerequest scriptStack Overflow