{"record":{"id":"8187ce21dac774a2","repo":"hashicorp/packer","slug":"unable-to-fetch-organization-list-v","errorCode":null,"errorMessage":"unable to fetch organization list: %v","messagePattern":"unable to fetch organization list: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/api/client.go","lineNumber":120,"sourceCode":"\t\t\t\tStatusCode: InvalidClientConfig,\n\t\t\t\tErr:        err,\n\t\t\t}\n\t\t}\n\t}\n\n\treturn client, nil\n}\n\nfunc (c *Client) loadOrganizationID() error {\n\tif env.HasOrganizationID() {\n\t\tc.OrganizationID = os.Getenv(env.HCPOrganizationID)\n\t\treturn nil\n\t}\n\t// Get the organization ID.\n\tlistOrgParams := organizationSvc.NewOrganizationServiceListParams()\n\tlistOrgResp, err := c.Organization.OrganizationServiceList(listOrgParams, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to fetch organization list: %v\", err)\n\t}\n\torgLen := len(listOrgResp.Payload.Organizations)\n\tif orgLen != 1 {\n\t\treturn fmt.Errorf(\"unexpected number of organizations: expected 1, actual: %v\", orgLen)\n\t}\n\tc.OrganizationID = listOrgResp.Payload.Organizations[0].ID\n\treturn nil\n}\n\nfunc (c *Client) loadProjectID() error {\n\tif env.HasProjectID() {\n\t\tc.ProjectID = os.Getenv(env.HCPProjectID)\n\t\terr := c.ValidateRegistryForProject()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"project validation for id %q responded in error: %v\", c.ProjectID, err)\n\t\t}\n\t\treturn nil\n\t}","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/api/client.go#L102-L138","documentation":"loadOrganizationID lists the HCP organizations visible to the authenticated principal via OrganizationServiceList. If that API call itself errors (network failure, auth expiry, API error), it returns `unable to fetch organization list: %v` wrapping the underlying error. This runs during client construction when the organization ID was not supplied directly.","triggerScenarios":"NewClient → loadOrganizationID is invoked (no cached org ID) and the OrganizationServiceList request fails: network error, expired/invalid token, HCP API 5xx, or the service principal lacking permission to list organizations.","commonSituations":"Service principal token expired mid-run; firewall/proxy blocking api.cloud.hashicorp.com; principal created without organization-scoped permissions; transient HCP outage during `packer init`/build.","solutions":["Re-authenticate or refresh the HCP service principal credentials, then retry","Check network reachability to the HCP API endpoint (proxy/firewall)","Grant the service principal permission to list organizations in the target org","Inspect the wrapped %v error for the HTTP status to decide between auth vs. transient failure and retry on 5xx"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"client, err := hcpapi.NewClient()\nif err != nil && strings.Contains(err.Error(), \"unable to fetch organization list\") {\n    // transient network/API failure: retry with backoff\n    return retryWithBackoff(3, func() error { _, err = hcpapi.NewClient(); return err })\n}","preventionTips":["Retry transient API failures with exponential backoff","Verify network/proxy access to api.cloud.hashicorp.com","Keep service-principal tokens fresh; re-authenticate on 401","Grant the principal org-list permissions in the target organization"],"tags":["hcp","network","api"],"backgroundTag":"api-request-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}