Errors Syncing Environment using PUT /environments

My team currently works on their postman collections & environments stored in an Azure DevOps git repo. I’m currently working on a side project to automatically sync the collections stored in the repo with a postman team workspace.

The idea is basically this:

  1. grab all collections & environments in git
  2. grab all collections & environments in postman workspace (using the GET /workspace API)
  3. match collection in git to collection in workspace
  4. update collection in workspace with git collection
  5. do the same for environments.

I have steps 1-4 working fine, but environments are not working for some reason. I’m always getting a 400 bad request with the following error body:

        "error": {
            "name": "invalidParamsError",
            "message": "The request had invalid parameters",
            "details": {
                "param": "key"
            }
        }
    }

Due to corporate policy I can’t send the entire environment JSON over, but the data I’m sending to Postman in the PUT request seems to be valid according to the API reference. Has anyone seen this before?

{
  "environment": {
"name":"E2E-ENV-Dev0","values":
[
{"key":"testAgency","value":"subsystem","enabled":true},
{"key":"completeFw","value":"amp_sdm660_64_IL01_AMP_R01.00.45","enabled":true},
{"key":"badFw","value":"","enabled":true},
{"key":"incompleteFw","value":"amp_sdm660_64_IL01_AMP_R1.00.24_IL01_AMP_R1.00.00","enabled"
:true},
{"key":"nonExistFw","value":"somefwpackage","enabled":true},
{"key":"postedFw","value":"","enabled":true},
{"key":"testName","value":"10.3-POST-FwRefAgency-BadInputs - Status Code 400","enabled":true},{"key":"version","value":"v1","enabled":true},
{"key":"keyid","value":"0","enabled":true},
{"key":"currentTestAgency","value":"subsystem","enabled":true},
{"key":"deviceName","value":"amp_sdm660_64","enabled":true},
{"key":"azureAgencyFwTable","value":"agencyFirmware","enabled":true},
{"key":"testAgencyName","value":"TestAgency1","enabled":true},
{"key":"deviceName","value":"amp_sdm660_64","enabled":true},
{"key":"newAgencyId","value":"","enabled":true},
{"key":"testAgencyName2","value":"TestAgency2","enabled":true},
{"key":"azureAgencyFwTable","value":"agencyFirmware","enabled":true},
{"key":"flow10AgencyName","value":"subsystem","enabled":true},
{"key":"rmApiTestAgency","value":"subsystem","enabled":true}
]}
}

I’m also seeing this error and can’t quite figure out the root cause. My goal is to have my monitor re-write some environment variables to iterate a test run so that other requests can use the new values. Here’s a simple version of my PUT request:

{
  "environment": {
    "values": [
    	{"key": "ownerID", "value": "{{ownerID}}"},
    	{"key": "postmanAPIkey", "value": "{{postmanAPIkey}}"},
    	{"key": "ownerID", "value": "{{ownerID}}"},
    	{"key": "environmentID", "value": "{{environmentID}}"},
    	{"key": "firstName", "value": "{{firstName}}"},
    	{"key": "email", "value": "{{email}}"},
    	{"key": "contactID", "value": "{{contactId}}"},
    	{"key": "externalRequestId", "value": "{{externalRequestId}}"},
    	{"key": "deadline", "value": "{{deadline}}"}
    	]
  }
}

@sam.lozano1 @DigitalSecurity this is because a bug in validate the data uniqueness in Postman backend.
In Postman frontend it allow you to have multiple env var with same key name, but failed when you try to use it API to update backend data.

As a workaround, remove the duplicate from your JSON data before sync.