Skip to content

[releases/28.x][Shopify] Fix fulfillment service handling#6959

Open
onbuyuka wants to merge 2 commits intoreleases/28.xfrom
bugs/623993-ShpfyFulfillmentSvc-28x
Open

[releases/28.x][Shopify] Fix fulfillment service handling#6959
onbuyuka wants to merge 2 commits intoreleases/28.xfrom
bugs/623993-ShpfyFulfillmentSvc-28x

Conversation

@onbuyuka
Copy link
Contributor

@onbuyuka onbuyuka commented Mar 3, 2026

Summary

  • Check that a fulfillment service exists before querying assigned fulfillment orders
  • Handle deleted fulfillment service locations in Shopify sync

Fixes AB#623993

Cherry-picked from main:

🤖 Generated with Claude Code

onbuyuka added 2 commits March 3, 2026 17:02
…ulfillment orders (#6904)

When syncing shipments to Shopify, the `assignedFulfillmentOrders`
GraphQL call fails with "The api_client is not associated with any
fulfillment service" if the fulfillment service was disassociated on
Shopify's side (e.g., app reinstall, store migration).

## Changes

- **New GraphQL query** (`HasFulfillmentService`): Queries Shopify
locations by name to verify the fulfillment service location exists
before calling `assignedFulfillmentOrders`.
- **`GetAssignedFulfillmentOrders`**: After the existing `Fulfillment
Service Activated` flag check, queries Shopify to confirm the service
actually exists. If not, resets the flag to `false` and exits
gracefully.
- **`ShpfySyncShipmToShopify`**: Tracks queried shop codes separately to
avoid redundant API calls when a shop has no assigned fulfillment
orders.

Fixes
[AB#623365](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/623365)
### Problem

When a fulfillment service location is deleted in Shopify but the
corresponding `Shpfy Shop Location` record still exists in Business
Central, the `GetLocation` GraphQL query returns
`{"data":{"location":null}}`. The code attempted to parse
`data.location.fulfillmentService` as a single path, which fails because
the null `location` token cannot be traversed to reach
`fulfillmentService`. This left a stale record with `Fulfillment Service
Id = 0`, causing `UpdateFulfillmentServiceCallbackUrl` to proceed with
an invalid ID in the `UpdateFulfillmentService` GraphQL mutation.

### Solution

**`GetFulfillmentService`**: Split the JSON parsing into two steps.
First resolve `data.location` — if it's null (location no longer exists
in Shopify), delete the stale `ShopLocation` record (which cascades to
related `Shpfy Shop Inventory` records) and exit. Then separately
resolve `fulfillmentService` within the location object.

**`UpdateFulfillmentServiceCallbackUrl`**: After calling
`GetFulfillmentService`, recheck `Fulfillment Service Id`. If it's still
`0` (record was deleted or service couldn't be resolved), exit before
attempting the update mutation. This provides defense in depth against
calling the Shopify API with an invalid ID.

Fixes
[AB#622988](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/622988)
@onbuyuka onbuyuka requested a review from a team as a code owner March 3, 2026 16:06
@github-actions github-actions bot added the AL: Apps (W1) Add-on apps for W1 label Mar 3, 2026
@onbuyuka onbuyuka enabled auto-merge (squash) March 3, 2026 16:07
@github-actions github-actions bot added this to the Version 28.1 milestone Mar 3, 2026
@onbuyuka onbuyuka changed the title [Shopify] Fix fulfillment service handling on 28.x [releases/28.x][Shopify] Fix fulfillment service handling Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant