Js-buy-sdk: [1.0alpha] Internal error when passing customAttributes

Created on 19 May 2017  路  5Comments  路  Source: Shopify/js-buy-sdk

Steps to reproduce:

  • Pass custom Attributes to addLineItems
[...]
shopClient.addLineItems(cart.id, [{
   variantId: variant.id,
   quantity: 1,
   customAttributes: [{
     key: 'foo',
     value: 'bar'
   }],
}]);
  • resulting query:
mutation  {
  checkoutLineItemsAdd(
    checkoutId: "Z2lkOi8vc2hvcGlmeS9DaGVja291dC9jZjBhNzZkZTEwNTNmMDhhYjdlMjUxNzA1MzZiMDU5Zj9rZXk9ZDNhODE4ZGUzNjkzZjYzZDc2ZjI2NTliY2NlZThhODc=",
    lineItems: [{
      variantId: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80MDMxNDU2MTkzNA==", 
      quantity: 1,
      customAttributes: [{key: "foo", value: "bar"}]
    }]
  ) {
    userErrors {
      message
      field
    }
    checkout {
      id
      ready
      lineItems(first: 250) {
        pageInfo {
          hasNextPage
          hasPreviousPage
        }
        edges {
          cursor
          node {
            id
            title
            variant {
              id
              title
              price
              weight
              image {
                id
                src
                altText
              }
              selectedOptions {
                name
                value
              }
            }
            quantity
            customAttributes {
              key
              value
            }
          }
        }
      }
      shippingAddress {
        address1
        address2
        city
        company
        country
        firstName
        formatted
        lastName
        latitude
        longitude
        phone
        province
        zip
        name
        countryCode
        provinceCode
        id
      }
      shippingLine {
        handle
        price
        title
      }
      requiresShipping
      customAttributes {
        key
        value
      }
      note
      paymentDue
      webUrl
      order {
        id
        cancelReason
        cancelledAt
        createdAt
        updatedAt
        processedAt
        orderNumber
        subtotalPrice
        totalShippingPrice
        totalTax
        totalPrice
        currencyCode
        totalRefunded
        displayFulfillmentStatus
        displayFinancialStatus
        customerUrl
        shippingAddress {
          address1
          address2
          city
          company
          country
          firstName
          formatted
          lastName
          latitude
          longitude
          phone
          province
          zip
          name
          countryCode
          provinceCode
          id
        }
        lineItems(first: 250) {
          pageInfo {
            hasNextPage
            hasPreviousPage
          }
          edges {
            cursor
            node {
              title
              variant {
                id
                title
                price
                weight
                image {
                  id
                  src
                  altText
                }
                selectedOptions {
                  name
                  value
                }
              }
              quantity
              customAttributes {
                key
                value
              }
            }
          }
        }
      }
      orderStatusUrl
      taxExempt
      taxesIncluded
      currencyCode
      totalTax
      subtotalPrice
      totalPrice
      completedAt
      createdAt
      updatedAt
    }
  }
}

Expected result:

Either:

  • The cart contains the cart with the custom attributes
  • or the endpoint / SDK return an error detailing what went wrong and how to correct it

This expectation stems from the Storefront API documentation, which is referred to by the SDK Api Reference, and the Javascript SDK Github Issue about custom line items attribute (#105)

Actual result:

  • The endpoint responds with 'internal error' {"errors":[{"message":"Internal error"}]}
  • The associated promise throws a TypeError TypeError: Cannot read property 'checkoutLineItemsAdd' of undefined

Other useful info:

  • Passing the lineItems or the customAttributes as simple objects or arrays makes no difference in the result.

Most helpful comment

Yeah, all values are strings. That should be more clearly documented. Thanks for the reminder!!

All 5 comments

Any feedback ?

This should actually work now. Sorry for the way late follow up. There was definitely a bug internally.

thanks for the update, tested now with alpha.8 and it's working correctly - the field is accepted by the API and the attribute shows up when viewing the order in the backoffice.

It seems it's not working when you pass an integer as value. Otherwise, It's working ;)

Yeah, all values are strings. That should be more clearly documented. Thanks for the reminder!!

Was this page helpful?
0 / 5 - 0 ratings