Hi
Is there a way to use the Common JS functions from a GIT repo or from a Network path within Postman pre request script/Post request script.
Thank you
Kavitha
Hi
Is there a way to use the Common JS functions from a GIT repo or from a Network path within Postman pre request script/Post request script.
Thank you
Kavitha
Hey @kdayalan ![]()
Could you provide an example of these common JS functions?
Would you like to have a single script, with different functions, that can be required and used within your scripts at the Collection/Folder/Request level?
Postman has a Package Library that will give you this functionality:
Yes Single script with custom JS functions which has our business logic/complex calculations but we wanted to maintain outside the postman and retrieve it within postman script inside the Package some thing like a JAVA libraries but not all functions will be used , we use what we needed for the specific collection/request.
The Package Library lives inside Postman, that way it’s able to call these functions if Collections are run outside of the Platform, like with the Postman CLI.
You can use external packages in the scripts from NPM or JSR but those would be public packages so likely not what you required.
Private packages can be used but this functionality is not available on all plans.
We have enterprise plan with alle carte do we have Private Packages features to be used?
Thank you
Also one more question/confirmation when using the Collection id/env id /collection name using Postman CLI or Newman CLI inside CI pipeline would a Postman API call will happen for both or happens only for Newman and will be coming under 1,000,000 calls per month?
pm.require will it work both in newman and postman cli execution or will work only in Postman cli
I’m not sure that I fully understand that question - Are you using the Newman or the Postman CLI.
Just to note, the packages would only be available to use with the Postman CLI.
Got it , so if we are using external packages it will work only in Postman CLI? not in newman CLI
I am checking if we use Newman/postman cli for CI pipeline using collection id /collection name without package library both calls Postma API to retrieve remotely is that correct?
They work in different ways - To directly use the collection or environment ids, you would need to be using the Postman CLI and using your Postman API Key, if this is running in a pipeline.
You wouldn’t be able to do that with Newman, you would only be able to use an exported Collection file or the Postman API URL which fetches the Collection.
Are you using one of the tools or both of them? I’m a bit confused ![]()
I’d need more information about the way you use it now and an example of the script, to provide more details. ![]()
We are in exploration stage so looking for optimal solution thats the reason asking for both the ways to run in CI Pipeline using Postman CLi and Newman CLI which serves our need the best
I would recommend using the Postman CLI in almost every case. It always includes the latest features from Postman, so anything you use, such as the Package Library, will work as expected when run in your pipeline.
Another advantage of the Postman CLI is that it integrates directly with your Collections in the UI. This lets you view the history of your runs and compare results easily.
While the Postman CLI doesn’t provide some of the custom reporting options or the ability to use it as a library within a project, those limitations are minor. If your Collection uses newer features and functionality, those wouldn’t run properly outside the CLI anyway.
Hi Danny
Request information you said we can use private npm packages in the pre request script.
But when I tried the example package you said in of your previous community response.
pm.require(‘@npm/[email protected]’) it didnt work, how to get it work
Yes we are mostly leaning towards to Postman CLI , will check the challenges when we try to implement. thank you
It looks like they syntax you’re using isn’t correct here, it should be this for the package you mentioned:
const cryptoJs = pm.require('npm:[email protected]');
ok below is my code referring to deprecated cryptoJS what is the new code to achieve the same functionality , I tried different ways but it said not working.
var bytes = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(CryptoJS.enc.Utf8.parse(message),CryptoJS.enc.Base64.parse(secretKey)));
There was a similar topic raised around this subject, I’m not going to claim to be an expert with that library
but I had a go at trying to answer the question.
Maybe something in that thread might help you out here? ![]()