Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A super simple CLI for making REST requests to Shopify. Modify with whatever methods you want!
// README: https://gist.github.com/newswim/a99b09a13e80c262d61915f0f28a51b1
// For instructions on `shopify-api-node`
// see: https://github.com/christophergregory/shopify-node-api
#!/usr/bin/env node
"use strict"
const clear = require('clear')
const inquirer = require('inquirer')
const jsonfile = require('jsonfile')
const s = jsonfile.readFileSync('config/secrets.json')
const Shopify = require('shopify-api-node')
const shopify = new Shopify({
shopName: s.shopName,
apiKey: s.api_key,
password: s.password,
autoLimit: s.autoLimit, // optional, simply remove to disable
timeout: 7000 // optional, defaults to 60000ms
})
let deleteCustomer = (customerId) => shopify.customer.delete(customerId)
.then(data => {
console.log(data)
})
.catch(err => {
console.log(err.message)
})
let deleteOrder = (orderId) => shopify.order.delete(orderId)
.then(data => {
console.log(data)
})
.catch(err => {
console.log(err.message)
})
let questions = ([
{
type: 'list',
name: 'which',
message: 'What type of record do you wish to delete?',
choices: [
'Customer',
'Order'
]
},
{
type: 'input',
name: 'customerRec',
message: `What's the ID of the Customer?`,
when: function (answers) {
return answers.which == 'Customer'
},
validate: function (val) {
if (val.length < 9) {
return 'Please enter a valid ID'
}
else {
return true
}
}
},
{
type: 'input',
name: 'orderRec',
message: `What's the ID of the Order?`,
when: function (answers) {
return answers.which == "Order"
},
validate: function (val) {
if (val.length < 9) {
return 'Please enter a valid ID'
}
else {
return true
}
}
}
])
clear()
inquirer.prompt(questions).then(function (answers) {
if (answers.which == 'Customer') {
deleteCustomer(answers.customerRec)
}
else if (answers.which == 'Order') {
deleteOrder(answers.orderRec)
}
console.log(JSON.stringify(answers, null, ' '))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.