class Shopify::Customer

Overview

https://shopify.dev/api/admin-rest/2022-01/resources/customer

Extended Modules

Defined in:

shopify/resources/customer.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Shopify::Resource

store : Store store, store=(store : Store) store=

Constructor methods inherited from class Shopify::Resource

new(pull : JSON::PullParser) new

Class methods inherited from class Shopify::Resource

headers headers

Constructor Detail

def self.new(pull : JSON::PullParser) #

[View source]

Class Method Detail

def self.all(domain : String, depth : Int32 = 20, headers : HTTP::Headers = headers) : Array(Shopify::Customer) #

Used to return an array of customers. Uses fibers to fetch pages concurrently.

NOTE It is recommended to use .all(domain, next_page_uri, headers, &block) directly instead of this method as it is more performant.

Generally, this is used with .with(store):

Shopify::Customer.with(store).all #=> Array(Shopify::Customer)

But it can be used stand-alone, too:

Shopify::Customer.all(domain, headers: headers) #=> Array(Shopify::Customer)

This just runs the &block version of .all(domain, next_page_uri, headers, &block) to create an array


[View source]
def self.all(domain : String, next_page_uri : String? = nil, depth : Int32 = 20, headers : HTTP::Headers = headers, &block : self -> ) #

Used to iterate over all customers. Uses fibers to fetch pages concurrently.

Generally, this is used with .with(store):

Shopify::Customer.with(store).all do |customer|
  # do something with customer
end

But it can be used stand-alone, too:

Shopify::Customer.all(domain, headers: headers) do |customer|
  # do something with customer
end

Under the covers, this just runs:

GET
/admin/api/2022-01/customers.json

and follows every next Response Headers "Link" until there are no more.

Uses NextPreviousParser to parse the response headers.


[View source]
def self.count(domain : String, headers : HTTP::Headers = headers) : Int64 #

Used to get a count of all customers.

Generally, this is used with .with(store):

Shopify::Customer.with(store).count #=> Int64

But it can be used stand-alone, too:

Shopify::Customer.count(domain, headers: headers) #=> Int64

Under the covers, this just runs:

GET
/admin/api/2022-01/customers/count.json

[View source]
def self.create(body : String, domain : String, headers : HTTP::Headers = headers) : Shopify::Customer #

Used to create one customer.

Generally, this is used with .with(store):

Shopify::Customer.with(store).create(body) #=> Shopify::Customer

But it can be used stand-alone, too:

Shopify::Customer.create(body, domain, headers: headers) #=> Shopify::Customer

A sample body from shopify docs:

{"customer":{"first_name":"Steve","last_name":"Lastnameson","email":"steve.lastnameson@example.com","phone":"+15142546011","verified_email":true,"addresses":[{"address1":"123 Oak St","city":"Ottawa","province":"ON","phone":"555-1212","zip":"123 ABC","last_name":"Lastnameson","first_name":"Mother","country":"CA"}]}}

Under the covers, this just runs:

POST
/admin/api/2022-01/customers.json

[View source]
def self.find(id : Int64, domain : String, headers : HTTP::Headers = headers) : Shopify::Customer #

Used to fetch one customer.

Generally, this is used with .with(store):

Shopify::Customer.with(store).find(id) #=> Shopify::Customer

But it can be used stand-alone, too:

Shopify::Customer.find(id, domain, headers: headers) #=> Shopify::Customer

Under the covers, this just runs:

GET
/admin/api/2022-01/customers/{id}.json

[View source]
def self.search(query : String, domain : String, headers : HTTP::Headers = headers) #

Under the covers, this just runs:

GET
/admin/api/2022-01/customers/search.json?query=

[View source]
def self.uri(domain : String, path : String = "") : URI #

[View source]
def self.with(store : Store) #

[View source]

Instance Method Detail

def accepts_marketing : Bool #

[View source]
def accepts_marketing=(accepts_marketing : Bool) #

[View source]
def accepts_marketing_updated_at : Time #

[View source]
def accepts_marketing_updated_at=(accepts_marketing_updated_at : Time) #

[View source]
def addresses : Array(Shopify::Address) #

[View source]
def addresses=(addresses : Array(Shopify::Address)) #

[View source]
def admin_graphql_api_id : String #

[View source]
def admin_graphql_api_id=(admin_graphql_api_id : String) #

[View source]
def create_account_activation_url : URI #

Under the covers, this just runs:

POST
/admin/api/2022-01/customers/{id}/account_activation_url.json

[View source]
def created_at : Time #

[View source]
def created_at=(created_at : Time) #

[View source]
def currency : String #

[View source]
def currency=(currency : String) #

[View source]
def default_address : Shopify::Address #

[View source]
def default_address=(default_address : Shopify::Address) #

[View source]
def delete #

Used to delete one customer.

Under the covers, this just runs:

DELETE
/admin/api/2022-01/customers/{id}.json

[View source]
def email : String #

[View source]
def email=(email : String) #

[View source]
def first_name : String #

[View source]
def first_name=(first_name : String) #

[View source]
def id : Int64 #

[View source]
def id=(id : Int64) #

[View source]
def last_name : String #

[View source]
def last_name=(last_name : String) #

[View source]
def last_order_id : Int64? #

[View source]
def last_order_id=(last_order_id : Int64?) #

[View source]
def last_order_name : String? #

[View source]
def last_order_name=(last_order_name : String?) #

[View source]
def marketing_opt_in_level : String? #

[View source]
def marketing_opt_in_level=(marketing_opt_in_level : String?) #

[View source]
def multipass_identifier : String? #

[View source]
def multipass_identifier=(multipass_identifier : String?) #

[View source]
def note : String? #

[View source]
def note=(note : String?) #

[View source]
def orders : Array(Shopify::Order) #

Under the covers, this just runs:

GET
/admin/api/2022-01/customers/{id}/orders.json

[View source]
def orders_count : Int32 #

[View source]
def orders_count=(orders_count : Int32) #

[View source]
def phone : String? #

[View source]
def phone=(phone : String?) #

[View source]
def send_invite : Shopify::CustomerInvite #

Under the covers, this just runs:

POST
/admin/api/2022-01/customers/{id}/send_invite.json

[View source]
def sms_marketing_consent : JSON::Any? #

[View source]
def sms_marketing_consent=(sms_marketing_consent : JSON::Any?) #

[View source]
def state : String #

[View source]
def state=(state : String) #

[View source]
def tags : String #

[View source]
def tags=(tags : String) #

[View source]
def tax_exempt : Bool #

[View source]
def tax_exempt=(tax_exempt : Bool) #

[View source]
def tax_exemptions : Array(JSON::Any) #

[View source]
def tax_exemptions=(tax_exemptions : Array(JSON::Any)) #

[View source]
def total_spent : String #

[View source]
def total_spent=(total_spent : String) #

[View source]
def update(body : String) : self #

Sample Body from Shopify Docs:

{"id":207119551,"email":"changed@example.com","note":"Customer is great"}}

Under the covers, this just runs:

PUT
/admin/api/2022-01/customers/{id}.json

[View source]
def updated_at : Time #

[View source]
def updated_at=(updated_at : Time) #

[View source]
def verified_email : Bool #

[View source]
def verified_email=(verified_email : Bool) #

[View source]