Accessing the Magento V2 API

Recently I’ve been working with Magento at work, and in particular with integrating with their API. Now, before I say anything more, I must say that I am always pleased when I see that these products do include some kind of API. The Magento one is a bit interesting, although there is some half-decent API documentation for the original API.

However they have then released a new version of the API, with very little documentation. So here are two calls – one to the v1 API and one to the v2 – which I hope will help illustrate the differences. The example I’ll give is the customer list functionality, including filtering the result set – because this was a total mystery when I started working with the v2 API!

    $options = array(
        "location" => 'http://magentoinstall.local/index.php/api/index/index/',
        "uri" => 'http://magentoinstall.local/api/'
        );
    $client = new SoapClient(NULL, $options);

    $session = $client->login('user', 'pass');
    $list = $client->call($session, 'customer.list', array(array("customer_id" => "42")));

To make the same call with API version 2, we need to address the method in a different way, using the structure in the underlying code as the method name that we call, and CamelCasing those, like this:

   $client = new SoapClient('http:/magentoinstall.local/api/v2_soap?wsdl=1');

   $session = $client->login('user', 'pass');

    $filter = new StdClass();
    $filter->filter = array(array("key" => "customer_id", "value" => "42"));
    $list = $client->customerCustomerList($session, $filter);

I haven’t used either of the APIs a lot but once I was able to call the same method via both available services, I wanted to share the approach here in the hope that this would help someone else trying to solve the same problem. It is certainly not obvious from the documentation how to interact with the v2 API and I had some real puzzles getting the filtering working. These snippets are from my working code so I hope they are helpful to someone!

Your Open Source Stories

In this post, I am asking for your help and input, although it might seem like a post about nothing in particular to begin with. Please keep reading!

Last month, I gave a talk at TEK-X entitled “Open Source Your Career”. Personally I think that a lot of the high fliers in this profession use their community activities as a boost to their professional development, and I know that this has been true for me too. So in my talk I told stories about situations I’d met in my professional life and how I’d either achieved or made new opportunities by building on skills and experience (and network) that I’ve come across in my community activities.

For example I said to my CTO, Ivo Jansch that I was giving this talk and he asked what it was about. I said that, in a nutshell, I didn’t think Ibuildings would have trusted any of their developers to host the Dutch PHP Conference unless they’d seen that person hosting events elsewhere – as a volunteer co-host of PHPNW, I gained some experience doing this sort of thing. His response really brought home how true it is that getting out there can reap rewards in ways we don’t expect – or in my case don’t even recognise. He simply said “one reason you have the job you have now is the fact that you did an oracle podcast for zend once which I heard when I received your CV”. It hadn’t occurred to me that activities like that would have helped when I was changing jobs.

What I Need From You

I’m giving this talk again, at FrOSCon in Germany in August. It was a huge amount of fun to deliver last time but I’d really like to pull in more stories from other people to include in my talk. So … have you ever got involved with something outside of your day job, only to realise later that it was a good career move? And would you let me tell your story?

Answers on a postcard, by email, or in the comments field below. Any and all input is very gratefully received :)

Text Commands for Skype

I use Skype on linux and the client is quite limited in terms of buttons etc, which doesn’t bother me at all since I don’t use a mouse unless I must (answering skype calls forms a lot of the “must”!). In group chats however, its annoying to have the alerts popping up all the time and I don’t have a menu option to stop them. To disable them I discovered I can just use:

/alertsoff

The / lets skype know its a command – much like IRC! There’s a full list I found on Skype’s support site, very handy :)

DPC Retrospective

I spent most of last week and the weekend in (rather rainy) Amsterdam for the Dutch PHP Conference. This is an event that is in its 4th year, although I was attending for only the 3rd time. Two years ago, I spoke at DPC – my first conference talk. This year, I hosted the event, which was quite a different experience. The event is organised by my employers, Ibuildings, and I was astonished to be asked late last year if I would like to be its host. Hosting an event is quite a different set of anxieties from speaking at one, and although there were a few minor emergencies along the way (lost speakers, really “interesting” CfP submissions, a moment where only half the venue would have wifi and some sessions failing to run to time), nothing worth getting stressed over!

The event was great (can I say that myself?) and with a world-class schedule, excellent speakers who all delivered on the day, sponsors who supported the venture and of course the attendees who showed up, took part, joined in with the uncon and generally made the whole thing into the fun it was – I could not have asked for more. As for the community friends who kept on sneaking up on me with a hug or a word of encouragement … I can’t ever thank any of you enough. On a very personal level it was fanstastic – I’ve enjoyed DPC for a few years and although the weather in Amsterdam was not so kind this year, the friends at the event (both the people I had already met and the friends I made while I was there) made it more than worth it.

Poor Man’s Caching

Describing something as a “poor man’s” version of the thing is to say its a bit of a cheap or short-cutting version. I thought I’d share some VERY poor man’s caching that I came up with the other day.

To set the scene – I’m hosting the Dutch PHP Conference this week and there’s a LOT of information to keep track of. Between tweets using the hashtag, people tweeting either my username or any of the conference twitter accounts, the schedule itself which will change as we’re having a no-prior-scheduling uncon, and the event and talk-related comments coming in via joind.in itself, its quite a bit of stuff to track. Add into the mix the fact that my iphone’s data package will be too expensive to use in NL and although I will have a phone with a data package it wont’ be mine and there’s no guarantee exactly what it will be. Oh and conference wireless, which last year wasn’t bad at DPC but you have to assume there’s a bottleneck.

