Skip to content

Fix: Dynamically extract resourceType to prevent 400 Bad Request error#22

Open
0xharkirat wants to merge 3 commits intomicrosoft:mainfrom
0xharkirat:fix-resource-type-mismatch-400
Open

Fix: Dynamically extract resourceType to prevent 400 Bad Request error#22
0xharkirat wants to merge 3 commits intomicrosoft:mainfrom
0xharkirat:fix-resource-type-mismatch-400

Conversation

@0xharkirat
Copy link

Problem

The current implementation hardcodes "resourceType": "AzureSolutionTemplatePackageConfiguration" in the application_generateUpdatePackageReferenceRequestBody() function. This causes a 400 Bad Request error when the package configuration uses a different resource type (e.g., AzureApplicationPackageConfiguration).

Error Details

When running the workflow, the API returns:

400 Bad Request: The resourceType in the request body doesn't match the actual resource type

Solution

This PR modifies the application_generateUpdatePackageReferenceRequestBody() function to:

  1. Dynamically extract the resourceType from the existing $configuration variable (which contains the current package configuration)
  2. Use jq to preserve the original resourceType and id fields while updating only the version and packageReferences

Changes Made

  • Replaced the hardcoded JSON template with a dynamic jq transformation
  • The resourceType and id are now preserved from the existing configuration
  • Only version and packageReferences are updated with new values

Before

cat <<EOF
{
    "resourceType": "AzureSolutionTemplatePackageConfiguration",  # ❌ Hardcoded
    "version": "${artifactVersion}",
    "packageReferences": [...]
}
EOF

After

echo "$configuration" | jq --arg v "$artifactVersion" --arg pkg "$packageId" '
  .version = $v
  | .packageReferences = [
      {
        "type": "AzureApplicationPackage",
        "value": $pkg
      }
    ]
'

Benefits

  • ✅ Works with any resourceType (e.g., AzureSolutionTemplatePackageConfiguration, AzureApplicationPackageConfiguration)
  • ✅ Preserves all existing configuration fields
  • ✅ Prevents 400 errors due to resource type mismatch
  • ✅ More maintainable and flexible

Testing

Tested with workflows that use different resource types and confirmed the 400 error is resolved.

Closes #21

Dynamically extract resourceType from existing configuration instead of hardcoding it as 'AzureSolutionTemplatePackageConfiguration'. This fixes the 400 Bad Request error when the package configuration uses a different resource type.
@0xharkirat
Copy link
Author

Any feedback guys?

@0xharkirat
Copy link
Author

Hi Guys,
I have been waiting for this for this since Dec 2025. Any plan to review or merge this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Dynamically extract resourceType to prevent 400 Bad Request error

1 participant