Adding Customer Code blocks in the Pre- and Post- functions #955
Replies: 7 comments 32 replies
-
Hi @smiller0924 see docs here let me know if you have any questions |
Beta Was this translation helpful? Give feedback.
-
Here are the steps
6 Run the request and see if its working or not, see also |
Beta Was this translation helpful? Give feedback.
-
Ok. I have tested you suggestions. It is not parsing out the Label Buffers. It is instead returning the entire JSON Response Body as well as the filters.js as you recommended it be written. (I have zipped the response as the upload does not support .json or .js extensions). It does not appear to be running the script at all from the function from the filters.js. In fact it is ignoring the filter is even there. Any thoughts you have would be helpful. Thank you. |
Beta Was this translation helpful? Give feedback.
-
I did add the json. in front of "output...". Still no result: |
Beta Was this translation helpful? Give feedback.
-
One other thing I noticed. I get a 'lightbulb' by the line, "exports.decodeFilter = decodeFilter;" It make a recommendation to, "Convert to an ES Module". If I select that then it conversts "exports.decodeFilter = decodeFilter;" to: const _decodeFilter = decodeFilter; I've tried that modification. It seems almost as if the "json | decodeFilter" is completely ignoring the "decodeFilter" and just pushing the entire reply into my variable. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I had another thought (yes, that's a dangerous thing with me). Can I use one of the Post-Script events to create a .js script that would print my decoded ZPL buffer directly to a printer instead of sending it to a variable? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am just becoming familiar with your product. The majority of my experience is with Postman.
One of the features that I enjoy with Postman is to run custom programming either prior to or after a API call.
Here are examples of Pre-Request Scripts. The requirement is that I need to get a date to feed into a variable in a specific format:
var moment = require('moment'); pm.environment.set('PickupDate', moment().format("YYYY-MM-DD")+"T16:00:00Z");
This will get the date and then return the value in the format: 2022-12-30T16:00:00Z (Thes function is used to set a pickup request that must be in a specific format required by the carrier.
Another example would be:
var moment = require('moment') pm.environment.set("future_timestamp", moment().add(1, 'day').format("YYYY-MM-DD")+"T11:00:00Z")
This request is similar to the first. But it advanced the date by one day and returns the request as 2022-12-31T16:00:00Z
Similarly, I need to run Post scripts. In this example I am decoding a base64 document reply that returns multiple labels in an array:
The atob(newLabelBuffer) decodes the base64 to actual document language. In this case it is a Zebra ZPL printer code.
Having the ability to run code prior to an API Request and after an API Reply would be extremely helpful. It would also give me an alternative to Postman should I need it.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions