Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

CartCreateInput isn't a defined input type (on $cartInput)

Solved

CartCreateInput isn't a defined input type (on $cartInput)

sadLily
Shopify Partner
6 0 0

I am following the official tutorial, migrate your app.

The url I used is https://XXX.myshopify.com/admin/api/2024-04/graphql.json

The script I used in Postman is 

---

{
"query": "mutation cartCreate($cartInput: CartCreateInput!) { cartCreate(input: $cartInput) { cart { id checkoutUrl lines(first: 5) { edges { node { merchandise { ... on ProductVariant { title } } quantity } } } } } }",
"variables": {
"cartInput": {
"lines": [
{
"quantity": 1,
"merchandiseId": "gid://shopify/ProductVariant/1"
}
]
}
}
}
---

However the response I got was an error
---
{
"errors": [
{
"message": "CartCreateInput isn't a defined input type (on $cartInput)",
"locations": [
{
"line": 1,
"column": 21
}
],
"path": [
"mutation cartCreate"
],
"extensions": {
"code": "variableRequiresValidType",
"typeName": "CartCreateInput",
"variableName": "cartInput"
}
},
{
"message": "Field 'cartCreate' doesn't exist on type 'Mutation'",
"locations": [
{
"line": 1,
"column": 53
}
],
"path": [
"mutation cartCreate",
"cartCreate"
],
"extensions": {
"code": "undefinedField",
"typeName": "Mutation",
"fieldName": "cartCreate"
}
},
{
"message": "Variable $cartInput is declared by cartCreate but not used",
"locations": [
{
"line": 1,
"column": 1
}
],
"path": [
"mutation cartCreate"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "cartInput"
}
}
]
}
---

Accepted Solution (1)

Eric-HAN
Shopify Partner
297 30 33

This is an accepted solution.

Hi there

1. cartCreate is a storefront api  so your url is not correct . your current url is a admin graphql url.  change it to https://XXX.myshopify.com/api/2024-04/graphql.json,

no 'admin' in that url

 2.  there is indeed no object  input type called  CartCreateInput. Instead you should use CartInput type.  so change it to the CartInput

      could refer to the doc. https://shopify.dev/docs/api/storefront/unstable/mutations/cartCreate

     

EricHAN_0-1722239548296.png

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee

View solution in original post

Replies 5 (5)

Eric-HAN
Shopify Partner
297 30 33

This is an accepted solution.

Hi there

1. cartCreate is a storefront api  so your url is not correct . your current url is a admin graphql url.  change it to https://XXX.myshopify.com/api/2024-04/graphql.json,

no 'admin' in that url

 2.  there is indeed no object  input type called  CartCreateInput. Instead you should use CartInput type.  so change it to the CartInput

      could refer to the doc. https://shopify.dev/docs/api/storefront/unstable/mutations/cartCreate

     

EricHAN_0-1722239548296.png

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
sadLily
Shopify Partner
6 0 0

Hi,

 

Thank you for replying to my question. I have two further questions I would like to ask. First, what is this migrate your app used for? I am not clear on the difference between admin and storefront.

Additionally, I have already changed the URL to https://XXX.myshopify.com/api/2024-04/graphql.json, which is the body I am using in Postman.

 

{
  "query": "mutation cartCreate($input: CartInput!){ cartCreate(input: $input) { cart { id checkoutUrl lines(first: 5) { edges { node { merchandise { ... on ProductVariant { title } } quantity } } } } } }",
  "variables": {
    "input": {
      "lines": [
        {
          "quantity": 1,
          "merchandiseId": "gid://shopify/ProductVariant/123"
        }
      ]
    }
  }
}

 

I got the response successfully, however I couldn't opened checkoutUrl. This is what I got when I tried to open the link
截圖 2024-07-29 14.04.07.png

 Did I miss something?

Eric-HAN
Shopify Partner
297 30 33

Admin Graphql Api  is designed for managing a Shopify store's backend operations. It allows developers to interact with store data, manage products, orders, customers, and other store-related entities. while  storefront API is designed for building custom storefronts and customer-facing applications. It allows developers to fetch product data, manage customer sessions, and handle checkout processes.

 

You could open the website   might be your dev store has private passwords.  check the store settings.

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
Eric-HAN
Shopify Partner
297 30 33

please ensure that your development store is properly set up and that you are logged into the correct Partners organization and development store. You can also manually create a checkout by adding products to your cart from the storefront and proceeding to checkout.

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
sadLily
Shopify Partner
6 0 0

Hi Han,

 

  I am migrating my shop to new storefront cart api from deprecated checkout api. 

  Currently, the checkout API allows me to reach the checkout page and complete the checkout process, so I believe my store is already set up and functioning. This is the checkout URL generated using the current checkout API.

https://XXX.myshopify.com/80836493596/checkouts/0d1323cc135fbf013ef1419dd4a402c6?key=12345

 

However, when I use Postman to get the checkout URL through the storefront cart API, I can not open that url. Do I need to set up anything additional to use the new storefront cart API?