Error in referencing the environment variable within Postman

I'm encountering an issue while attempting to transfer a variable from JSON using Postman to an environment variable.

The variable is successfully extracted, but there seems to be an obstacle in storing it in the environment variable. Here's the current state of my code:

var allGazette = JSON.parse(responseBody);

if(allGazette.total_count!==0){
    for (i = 0; i < allGazette.total_count; i++) {
        var dateUse=allGazette.items[i].date;
        console.log(dateUse);
        postman.setEnvironmentVariable('jsonGazetteDate', dateUse);
        console.log(jsonGazetteDate);
    }
}
else(postman.setEnvironmentVariable('jsonGazetteDate',''));

The problem arises at the line where postman.set... is used. According to the console logs provided below, the dateUse is successfully retrieved as 2018-05-01. Despite my attempts with different combinations of stringify/parse methods, I have been unable to resolve this issue. Any suggestions or ideas?

GET https://api.companieshouse.gov.uk...
2018-05-01
ReferenceError | jsonGazetteDate is not defined
GetGazette: ReferenceError: jsonGazetteDate is not defined

Answer №1

It seems like there is an issue with the jsonGazetteDate variable not being declared, yet you are attempting to log it to the console. This error likely occurs during the data loop.

If your intention is to log the environment variable that was set in the previous line, you should use the following code:

console.log(pm.environment.get('jsonGazetteDate'))

Furthermore, it is advisable to replace the older Postman syntax statements with the newer pm.* functions, especially if you are using the native client app.

  • JSON.parse(responseBody) = pm.response.json()
  • postman.setEnvironmentVariable() = pm.environment.set()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Mastering data binding with Vue Js is a process that requires dedication and time

I'm a Vue JS beginner and I've created a component that repeats a grid-like section. However, I've noticed that adding a dropdown in the grid is causing a significant increase in load time. As the number of records grows, the load time will ...

Minimize all expanded containers in React

Although I've come across similar questions, none of them have addressed mine directly. I managed to create a collapsible div component that expands itself upon click. However, I am looking for a way to make it so that when one div is expanded, all o ...

Distinguish between a function and a constructor during execution

As I work with TypeScript, I am creating a function that accepts an error factory as an argument. This factory can be either a class name or a function. The function looks something like this: // Alias from class-transformer package type ClassConstructor& ...

Calculate the frequency of a specific name within a Json Array

I am looking to calculate the frequency of occurrences in a JSON Array returned by an API. Here is my data: data = [ {"id":"1939317721","pauseReason":"DISPLAY","DeptName":"Account"}, {"id":"1939317722","pauseReason":"DISPLAY","DeptName":"Admission"}, ...

Electron.js issue: ipcRenderer and ipcMain leading to a white screen problem

I am currently working on a desktop application using Electron, Vue, and Vuetify. However, I have encountered an issue where sending data from the rendererProcess to mainProcess using IPC results in a white blank screen. I'm unsure of what is causing ...

Struggling to Parse JSON Arrays in Node.js

Embarking on a journey with Node JS and Express, I find myself facing the challenge of developing a small proof of concept API in Node. The main hurdle I'm currently encountering stems from my limited understanding of how to parse JSON arrays to extr ...

Tips for using res.json as a callback function

When using a function with a callback parameter, I found that this method works perfectly fine: DB.last(user,(data) => res.json(data)); However, when attempting to refactor it for better readability as shown below: DB.last(user,res.json); The structu ...

What is the process of utilizing the JSON value within an AJAX function to integrate with a JSP

Why am I getting an undefined value outside the Ajax function when trying to generate a table with JSON data printed in both the console and JSP? <head> <title>Unique Spring MVC Ajax Demo Title</title> <script type="text/javascript" s ...

Converting a CSV File to JSON format using C#

Greetings, I come with a question that delves into the realm of “How to” rather than technicalities. My journey in C# and Json has just begun and I find myself faced with a CSV file structured like so: Upon my search, I stumbled upon some code here - ...

How to parse nested JSON data containing unknown object keys during deserialization

I am working with a nested JSON file containing 5 objects. The structure of the JSON file is as follows: { "Object1": { "Object2": { "Object3": { "Object4": [ ...

The error message received was: "The type 'List<dynamic>' is not a matching type of 'Map<dynamic, dynamic>' when performing a type cast."

Hey there, I'm just diving into the world of Flutter and ran into an issue while trying to access a folder name on my device. I used storage_Path to retrieve it, but encountered this error along the way. My app is set up to fetch the folder name from ...

Obtaining Local JSON data in a standard Flutter class

In the Services-> math_logic.dart file, I have a page dedicated to mathematical calculations where I did not use StateFul Widget. However, I encountered an error indicating that 'Future is not a subtype of String'. It seems that there was also ...

Encountering an "Undefined index" error when attempting to send a file and path using FormData through

I have a question about my code. I am trying to send a file and a path to the server. The path needs to be constructed using these variables so that I can use it to output the file later on. var FD = new FormData(); var MyString = "uploads/docs/KEP" + m ...

Dynamic binding in AngularJS with ng-repeat allows for seamless updating of data

I recently started using a helpful library called Angular Material File input <div layout layout-wrap flex="100" ng-repeat="val in UploadDocuments"> <div flex="100" flex-gt-sm="45"> <div class="md-default-theme" style="margin-le ...

What could be the reason for the failure of calling a function within an object using "this.myFunction"?

Reviewing these two code snippets, I am faced with a puzzle. The first code block fails to execute, while the second one successfully runs. This has left me perplexed, and I am seeking clarification from those who can shed some light on the matter. [My cu ...

Obtain an indeterminate value from a variable

My situation involves a dynamic variable assigned from a service, requiring a real-time calculator to update another variable using its value. Below is the relevant code snippet: $scope.getSubTotalSCTax = function(){ TableService.checkOut('SubTo ...

Unable to Display Embed Request Using Javascript in IE9 and IE10

My website allows users to embed content they create on the site into their own blogs or pages using a series of embeds. Here is the code we provide them: <script src="[EMBED PROXY URL]" type="text/javascript"></script> When this code calls ...

The loader fails to disappear even after the AJAX response has been received

I am currently working on a page that utilizes AJAX to display data. While the data is being fetched, I want to show a loading animation, and once the data has been retrieved, I want the loader to disappear. Below is a snippet of the code where I am attemp ...

Various filters have been utilized on an array of objects

Within one of my Vue components, the code structure is as follows: <li class="comment" v-for="comment in comments"> ... </li> Accompanied by a computed method: computed: { comments() { // Here lies the logic for filtering comment ...

What is the best way to continuously compare two date variables every minute using Javascript?

In my script, I have two date variables - one representing the current time and the other two minutes later. My goal is to compare both values every minute and trigger a function when the current time is greater than or equal to the latter time. Unfortun ...