Edits history of script submission #23777 for ' Release Fulfillment Order Hold (shopify)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Release Fulfillment Order Hold
     * Release holds on a fulfillment order so it can be fulfilled. Leave hold_ids empty to release every hold the app placed.
     */
    export async function main(
      auth: RT.Shopify,
      fulfillment_order_id: string,
      hold_ids: string[] | undefined
    ) {
      const response = await fetch(
        `https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
        {
          method: "POST",
          headers: {
            "X-Shopify-Access-Token": auth.token,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify({
            query: `mutation ($id: ID!, $holdIds: [ID!]) { fulfillmentOrderReleaseHold(id: $id, holdIds: $holdIds) { fulfillmentOrder { id status fulfillmentHolds { id reason } } userErrors { field message } } }`,
            variables: {
              id: fulfillment_order_id.startsWith("gid://")
                ? fulfillment_order_id
                : `gid://shopify/FulfillmentOrder/${fulfillment_order_id}`,
              holdIds: hold_ids?.length
                ? hold_ids.map((id) =>
                    id.startsWith("gid://")
                      ? id
                      : `gid://shopify/FulfillmentHold/${id}`
                  )
                : undefined,
            },
          }),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      const { data, errors } = await response.json()
      if (errors) {
        throw new Error(JSON.stringify(errors))
      }
    
      if (data.fulfillmentOrderReleaseHold.userErrors.length) {
        throw new Error(JSON.stringify(data.fulfillmentOrderReleaseHold.userErrors))
      }
    
      return data.fulfillmentOrderReleaseHold
    }
    

    Submitted by hugo989 3 hours ago