AppSubscriptionCreate ERROR: Parse error on ...

Solved

AppSubscriptionCreate ERROR: Parse error on ...

johnAirRobe
Shopify Partner
6 1 2

I'm using v18.1.1 of the shopify_app in a Rails application. I'm making a request to create a usage subscription however when I make the request I get the error AppSubscriptionCreate ERROR: Parse error on "name" (IDENTIFIER) at [2, 25] and it's not clear why.

 

I'm running the client query like this:

 

 

result = client.query(query::AppSubscriptionCreate, variables: variables)

 

 

 

With variables being:

 

 

def variables
      {
        name: "Airrobe usage subscription for #{shop.name}",
        terms: "Merchant Terms: https://drive.google.com/file/d/1aE1NBoUBatp3jE1abIkGQB5Le0j1J8MK/view
        Refer to Letter to Offer, Schedule 1, which stipulates the Special Conditions for our partnership including the Commission Fee.
        For questions or concerns contact merchant support at merchantsupport@airrobe.com
        ",
        capDollars: Money.new(shop.app_subscription_cap_cents, "USD").to_s.to_f,
        returnUrl: "https://#{shop.shopify_domain}/admin",
        test: true
      }
    end

 

 

 

and my query being

 

 

 

 def query
      @query ||= client.parse <<~GRAPHQL
      mutation AppSubscriptionCreate($name: String!,$capDollars: Decimal!, $terms: String!, $returnUrl: URL!) {
        appSubscriptionCreate(
          name: $name,
          returnUrl: $returnUrl,
          lineItems: [{
            plan: {
              appUsagePricingDetails: {
                terms: $terms,
                cappedAmount: { amount: $capDollars, currencyCode: USD }
              }
            }
          }]
        ) {
          userErrors {
            field
            message
          }
          confirmationUrl
          appSubscription {
            id
            currentPeriodEnd
            name
            status
            lineItems {
              id
              plan {
                pricingDetails {
                  ... on AppUsagePricing {
                    balanceUsed
                    cappedAmount
                    interval
                    terms
                  }
                }
              }
            }
          }
        }
      }
      GRAPHQL
    end

 

 

 

However, when I run this query:

 

 

def query
      @query ||= client.parse <<~GRAPHQL
      mutation {
        appSubscriptionCreate(
          name: "whatever",
          returnUrl: "https://test.com",
          lineItems: [{
            plan: {
              appUsagePricingDetails: {
                terms: "Merchant Terms: https://drive.google.com/file/d/1aE1NBoUBatp3jE1abIkGQB5Le0j1J8MK/view
                Refer to Letter to Offer, Schedule 1, which stipulates the Special Conditions for our partnership including the Commission Fee.
                For questions or concerns contact merchant support at merchantsupport@airrobe.com",
                cappedAmount: { amount: 3.00, currencyCode: USD }
              }
            }
          }]
        ) {
          userErrors {
            field
            message
          }
          confirmationUrl
          appSubscription {
            id
            currentPeriodEnd
            name
            status
            lineItems {
              id
              plan {
                pricingDetails {
                  ... on AppUsagePricing {
                    balanceUsed
                    cappedAmount
                    interval
                    terms
                  }
                }
              }
            }
          }
        }
      }
      GRAPHQL
    end

 

 

 

It runs fine. I'm not sure what is going on here. If I cannot pass variables in from outside using the AppSubscriptionCreate(), how will I be able to pass variables in??

 

Cheers!

Accepted Solution (1)

johnAirRobe
Shopify Partner
6 1 2

This is an accepted solution.

The issue was that I'm using a named query. When I turned it into an anonymous query it worked. I did this by removing

AppSubscriptionCreate

 

From the query and the query invocation in

client.query(query::AppSubscriptionCreate, variables: variables)

 

 

View solution in original post

Reply 1 (1)

johnAirRobe
Shopify Partner
6 1 2

This is an accepted solution.

The issue was that I'm using a named query. When I turned it into an anonymous query it worked. I did this by removing

AppSubscriptionCreate

 

From the query and the query invocation in

client.query(query::AppSubscriptionCreate, variables: variables)