ShopifyAPI gem. Update address

Solved
New Member
4 0 0

Hi.

How can I update customer's default address using ShopifyAPI gem?

I try this:

 

customer = ShopifyAPI::Customer.find(params[:shopifyCustomerId])
    
    if customer
      customer.addresses.each do |address|
        if address.default
          address.first_name = params[:firstName]
          address.save
       end
   end

and get - ActiveResource::ClientError: Failed. Response code = 406. Response message = Not Acceptable. 

0 Likes

Success.

Shopify Staff
Shopify Staff
223 28 28

Hey @Illia_Kuzma 

 

You will want to save the customer object versus the address. You can do something like this here: 

 

    if customer
      customer.addresses.each do |address|
        if address.default == true
          address.first_name = params[:firstName]
          customer.save
       end
   end

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes
New Member
4 0 0

Hi @vix ,

thanks for helping. It is really hard to find info on this.

 

I just tried what you suggested and get:

 

ActiveResource::BadRequest: Failed. Response code = 400. Response message = Bad Request.
0 Likes
Highlighted
Shopify Staff
Shopify Staff
223 28 28

Hey @Illia_Kuzma 

 

Can you paste your entire code? I can confirm that works while using the Shopify API Console. You may have luck testing there for troubleshooting: https://help.shopify.com/en/api/guides/using-the-api-console

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes
New Member
4 0 0

Hi.

I had a mistake in my code. I confirm that the solution works. Thanks!

0 Likes