Injecting a variable into POST JSON call in Postman Flow

161 Views Asked by At

I am using postman flow for my POST calls. I have a variable, organizationId, that I would like to insert into my JSON body of my POST call. But I am getting the following error: body: "invalid character 'a' after object key:value pair"

Below is my flow:

enter image description here

This is the JSON of my POST call:

 {
  "title": "Joe's Yearbooks",
  "merchantId": {{organizationId}},
  "description": "Printing yearbooks for 3 decades.",
  "imageUrl": "https://example.com/image.jpg",
  "websiteUrl": "https://www.joeyearbooks.com",
  "support_phone": {
    "countryCode": "1",
    "phoneNumber": "2345678900"
  },
  "support_email": "[email protected]",
  "status": "ACTIVE",
  "organizationIds": [
    "123e4567-e89b-12d3-a456-426614174000"
  ]
}

Am I missing something here?

1

There are 1 best solutions below

2
Bench Vue On BEST ANSWER

You missing the variable "organizationhId" in your collection.

Steps

enter image description here

Step 1

Access Collection Settings: Locate the collection you want to modify in Postman. To access its settings, click on the three dots (ellipsis) menu situated to the left of the collection name.

Step 2

Edit Collection: From the menu that appears, select the "Edit" option. This will open the collection's settings in a new window or tab.

Step 3

Navigate to Variables: In the collection settings window, find and select the "Variables" tab. This tab is dedicated to managing the variables associated with this particular collection.

Step 4

Set Your Variable: In the "Variables" section, enter the name of your variable in the "Key" field. For example, type organizationId as the key. Then, in the corresponding "Value" field, input the value you wish to assign to this variable.

These steps will guide you through the process of adding or modifying a collection variable in Postman, ensuring your collections are well-organized and your variables are correctly set up for your API testing needs.

I demoed with own mock REST server for creating organization POST call by express library.

And call it by Postman POST request and

Flows will display pick up the "organizationId" and display by Log Block.

Server code

Save as 'server.js'

const express = require('express');
const app = express();
const port = 3000;

app.use(express.json());

let organizationIdCounter = 1;

// Endpoint for creating an organization
app.post('/organization', (req, res) => {
    // Extract the body from the request
    const organizationData = req.body;

    // Generate a unique organization ID
    const organizationId = organizationIdCounter++;

    // Add the organizationId to the response
    organizationData.organizationId = organizationId;

    // Send back the organization data with the new organizationId
    res.json(organizationData);
});

app.listen(port, () => {
    console.log(`Server running on http://localhost:${port}`);
});

Install dependency and run it

npm install express
node server.js

enter image description here

Call from Postman

enter image description here

Call from Flows

enter image description here