Join us today @ 1pm EDT for an AMA with 2H Media: Holiday Marketing for Your Shopify Store and have your marketing questions answered by marketing experts 2H Media | Plus watch the 2H Media AMA Livestream on Twitch!

Add data to user

Solved

Add data to user

fbd
Shopify Partner
6 0 1

Hello.

I want to add custom data to each user who buy a product.

Like if someone buy from my store, i want to add data on his account like a SQL database.

Can i do it with shopify liquid or anything else ?

 

Also, is there a way to have a database (not attached to customer) in a shopify website ?

 

Thanks!

Accepted Solution (1)
chris-sellboost
Shopify Partner
22 3 12

This is an accepted solution.

@fbd that is perfect! You are posting inside the Shopify APIs and SDKs, thats is not a liquid based solution, is a app based solution, you can check the guide to build it

Lets me explain, in Shopify you cat get subscribed to some event is dispatched in the Shopify backend with Webhooks (check the order/paid event topic for your case) in that moment that receipt a notification, you can check the line_orders of the order details with data that are in the same notification, with your rules to determine if you need to update the customer data with the Admin API.

Other option that i commented, for do the same, is collect all orders data periodically (with a CRON) to check the line_items to determine if you need to update the customer data.

- How to register a webhook: https://shopify.dev/docs/api/admin-rest/2022-04/resources/webhook
- How to update a customer: https://shopify.dev/docs/api/admin-rest/2023-04/resources/customer
- How to get orders list: https://shopify.dev/docs/api/admin-rest/2022-04/resources/order



Note: every buyer is a customer in Shopify, if purchase as guest, is a non-registered customer identified by the email at moment of the purchase, and you can add notes, tags, metafields..etc


View solution in original post

Replies 7 (7)

chris-sellboost
Shopify Partner
22 3 12

Hi @fbd

I like use tags for that, you can use the webhook yo subscribe to order topic and tag the user, other alternative is a CRON job that process our orders and tagging the users, in any case, you need write some code or external apps for that. 

fbd
Shopify Partner
6 0 1

Thanks to responding me!

I forgot to say that I am a developer, but I am new in the shopify liquid ecosystem.

I am trying to know how it works and it is not a problem to add some code.

 

You spoke about tags, webhook and cron, but I don't understand the link with how I could add data to my user, and non-user ?

chris-sellboost
Shopify Partner
22 3 12

This is an accepted solution.

@fbd that is perfect! You are posting inside the Shopify APIs and SDKs, thats is not a liquid based solution, is a app based solution, you can check the guide to build it

Lets me explain, in Shopify you cat get subscribed to some event is dispatched in the Shopify backend with Webhooks (check the order/paid event topic for your case) in that moment that receipt a notification, you can check the line_orders of the order details with data that are in the same notification, with your rules to determine if you need to update the customer data with the Admin API.

Other option that i commented, for do the same, is collect all orders data periodically (with a CRON) to check the line_items to determine if you need to update the customer data.

- How to register a webhook: https://shopify.dev/docs/api/admin-rest/2022-04/resources/webhook
- How to update a customer: https://shopify.dev/docs/api/admin-rest/2023-04/resources/customer
- How to get orders list: https://shopify.dev/docs/api/admin-rest/2022-04/resources/order



Note: every buyer is a customer in Shopify, if purchase as guest, is a non-registered customer identified by the email at moment of the purchase, and you can add notes, tags, metafields..etc


fbd
Shopify Partner
6 0 1

 

Ok. In my store i want to do something like this: when customer buys 5 articles, he gets +50 points. If he buys 10 articles, he gets +100 points again.

 

And if I understand, you advise me to use Webhook for "knowing when user has bought", and then change user's custom metafield which is "points" with this https://shopify.dev/docs/api/admin-rest/2023-04/resources/customer

 

Just to make sure of an expert opinion, could this system work?

fbd
Shopify Partner
6 0 1

And also, to use webhook, do i need to create an application ?

chris-sellboost
Shopify Partner
22 3 12

Yes, for webhooks you need a apikey, this only can do with an app (public or private)

fbd
Shopify Partner
6 0 1

Last question to really understand lol: and with the app, we can also update a customer (with the link you gave me)