{"record":{"id":"22b4e3f548a950db","repo":"puppetlabs/puppet","slug":"an-environment-parameter-must-be-specified","errorCode":null,"errorMessage":"An environment parameter must be specified","messagePattern":"An environment parameter must be specified","errorType":"http","errorClass":"Puppet::Network::HTTP::Error::HTTPBadRequestError","httpStatus":400,"severity":"error","filePath":"lib/puppet/network/http/api/indirected_routes.rb","lineNumber":86,"sourceCode":"    # this also depluralizes the indirection_name if it is a search\n    method = indirection_method(http_method, indirection_name)\n\n    # check whether this indirection matches the prefix and version in the\n    # request\n    if url_prefix != IndirectionType.url_prefix_for(indirection_name)\n      raise Puppet::Network::HTTP::Error::HTTPBadRequestError, _(\"Indirection '%{indirection_name}' does not match url prefix '%{url_prefix}'\") % { indirection_name: indirection_name, url_prefix: url_prefix }\n    end\n\n    indirection = Puppet::Indirector::Indirection.instance(indirection_name.to_sym)\n    unless indirection\n      raise Puppet::Network::HTTP::Error::HTTPNotFoundError.new(\n        _(\"Could not find indirection '%{indirection_name}'\") % { indirection_name: indirection_name },\n        Puppet::Network::HTTP::Issues::HANDLER_NOT_FOUND\n      )\n    end\n\n    unless environment\n      raise Puppet::Network::HTTP::Error::HTTPBadRequestError, _(\"An environment parameter must be specified\")\n    end\n\n    unless Puppet::Node::Environment.valid_name?(environment)\n      raise Puppet::Network::HTTP::Error::HTTPBadRequestError, _(\"The environment must be purely alphanumeric, not '%{environment}'\") % { environment: environment }\n    end\n\n    configured_environment = Puppet.lookup(:environments).get(environment)\n    unless configured_environment.nil?\n      configured_environment = configured_environment.override_from_commandline(Puppet.settings)\n      params[:environment] = configured_environment\n    end\n\n    if configured_environment.nil? && indirection.terminus.require_environment?\n      raise Puppet::Network::HTTP::Error::HTTPNotFoundError, _(\"Could not find environment '%{environment}'\") % { environment: environment }\n    end\n\n    params.delete(:bucket_path)\n","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/network/http/api/indirected_routes.rb#L68-L104","documentation":"Every request to a v3 indirected route must carry an environment query parameter. The handler removes it from params with params.delete(:environment) and then checks it; if it is absent, the request fails with HTTP 400 'An environment parameter must be specified'. The environment selects which manifest and module set the master uses to answer the request.","triggerScenarios":"GET /puppet/v3/catalog/mynode with no ?environment=..., PUT /puppet/v3/report/mynode without the query parameter, or a custom client that sends the environment as a header or in the body instead of the query string.","commonSituations":"Raw curl calls that copy the path but drop the query string; scripts ported from the v2 API where the environment was part of the path; clients that misname the parameter (env= instead of environment=); proxies that discard the query string on rewrite.","solutions":["Append ?environment=production (or the target environment) to the request URL","In client code always pass it explicitly, e.g. conn.get(\"/puppet/v3/catalog/#{certname}\", environment: Puppet[:environment])","Verify no proxy/rewrite rule strips the query string before the request reaches the master"],"exampleFix":"# before\ncurl \"https://puppet.example.com:8140/puppet/v3/catalog/mynode\"\n\n# after\ncurl \"https://puppet.example.com:8140/puppet/v3/catalog/mynode?environment=production\"","handlingStrategy":"validation","validationCode":"def build_indirected_url(indirection, key, environment)\n  raise ArgumentError, 'environment is required' if environment.nil? || environment.to_s.empty?\n  \"/puppet/v3/#{indirection}/#{key}?environment=#{environment}\"\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat environment as a mandatory argument in every helper that builds Puppet REST URLs","Log the full URL including query string when debugging API clients"],"tags":["http","environment","missing-parameter","rest-api"],"backgroundTag":"missing-required-parameter","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}