So I figured that since I have a fast production server with lots of spare resource, it can do the hard work on processing the feeds, and just serve me a basic page with everything on and some internal hyperlinks to get around. So I wrote this monster, which runs a bunch of twitter searches and pulls in schedule and comments from joind.in, and that was good.

Except, it does take quite a long time to run (well, a few seconds, but that’s too long in my book) so I thought about caching each result set in memcache, and writing a cron job to repopulate those regularly, so every time I hit the script, the cache would be warm. Then I realised I was overcomplicating the matter, and simply wrote a cron job to run my php script and pipe the output to a static HTML file every minute! Whenever I hit the page, I’ll get the latest version. It doesn’t scale but it doesn’t need to, its only for me to use for a few days! Here’s the cron job:

* * * * * php -f /path/to/generate.php > /path/to/index.html

Job done! (the actual page I made is/ here if anyone is inquisitive)

Magic Methods on Think Vitamin

I’m happy to announce that my new post 9 Magic Methods for PHP is live on Think Vitamin this morning. I’ve written a series of posts about OOP for the site, with a few more to come, and these “underscore-underscore” methods make for some very neat tricks with PHP, which I’ve tried to show in the post. Hope you like it :)

The Unavoidable PHPWomen

I’m subscribed to a number of women-in-tech mailing lists because, well, I’m a woman in tech. Every few months or so a thread will come round about a technical conference with no female speakers. The issues around this are many, lengthy, and not something I want to write about here (or not today anyway!).

I was pleasantly surprised to note, then, that at the recent TEK-X conference, there was one slot where you could not AVOID seeing a female speaker. While Elizabeth Marie Smith delivered her slightly ranty “Cross Platform PHP”, Ligaya Turmelle was sharing her wisdom in her session “Replication with MySQL”, and in the remaining track there was a community roundtable, with my noble self on the panel! (OK so a panel is not a talk but hey, bear with me!)

I want to say thanks to TEK-X for being an amazing conference, to the community for being generally fabulous, and to the women in particular for being awesome beyond belief – this was a good day :)

DPC10 Has an Uncon

As the Host of the Dutch PHP Conference this year, you can imagine I’m squeaky-excited about the whole event. This story goes right back to last year though, when someone (Ivo? Cal? I don’t know who) conceived the idea of including an unconference in this year’s event. DPC is easily one of my favourite conferences and although I work for Ibuildings, I wasn’t directly involved with its organisation last year. In the autumn I wrote a proposal for running the unconference, and it was agreed that we should do it. Fast forward a bit and I became the host of the main conference, which is great news but left a slightly abandoned unconference behind – until the PHPBenelux user group stepped up and will be hosting the unconference alongside our main event (thanks guys!)

I’m so excited about the unconference, although I don’t know how our wider attendees will take to it as it hasn’t been done before locally. In order to include as many people as possible (and to keep the admin overhead to a minimum) we’ll schedule during the conference, on a first-come, first-served basis. This avoids the in-crowd getting voted into all the slots in advance; the uncon is for everyone to take part, not just for the people who are already well known! The uncon will also give us space to include extra on-demand sessions where people are wanting to see more about a particular topic, or see a demo of something a speaker mentions in a talk. Managing a changing schedule in real time will be interesting, we’re planning a two-pronged approach with twitter and Joind.in and I’m hoping this will allow attendees to hear about things they want to see in time to actually see them!

Its a new venture and I’m really interested to see how it turns out … if you’re coming to the conference then I hope you will give the uncon a look (in between the other awesome sessions on the schedule of course) and also take the time to share your thoughts on this and on the event as a whole. If you’re going to be there – leave a comment and let me know :)

A Three-Year Old Home

At one time I wrote about little else than the house on this blog, but these days its a pretty rare occurrence. However this weekend marks three years since we bought this place and moved in, and it does begin to feel like a home. In fact the house is a lot more than three years old, around 115 years in fact, its a old brick-built semi-detached house, red bricks and set over 4 floors as is fairly common in this part of the world (West Yorkshire).

In real terms, not a whole lot has happened in the house this year. I’m not exactly sure what we did with our time but Kevin changed job twice and I’ve been pretty busy so home improvements have definitely been getting neglected! One major thing we did, which I absolutely love, is we decorated my office (scroll down to see the “after” photos!). I have spent quite an insane amount of time at this desk over the last few months, between working, writing, preparing talks, and who knows what else, so having a place that suits me so well makes that so much easier! Control over my environment and only the cat to interrupt me most of the time is my idea of a good working environment! I’ve been working from home for almost 2 and a half years, and still enjoy this as much as ever, which is good news since although Ibuildings now has an office in Sheffield, that’s still a commute that is way too crazy to do regularly.

The office looks over the garden and the garden is one part of the house project which is really coming together in a way that I like. Looking at those initial photos of the space, and remembering that we just strimmed the 4-foot-high weeds down to a couple of inches for our housewarming party … it was a junk yard, really. And now, the flowerbeds I dug out last year have everything just a bit bigger and better this year, and mum has brought me lots of new plants. The climbers I planted along the edge of the nasty garage are getting the idea and growing themselves into beautiful flowery garage-hiding wallpaper (well and they’re growing across and onto everything else that gets close to them also, I had to rescue the barbecue from getting assimilated this week!) After laying the lawn about 18 months ago, and the patio last summer, we now have an apple tree growing in the lawn and some furniture for the patio … all in all its quite a suburban garden:

New Patio Furniture

For me the garden space always had the potential for this, and now I’ve got my own herb garden, annual flowering things (plus a few pretty weeds that I’m allowing to remain), and rhubarb, it really does feel like home!

For the coming year, we’re hoping to sort out our basement/damp problems, once and for all … if we can afford it!