Solved

Problem with GraphQl - delete orders using metafieldDelete

jirnmy
Shopify Partner
6 0 0

I received this message when using GraphQL. Could you help please?

{
  "errors": [
    {
      "message": "Internal error. Looks like something went wrong on our end.\nRequest ID: 25ea121b-2774-4772-9e01-f104fa28dbec (include this in support requests).",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "requestId": "25ea121b-2774-4772-9e01-f104fa28dbec"
      }
    }
  ]
}

 

This is my code, the order Id was taken from the query above

query main {
  orders(first: 5) {
    edges{
      node {
        id
        closed
      }
    }
    pageInfo {
      hasNextPage
    }
  }
}

mutation delorder {
    second: metafieldDelete(input: {
		id: "gid://shopify/Order/2094635679805"
    }) { 
    	userErrors {field message } deletedId 
    }
}

Please notice that with the id encoded in base64, the error is the same

Accepted Solution (1)
SBD_
Shopify Staff
1829 269 407

This is an accepted solution.

Ah, I misunderstood - I thought you were trying to delete metafields.

 

I can't see an orderDelete mutation, you might need to use the REST API instead.

Scott | Developer Advocate @ Shopify 

View solution in original post

Replies 10 (10)

SBD_
Shopify Staff
1829 269 407

Hey @jirnmy 

 

The id should be the ID  of the metafield to delete. Have you tried:

 

 

mutation metafieldDelete($input: MetafieldDeleteInput!) {
  metafieldDelete(input: $input) {
    deletedId
    userErrors {
      field
      message
    }
  }
}

{
"input": { "id": "Z2lkOi8vU2hvcGlmeS9FeGFtcGxlLzE=" }
}

 

 

Scott | Developer Advocate @ Shopify 

jirnmy
Shopify Partner
6 0 0

Hi @SBD_ 

 

Could you take a look at my query please? I first get the IDs from the `main` query. And then use the IDs from that to delete the Meta in `delorder`.

Could you help point out where I'm wrong?

 

Thanks!

SBD_
Shopify Staff
1829 269 407

Hey @jirnmy 

 

You'll need the metafield ID, not the order ID. Try something like this:

 

{
  orders(first:1) {
    edges {
      node {
        id
        metafields (first:1) {
          edges {
            node {
              id
            }
          }
        }
      }
    }
  }
}

mutation metafieldDelete($input: MetafieldDeleteInput!) {
  metafieldDelete(input: $input) {
    deletedId
    userErrors {
      field
      message
    }
  }
}

{
  "input": {
    "id": "gid://shopify/Metafield/1234"
  }
}

Scott | Developer Advocate @ Shopify 

jirnmy
Shopify Partner
6 0 0

@SBD_ Thanks! I understand now.

 

However, the metafield query doesn't give me any Ids? What could be the problem?

 

The order I'm checking has the status of Cancelled. It's displaying the delete button when viewing order's detail.

SBD_
Shopify Staff
1829 269 407

What's the order ID?

Scott | Developer Advocate @ Shopify 

jirnmy
Shopify Partner
6 0 0

Here is the response, please help, thanks!

{
  "data": {
    "orders": {
      "edges": [
        {
          "node": {
            "id": "gid://shopify/Order/2119891517501",
            "metafields": {
              "edges": []
            }
          }
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 6,
      "actualQueryCost": 5,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 995,
        "restoreRate": 50
      }
    }
  }
}
SBD_
Shopify Staff
1829 269 407

Hey @jirnmy 

 

That order doesn't appear to have any metafields.

Scott | Developer Advocate @ Shopify 

jirnmy
Shopify Partner
6 0 0

My main purpose is to delete this Order. It is deletable in the Admin panel.

 

I want to delete it with the API. Could you help please?

SBD_
Shopify Staff
1829 269 407

This is an accepted solution.

Ah, I misunderstood - I thought you were trying to delete metafields.

 

I can't see an orderDelete mutation, you might need to use the REST API instead.

Scott | Developer Advocate @ Shopify 

jirnmy
Shopify Partner
6 0 0

I see.

I read some articles on the internet and it said that metafield can be used to delete Orders.

 

I will go for REST then. Thanks for your help!