Posts tagged with 'graffiticlient'

GraffitiClient API: calling GraffitiCMS from a program

I have a whole set of posts on my static website that I'd like to transfer over to my Graffiti CMS site, leaving behind a redirect link. Since I was using CityDesk from Fog Creek to blog before, there's no migration tool available. Hey, no problem, I'm a developer at heart so it's just a simple case of opening up a a couple of databases, writing a conversion routine, and Bob's your uncle.

Even better, Graffiti exposes a web service that I can call. I only need to open ONE database, and the conversion method calls a method on the web service to add these converted posts! Brilliant. Sometimes I astound myself with my perspicacity.

But, boy finding out information about the web service is ruddy difficult and I ran into some issues when I did so. This post is a quick explanation of what you should do in order to use the Graffiti web service.

First of all, when you unzipped the Graffiti product you would have created three folders: Data. Utility, and Web. The latter you will have copied to your web site. In Utility there's a dll called GraffitiClient.dll which is the entryway to the Graffiti web service. (Yeah, I'm being pedantic here about where it is because at one point I was looking in web/_utility on the web site for this mysterious dll. Grasshopper, do not follow my path.)

In Visual Studio, create a new Console application. Add a reference to GraffitiClient.dll. Type the basic code to list the categories (the code shown is for this blog). By the way, do not miss the api folder name off the end of the URL.

using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GraffitiClient.API;

namespace GraffitiApiTest {
  class Program {
    static void Main() {
      Console.WriteLine("List of categories");

      GraffitiService gs = new GraffitiService("username", "password", "http://blog.boyet.com/api/");

      try {
        PagedList<Category> plc = gs.Categories.Get(new NameValueCollection());

        foreach (Category c in plc)
          Console.WriteLine(c.Name);
      }

      catch (GraffitiServiceException gse) {
        Console.WriteLine(gse.Message);
        Console.WriteLine(gse.StatusCode);
      }

      Console.WriteLine("..done");
      Console.ReadLine();
    }
  }
}

(Obviously, those aren't valid user credentials for my website.) I decided to create a "special" user in Graffiti to handle access through the web service rather than use my main one. So I created a user called MigrationUser, a contributor, changed the hard-coded user and password in the code above, compiled and ran the application.

Boom.

Thread was being aborted
500

What the... ? So I dutifully looked up error 500 and essentially all I could find was "The server ran into a problem. Tough. Talk to your system admin." Couldn't find anything relevant about "Thread was being aborted", although there was some muttering about timeouts. I went to the Graffiti logs: nothing there at all. Hmm.

I pulled out Reflector and started looking through the code paths. This is made slightly more tricky since there are two of course: one on the client and one on the server. I was guessing that it was the server one that was the most probable, but the only error 500 I found was in a bit of code for deleting a category. Didn't sound right. I did notice some code that talked about permissions; hmm, I wonder.

So I made MigrationUser an admin.

And the code worked.

There you have it: the 5 minute intro to GraffitClient.dll. Oh and make sure the user whose credentials you are using is an admin.

Now to write a migration tool.

Album cover for Greatest Hits Now playing:
Ace of Base - All That She Wants
(from Greatest Hits)



Extras

Search

About Me

I'm Julian M Bucknall, the M because it's my middle initial and because I and the other Julian Bucknall (the movie guy) would like to differentiate ourselves.

I'm a programmer by trade, an actor by ambition, and an algorithms guy by osmosis. I write articles for PCPlus in my spare time, not that there's much of that.

Julian M Bucknall Apart from that, an ex-pat Brit, atheist, microbrew enthusiast, Pet Shop Boys fanboy, slide rule and HP calculator collector, amateur photographer, Altoids muncher.

DevExpress

I'm Chief Technology Officer at Developer Express, a software company that writes some great controls and tools for .NET and Delphi. I'm responsible for the technology oversight and vision of the company.

Validation

Validate markup as HTML5 (beta)     Validate CSS

Bottom swirl

Archives

May 2012 (4)
SMTWTFS
« Apr  
12345
6789101112
13141516171819
20212223242526
2728293031

Like this Archive Calendar widget? Download it here.

Social networking

The OUT Campaign

The OUT Campaign

My Tweets

  • Honest Movie Trailer of Phantom Menace http://t.co/sif8y4Ns and then Battleship, er, Transformers http://t.co/sif8y4Ns
  • Damn, Donna Summer and Chuck Brown both gone in the last 24 hours. Different types of music, sure, but enjoyed them both. :(
  • Just saw a company page showing a list of tweets with "Join the conversation" linked to their Twitter a/c. The tweets are 6 months old #fail
Bottom swirl