Created
July 22, 2016 14:03
-
-
Save dominiceden/791228be12dfd3487d93a9ceb7ffdf4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
redirects = [ # FIELD1 is the current URL; FIELD2 is the URL you want the user to be redirected to. | |
{ | |
"FIELD1": "http:\/\/www.myshop.com\/products\/urban-camo-tracksuit", | |
"FIELD2": "http:\/\/www.myshop.com\/collections\/tracksuit\/products\/urban-camo-tracksuit-bottoms" | |
}, | |
{ | |
"FIELD1": "http:\/\/www.myshop.com\/products\/urban-camo-vest", | |
"FIELD2": "http:\/\/www.myshop.com\/collections\/mens-vests\/products\/kutula-urban-camo-vest" | |
} | |
] | |
redirects.each do |redirect| | |
redirect_item = { # generate an object in the correct format for Shopify | |
"redirect": { | |
:path => redirect[:FIELD1], | |
:target => redirect[:FIELD2] | |
} | |
} | |
@result = HTTParty.post('https://josie-anna.myshopify.com/admin/redirects.json', | |
:body => redirect_item.to_json, | |
:headers => { 'X-Shopify-Access-Token' => 'YOUR_PRIVATE_APP_PASSWORD_GOES_HERE', 'Content-Type' => 'application/json' } | |
) | |
puts @result # log the result to the console | |
sleep 5 # wait 5 seconds before submitting the next redirect item | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bulk upload redirect rules via the Shopify API. All you need to do is create a private app, and then create a list of redirects you want to send to Shopify. This is a Ruby script, so you will need Ruby installed to run the script.