Add line item properties via the API

James_Oliver
Visitor
2 0 0

We have an e-commerce site that sells customizable printed products. We have some design tools built on top of a Ruby on Rails app to help our customers upload their own artwork, select color, size, etc. We would like to swap out our custom order management code and use Shopify to power all of the regular e-commerce stuff so we can just focus on building out great design tools for our customers.

I started digging around the documentation and it looks like we should be able to pass a customized product to the cart with some line item properties (for image and dimensions) but I'm having trouble figuring out how to add line item properties via the API. It doesn't look like the REST API allows you to manage the cart so I would need to use the AJAX API, but I don't see how I can pass line item properties to that. I also don't think we could use that from the Rails app since it looks like it can only be used on a Shopify storefront.

The other option I see is just submitting a form or using a hyperlink to add a cart item, but I don't see a way to add line item properties through that either.

Am I missing something? Anyone know if it's possible to get the setup we want with the current capabilities of Shopify's API?

Replies 13 (13)

HunkyBill
Shopify Expert
4848 60 554

Sounds like lingo confusion:

Line Item Properties are great for client-side customization. Orders are generated with line items, each of which is a product that can have these line item properties. 

Your job is to build great client-side code that fully customizes a product using these Line Item Properties. Nothing more than HTML and Javascript there. You could loosely refer to using the Shopify Javascript API here since there is one for front-end developers to use.

On the back-end, you can hook up your App built from RoR to accept your orders, parse them, and "discover" the customization needed from the Line Item Properties present. This App uses the REST API or Shopify API.

So you can indeed do what you want. 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com

James_Oliver
Visitor
2 0 0

Thanks for your response, HunkyBill! Just to clarify, the client-side code that you are referring to customize the product would need to be in the Shopify store, correct? What I was hoping for is a way to preserve the existing tools we have for creating the customized products in the Rails app and then just pushing the properties I need to Shopify from the Rails app when someone wants to order something.

HunkyBill
Shopify Expert
4848 60 554

You can try. Use iframes. No reason why not. Note that you're tying a high-performance optimized CDN based shop to your server remotely. Essentially you're saying you don't want to refactor your tools but are content to keep them as is to re-use them thus ensuring your customers have a pokey old time as Internet latency kills your goose that laid the golden egg. 

oh, and even if you wrapped your toolset into an App Proxy, which you should do anyways, the speed of your server will still drag down performance. You gain many benefits with the Proxy though. 

So there are two choices for you.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
MadGeniusBlink
Shopify Partner
22 0 3

hey @HunkyBill,

 

I am trying to get an image to appear in Shopify Order tab under the Order placed item. I manage to get a link over to it like in the Image below.. but the issue now is that it opens "localhost:800/image" as the url. I do not have a database on my E-commerce.  is there a way to submit the whole image.. without having to store the image in our own database and then send the link via a custom attribute?

here is what I have up to now... When you press on Link it opens up "http://localhost:8000/b51ef9f1-f712-4fe1-b0af-76bdaf3af05c" but it doesn't exist.. is there a way to have Shopify store that image or URL passed in? Should I be passing some sort of other key and value? Screen Shot 2019-11-03 at 2.53.16 PM.png

 

My code:

  const addPrescriptionToCart = async (file) => {
    const image = URL.createObjectURL(file);

    return image;
  };

  // addProductToCart awaits the visitor action to click add to cart.
  const addProductToCart = async (variantId, file) => {
    try {
      setLoading(true);
      const image = URL.createObjectURL(file).replace('blob:', '');
      // the product Item and quantity
      const lineItems = [
        {
          variantId,
          quantity: 1,
          customAttributes: [{ key: 'Photo', value: `${image}` }],
        },
      ];
      // adds Item to checkout card which takes the Id from newCheckout
      const newCheckout = await client.checkout.addLineItems(
        checkout.id,
        lineItems,

      );
      setCheckout(newCheckout);
      setLoading(false);
    } catch (e) {
      setLoading(false);
      throw new Error('Error in AddProductToCart', e);
    }
  };
HunkyBill
Shopify Expert
4848 60 554

If you look at the Shopify documentation for Line Item Properties, you can easily see that uploading an image with a product is part of the form setup. So to get an image to not only upload but to show up with the order, you probably want to use Line Item Properties the way the documentation tells you to use them. So in a multipart form, there will be a file element to accept an image from a customer. Try using that. It works perfect.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
MadGeniusBlink
Shopify Partner
22 0 3

hey @HunkyBill,

 

Would you be kind to link to the documentation? 

 

I have been having a hard to finding it

 

Thank you!

HunkyBill
Shopify Expert
4848 60 554

https://help.shopify.com/en/themes/customization/products/features/get-customization-information-for...

 

Look for the file upload section... that is one document...  there could of course be others... but nonetheless...

 

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
MadGeniusBlink
Shopify Partner
22 0 3

@HunkyBill,

 

for some reason, it doesn't seem to be working... perhaps because I am not editing from shopify theme itself I am using the JS buy SDK API to build my store..

HunkyBill
Shopify Expert
4848 60 554

Oh hey ya! I had no idea. Well, you're so close, you'll figure out something...

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
MadGeniusBlink
Shopify Partner
22 0 3

hahaha,

 

Thank you! I really wish shopify had a way better documentation for the JS buy SDK 

HunkyBill
Shopify Expert
4848 60 554

In looking through the docs, I did not find any support for your endeavor. Uploading images is not trivial in the sense of establishing an asset in CDN for the product, as an order line item. You might want to forgo your attempts till Shopify actually does support it in that JS SDK.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
MadGeniusBlink
Shopify Partner
22 0 3

Hey @HunkyBill,

 

Thank for looking for me!

 

I am assuming the best way is to store the images in an S3 bucket? and have the order users click the link right?

HunkyBill
Shopify Expert
4848 60 554

That is how I do it. I use a pre-signed URL for S3 and then manage the asset that way. You would then be able to save the URL to the uploaded asset in your line items custom attributes as the value ...

 

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com