Skip to content

Instantly share code, notes, and snippets.

@dominiceden
Created July 22, 2016 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominiceden/791228be12dfd3487d93a9ceb7ffdf4d to your computer and use it in GitHub Desktop.
Save dominiceden/791228be12dfd3487d93a9ceb7ffdf4d to your computer and use it in GitHub Desktop.
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
@dominiceden
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment