"message": "input must be a 24 character hex string, 12 byte Uint

Hi,
I keep getting this message when trying to bulk update my collection
“message”: “input must be a 24 character hex string, 12 byte Uint8Array, or an integer”

This is my input data

{
  "ids": ["66679e9e54711517579556f3", "66679e9e54711517579556f4"],
  "update": { "Temperature (°C)": 28 }
}

my single get, multiple get, single post, multiple post and single put requests all work in postman, but my bulkUpdate(the example above) as well as my bulk delete and projection don’t work and keep giving me the above error.

Thanks for your help,

I suspect its the degrees celcius symbol.

Try escaping it with \u2103

{
    "ids": [
        "66679e9e54711517579556f3",
        "66679e9e54711517579556f4"
    ],
    "Temperature (\u2103)": 28
}

Postman Echo seems to read this correctly.

image

Not sure if it will be the same for the collection API. Something to try though.

Hi, thank you for your help. I have also tried
{ "ids": ["66679e9e54711517579556f4", "66679e9e54711517579556f5"], "update": { "Latitude": 100 } }
and am still getting the same message:

“message”: “input must be a 24 character hex string, 12 byte Uint8Array, or an integer”

What API documentation are you using\following?

I’ve just had a quick look at the collection API PUT and PATCH requests and I can’t see where they support bulk uploading like your JSON.

For example…

Update part of a collection | Postman Public Workspace | Postman API Network

Hi Mike Jones,

Being able to bulk update a collection was an assumption I made of POSTMAN after reading my assignment objective to bulk update a weather collection using a REST API. This possible solution I was trying was from ChatGPT4o though. If there is no way to bulk update on ids in POSTMAN than I will need to find another way. Do you have any suggestions of other places I could perform the task outside of POSTMAN?

Is it possible to bulk delete on ids in POSTMAN?

Is it possible to do projections on a variable in POSTMAN?

Thank you for help

You can bulk update collections using the collection API and a patch request.

It just won’t be a single request. You will have to create a loop using setNextRequest() to repeat the same request using your array of ids.

I don’t know what you mean by “projections on a variable”.

Bulk updating the collection using the collection API and a patch request sounds like what I want to do. How would I change the code below to do that?

router.put('/bulkUpdate', async (req, res) => {
  console.log("bulkUpdate route hit");

  try {
    const db = mongoose.connection;
    const weatherCollection = db.collection('weather');

    const { ids, update } = req.body;

    if (!Array.isArray(ids)) {
      return res.status(400).json({ message: 'ids must be an array of valid 24-character hex strings.' });
    }

    const objectIds = ids.map(id => {
      if (typeof id === 'string' && /^[a-fA-F0-9]{24}$/.test(id)) {
        return new mongoose.Types.ObjectId(id);
      } else {
        throw new Error(`Invalid _id format: ${id}. Must be a 24-character hex string.`);
      }
    });

    if (typeof update !== 'object' || Array.isArray(update) || Object.keys(update).length === 0) {
      return res.status(400).json({ message: 'Update must be a valid non-empty JavaScript object.' });
    }

    const result = await weatherCollection.updateMany(
      { _id: { $in: objectIds } },
      { $set: update }
    );

    if (result.matchedCount === 0) {
      return res.status(404).json({ message: 'No documents matched the provided ids.' });
    }

    res.json({ message: 'Documents updated successfully', modifiedCount: result.modifiedCount });
  } catch (err) {
    console.error('Error during update:', err.message);
    res.status(400).json({ message: err.message });
  }
});

The meaning of “projections” in the context of my assignment is to get all the time and temperature values for instance.

This is my new input as an array:

{
“updates”: [
{ “id”: “66679e9e54711517579556f4”, “Latitude”: 100 },
{ “id”: “66679e9e54711517579556f5”, “Latitude”: 100 }
]
}

I have tried to code it like this, but I am still getting the same error message.

