Why does the WFM schedule import endpoint returns a 400 error with ‘Invalid shift pattern ID’ when triggered from a GitHub Actions pipeline?
The shift pattern must be active and available in the target organization.
The pattern is active. Terraform provider v1.9.4. Environment au-1. The CLI works locally. Fails in CI. Checking the audit logs shows the request originates from the correct sub-organization. No timezone mismatch. Just a straight 400.
The best way to fix this is to ensure the shift pattern metadata is fully synchronized in the target organization before the Terraform execution begins. While the pattern appears active, the WFM service often has a propagation delay for new entities in the CI environment, especially in the au-1 region. The 400 error usually stems from the API attempting to reference a pattern ID that exists in the database but has not yet been indexed for the bulk import scheduler.
To mitigate this, add a conditional wait in your GitHub Actions workflow. You can poll the WFM Schedule API until the pattern status returns PUBLISHED and AVAILABLE. Here is a snippet for your local-exec or a custom action step:
- name: Wait for Shift Pattern Sync
run: |
for i in {1..10}; do
STATUS=$(curl -s -H "Authorization: Bearer ${{ secrets.GC_TOKEN }}" \
"https://api.au-1.genesyscloud.com/v2/wfm/schedules/groups/${GROUP_ID}/shiftpatterns/${PATTERN_ID}" \
| jq -r '.status')
if [[ "$STATUS" == "PUBLISHED" ]]; then
echo "Pattern is ready."
break
fi
echo "Waiting for index propagation... ($i)"
sleep 10
done
Additionally, verify that the Terraform state file does not contain a stale reference to a previous draft version of the pattern. If the pattern was edited and republished, the ID remains the same, but the internal versioning might cause the bulk import validator to reject it if the metadata hash does not match.
This approach ensures the chain of custody for the schedule data remains intact and prevents import failures due to race conditions in the CI pipeline.
The documentation actually says you must wait for the published status, not just active. In Zendesk, tags were instant, but GC WFM needs that propagation window. Adding a sleep or waiting for the webhook event fixed it for me.