NY Email Marketing

A lot has been going on at ITCL and this post I would like to make a little different. It will still be industry focused (because we live and breathe technology and innovation) but it will be more personal. In the time when most of it can be done by an AI assistant it feels right to take a moment and jot a few words myself. 

A couple years back we had the honor to be represented at Forbes Under 30 conference as well as at NY Tech Week. More detailed posts on each to follow. This year we have big plans for our small company. In addition to our consulting and software development services (web, mobile) we are expanding our email marketing services, which will be consumed by digital marketing services. We have been working hard on establishing this line of business last year and are thrilled to finally “get it off the ground”.  Please welcome NY Email Marketing, your go-to digital agency for all things email marketing and what I like to call a digital marketing hub. It also means that we are hiring to expand our strong team of Salesforce Marketing Cloud certified professionals and experts in other digital marketing platforms, such as IBM Marketing Cloud, Adobe Marketing Cloud, Oracle Marketing Cloud and others. Because Digital Marketing is such a buzz word and because there is a plethora of marketing cloud platforms out there and because it is very easy to get confused which platform would work best for your business and because we would like to share our expertise with those in need, we are preparing a very cool case study on the subject. We will review top 10 digital marketing platforms and rate their features to give you a good grip on the current offerings and to empower you to make informed strategic decisions on which digital marketing solution would be the best option for your business.

Excited to congratulate the team on the launch of a new email marketing hub!

nyemailmarketing.com

Digital marketing solutions provider.

Visit NYEM on Facebook, like and subscribe!

nyem-launch

Connect to WooCommerce Rest API using Javascript

Do you  know, how to get data from WooCommerce via Rest API from the client, using JavaScript? Surprisingly, tutorials on this delicate subject are seldom found on page one of search results. Moreover, as of the moment of this writing WooCommerce documentation is also missing this information.

Warning: It is never a good idea to expose API authentication credentials.

Nevertheless, in rare cases when you do end up using this frivolous setup in production, make sure that your API key is for read only.

Below are a couple working code snippets – one using jQuery and one using vanilla async/await. Both get the job done:

const wooClientKey = 'ck_00000000000000000000000000';
const wooClientSecret = 'cs_00000000000000000000000000';
const wooUrl = 'https://yoursite.com/wp-json/wc/v3/products';

function basicAuth(key, secret) {
    let hash = btoa(key + ':' + secret);
    return "Basic " + hash;
}

let auth = basicAuth(wooClientKey, wooClientSecret);

function getData(url) {
    jQuery.ajax({
        url: url,
        method: 'GET',
        beforeSend: function (req) {
            req.setRequestHeader('Authorization', auth);
        }
    })
        .done(function (data) {
            console.log(data);
            return data;
        });
}

getData(wooUrl);

While the code itself is fairly self explanatory, here’s a quick step by step breakdown:

Const

The “consts” are merely script settings, which one can generate from within their WooCommerce  API section (WP Admin area).

basicAuth

This is a helper function, introduced for clarity.

The “Basic” HTTP authentication scheme transmits access credentials – username and password, encoded using base64 (defined in RFC 7617).

Thus, all basicAuth does is uses btoa() method to create a base64 encoded ASCII string  (<key>: <secret>) and return the resulting hash along with the “Basic” identifier.

Vanilla Javascript

const wooClientKey = 'ck_00000000000000000000000000';
const wooClientSecret = 'cs_00000000000000000000000000';
const wooUrl = 'https://yoursite.com/wp-json/wc/v3/products';

function basicAuth(key, secret) {
    let hash = btoa(key + ':' + secret);
    return "Basic " + hash;
}

let auth = basicAuth(wooClientKey, wooClientSecret);

async function getProducts() {
    try {
        const response = await fetch(wooUrl + 'products', {
            headers: {"Authorization": basicAuth(wooClientKey, wooClientSecret)}
        });
        return await response.json();
    }
    catch (error) {
        // catches errors both in fetch and response.json
        console.log(error);
    }
}

Deploy Using Git Pull

Automatically pull files from bitbucket git repo upon commit/merge to master.

Whenever there’s a need to deploy by means of an automated git pull, without the whole container,  docker registry, aws overhead, the code below works best.

exec(“git pull https://username:password@bitbucket.org/company/repo.git master”);

Here are the step-by step instructions

  1. Create a user on bitbucket with access to the desired repository.
  2. SSH to your remote server, where the code should be pulled to.
  3. Clone the repository into the desired directory:  git clone https://username:password@bitbucket.org/company/repo.git
  4. Create a script (python, php or shell) – doesn’t matter. The “exec” command above is for php.  Script should be accessible from the web.
  5. Add a webhook to the repository on bitbucket, where the triggered url is the url to the php script.

All done! Now every time there’s a change to master, the code will be pulled by the remote server.

Why use username and password and not SSH keys?

SSH keys won’t work for a number of reasons, but anyone is free to give it a shot and let us know how it went. Note, the script is executed by the webserver, which runs under it’s own user that naturally has no access to the private key. Trying to make the keys available for that user is  not worth the headache.

Bitbucket’s own documentation has an FTP example, why not use that?

The whole FTP business is not secure and not that widely used. If one can avoid spinning up an FTP server, one probably should.

Below are a few search queries suggested by google, left here to help those seeking the solution to their problem 🙂

How to sync with git repository

Bitbucket pull via ftp sftp

Deploy using ftp sftp

Automate git pull

Simplest continuous integration

muCommander for Mac OS X

Mac OS has long lacked a robust file manager and unfortunately continues to do so, sigh. Nonetheless there exists muCommander, which fills the void. A cross-platform file manager written in Java is a great tool. Free download of muCommander v. 0.9.1 (year 2016) is available from our site.

Note: You need to have java installed in order for muCommander to work. In case you don’t have it already, we recommend using homebrew or the official java installer for Mac OS. Tips and instructions are available via Google search or this link.

Unfortunately the official muCommander site hasn’t been updated for years and while anyone can download and compile the app from source files, available on github, it may not be as easy and straightforward even for tech savy users. Since our team uses muCommander for daily operations and a member of our team occasionally contributes to the code he decided to compile a stable and working solution for all of us to use. We decided to share it with everybody else. Enjoy!

Отладка. Будет убрана потом