router.patch('/bulkUpdate', async (req, res) => {
  console.log("bulkUpdate route hit");

  try {
    const db = mongoose.connection;
    const weatherCollection = db.collection('weather');

    const { ids, update } = req.body;

    if (!Array.isArray(ids)) {
      return res.status(400).json({ message: 'ids must be an array of valid 24-character hex strings.' });
    }

    const objectIds = ids.map(id => {
      if (typeof id === 'string' && /^[a-fA-F0-9]{24}$/.test(id)) {
        return new mongoose.Types.ObjectId(id);
      } else {
        throw new Error(`Invalid _id format: ${id}. Must be a 24-character hex string.`);
      }
    });

    if (typeof update !== 'object' || Array.isArray(update) || Object.keys(update).length === 0) {
      return res.status(400).json({ message: 'Update must be a valid non-empty JavaScript object.' });
    }

    const result = await weatherCollection.updateMany(
      { _id: { $in: objectIds } },
      { $set: update }
    );

    if (result.matchedCount === 0) {
      return res.status(404).json({ message: 'No documents matched the provided ids.' });
    }

    res.json({ message: 'Documents updated successfully', modifiedCount: result.modifiedCount });
  } catch (err) {
    console.error('Error during update:', err.message);
    res.status(400).json({ message: err.message });
  }
});

This is still my error message in POSTMAN

{
“message”: “input must be a 24 character hex string, 12 byte Uint8Array, or an integer”
}

I’m not really following what you are doing here.

Your intial post appeared to indicate that you wanted to update a Postman collection using the Postman API.

What is this mongoose database stuff?

Hi,

Apologies for the confusion. I am learning about this stuff for the first time and I don’t know enough at this stage to explain myself clearly.

I am using a MongoDB database called WeatherData with a collection called weather.

My goals are to do:

  1. a bulk update using “PUT” on ids or by some other method
  2. bulk delete using ids or by some other method
  3. get all the time and temperature pairs

Code similar to what I have shown previously has worked for:

  1. single get
  2. multiple get
  3. single put
  4. single delete

Thanks for your help

Can you please clarify what you mean by database and collection.

You can only really use Postman if the database has an API wrapper.

Whether that API supports bulk deletes without creating some type of loop will be down to the API specification.

A good specification will include example requests.

The code you posted looks like direct database interactions, and not through an API.

What does your working GET request look like?

Do you have a link to the API specification or documentation.

I used MongoDB Compass to create a database and then within that database I created a collection called weather.

I then created an API using Node.js and used the code below to successfully perform GET and POST operations using POSTMAN.

const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');

// Retrieve a single record by ID
router.get('/:id', async (req, res) => {
  try {
    const db = mongoose.connection;
    const weatherCollection = db.collection('weather');
    const document = await weatherCollection.findOne({ _id: new mongoose.Types.ObjectId(req.params.id) });
    if (!document) return res.status(404).json({ message: 'Weather not found' });
    res.json(document);
  } catch (err) {
    res.status(500).json({ message: err.message });
  }
});

// Retrieve multiple records
router.get('/', async (req, res) => {
  try {
    const db = mongoose.connection;
    const weatherCollection = db.collection('weather');
    const documents = await weatherCollection.find({}).toArray();
    res.json(documents);
  } catch (err) {
    res.status(500).json({ message: err.message });
  }
});

// Insert a single record
router.post('/', async (req, res) => {
  try {
    const db = mongoose.connection;
    const weatherCollection = db.collection('weather');
    const result = await weatherCollection.insertOne(req.body);
    const insertedDocument = await weatherCollection.findOne({ _id: result.insertedId });
    res.status(201).json(insertedDocument);
  } catch (err) {
    res.status(400).json({ message: err.message });
  }
});

// Insert multiple records
router.post('/bulk', async (req, res) => {
  try {
    const db = mongoose.connection;
    const weatherCollection = db.collection('weather');
    const result = await weatherCollection.insertMany(req.body);
    const insertedIds = Object.values(result.insertedIds);
    const insertedDocuments = await weatherCollection.find({ _id: { $in: insertedIds } }).toArray();
    res.status(201).json(insertedDocuments);
  } catch (err) {
    res.status(400).json({ message: err.message });
  }
});


module.exports = router;

Despite the above succeeding I can’t get the multiple PUT, multiple DELETE and GET “time and temperature pairs”, to work and I keep getting the same error that is the title of this discussion.

The details you just posted appear to be about the database and API, not Postman.

If you are having issues at the application level with the API code, then it sounds like a question that should be posted on a Mongoose forum or Stackoverflow.