Adding orderid to orderMarkAsPaid boilerplate graphql syntax

Solved

Adding orderid to orderMarkAsPaid boilerplate graphql syntax

gavinramos
Tourist
3 1 0

Hello, 

I am attempting to use the OrderMarkedAsPaid mutation. I am new to graphql and don't know where to put and how to specify the order id in the below request:

 

https://shopify.dev/docs/api/admin-graphql/2023-10/mutations/orderMarkAsPaid

 

 

mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
  orderMarkAsPaid(input: $input) {
    order {
      # Order fields
    }
    userErrors {
      field
      message
    }
  }
}

 

 

 

 

I've tried putting it in the following places and returned the error: "message": "Field 'order' doesn't accept argument 'id'". 

 

 

mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
  orderMarkAsPaid(input: $input) {
    order(id:"gid://shopify/Order/5586699977000") {
      # Order fields
       id
    }
    userErrors {
      field
      message
    }
  }
}

 

 

Although if I run the query:

 

{
	order(id:"gid://shopify/Order/5586699977000") {
    id
	}
}

 

I get 

 

{
  "data": {
    "order": {
      "id": "gid://shopify/Order/5586699977000"
    }
  }
}

 

So my question is: does anyone know how I pass the orderID into this mutation and mark this order as paid?

Sorry for the novice question, appreciate any help you can give!

 

Accepted Solution (1)
gavinramos
Tourist
3 1 0

This is an accepted solution.

Liam, 

Thank you so much for pointing that out, I was trying to work within the graphiql shopify app for the time being until I figured out how graphql works overall. Now that I have that down, I will be passing in the variables outside the mutation body like you showed above so that I can automate requests for my site. 

In order to pass the variables within the mutation body I formatted it as follows and successfully marked the order as paid!

mutation orderMarkAsPaid {
  orderMarkAsPaid(input: {id:"gid://shopify/Order/5586699977000"}) {
    order {
      id,
      # ...other fields you want to return
    }
    userErrors {
      field
      message
    }
  }
}

 

 Thank you so much for your help! You're amazing!

View solution in original post

Replies 5 (5)

Liam
Shopify Staff
2846 311 811

Hi Gavinramos,

 

Great to see your trying out GraphQL. You could try specifying the order ID in the "input" object for the mutation. Here's how you would structure your mutation:

mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
  orderMarkAsPaid(input: $input) {
    order {
      # Order fields
    }
    userErrors {
      field
      message
    }
  }
}

And your variables would be:

{
  "input": {
    "id": "gid://shopify/Order/5586885542184"
 }

Please replace "gid://shopify/Order/5586885542184" with the actual Global ID of the order you want to mark as paid.

 

The Global ID is different from the regular order ID. You can get the Global ID by querying the order with its regular ID. Also note that the ID should be a string, not a number.

 

Hope this helps!

 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

gavinramos
Tourist
3 1 0

Liam,

Thank you so much for your response! After reading the graphql documentation (and practicing on a makeshift server) on passing in variables and using the input variable I'm actually more confused by the syntax than I was before. The following runs and correctly returns "message": "Variable $input of type OrderMarkAsPaidInput! was provided invalid value"

 

mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
  orderMarkAsPaid(input: $input) {
    order {
  input:
    id,
    
      
    }
    userErrors {
      field
      message
    }
  }
}

 

but the minute I try to put in the actual global id I return the following error:

 

mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
  orderMarkAsPaid(input: $input) {
    order {
  input:
    id: "gid://shopify/Order/5586699977000",
    
      
    }
    userErrors {
      field
      message
    }
  }
}

 

"message": "syntax error, unexpected COLON (\":\") at [5, 7]",

and removing the colon just returns "unexpected string". Many variations of this syntax have failed to produce any meaningful results.

I know I'm close, but I'm confused on that last part regarding actually passing in the global id, any way you could nudge in the right direction, or point to some resources I might be able to read?

 

Thanks again for your help!

 

 

Liam
Shopify Staff
2846 311 811

Hi again Gavinramos,

 

Just to confirm, are you defining the input variable as a GraphQL variable outside of the mutation body, not inside it? Also input should be passed as a variable and not hardcoded within the mutation, so it should look something like this:

 

mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
  orderMarkAsPaid(input: $input) {
    order {
      id
      // ...other fields you want to return
    }
    userErrors {
      field
      message
    }
  }
}

Hope this helps! 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

gavinramos
Tourist
3 1 0

This is an accepted solution.

Liam, 

Thank you so much for pointing that out, I was trying to work within the graphiql shopify app for the time being until I figured out how graphql works overall. Now that I have that down, I will be passing in the variables outside the mutation body like you showed above so that I can automate requests for my site. 

In order to pass the variables within the mutation body I formatted it as follows and successfully marked the order as paid!

mutation orderMarkAsPaid {
  orderMarkAsPaid(input: {id:"gid://shopify/Order/5586699977000"}) {
    order {
      id,
      # ...other fields you want to return
    }
    userErrors {
      field
      message
    }
  }
}

 

 Thank you so much for your help! You're amazing!

Liam
Shopify Staff
2846 311 811

Great to hear it's working as expected now Gavinramos - let us know if you run into any other issues!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog