简体   繁体   中英

How can i send array of object in postman?

I have this schema and whenever i try to post request using postman, it returns me error as basic is of required type "String" but i have defined it as number. I am also having trouble posting array of objects for bonuses and deductable. It is posting empty array. What is the way to post array of objects in postman?

const LevelSchema = new Schema({
  name: {
    type: String,
    required: true
  },
  description: {
    type: String
  },
  basic: {
    type: Number,
    required: true
  },
  bonuses: [
    {
      name: {
        type: String,
        required: true
      },
      amount: {
        type: Number,
        required: true
      }
    }
  ],
  deductables: [
    {
      name: {
        type: String,
        required: true
      },
      amount: {
        type: Number,
        required: true
      }
    }
  ],
  is_delete: {
    type: Number,
    default: 0
  }
});

You can create a new schema for bonuses and deductables . Because the share all properties, you can even use the same schema for both. For example:

const BonusesDeductableSchema = new Schema({ 
    name: { type: String, required: true},
    amount: { type: String, required: true},
});

And then, apply this schema in your LevelSchema :

const LevelSchema = new Schema({
    name: {
        type: String,
        required: true
    },
    description: {
        type: String
    },
    basic: {
        type: Number,
        required: true
    },
    bonuses: [BonusesDeductableSchema],
    deductables: [BonusesDeductableSchema],
    is_delete: {
        type: Number,
        default: 0
    }
});

I think this should work.

Then, in your postman, something like this:

{
    "name": "string",
    "description": "string",
    "basic": 1,
    "bonuses": [
        {
            "name": "string",
            "amount": 1
        },
        {
            "name": "string",
            "amount": 1
        }
    ],
    "deductables": [
        {
            "name": "string",
            "amount": 1
        },
        {
            "name": "string",
            "amount": 1
        }
    ],
    "is_delete": 1
}

Hope I helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM