This is the third in my series of posts on the GlobalSight Web Services API. See below for the previous posts:
- Interacting with the GlobalSight Web Services API from C#
- GlobalSight Web Services API: Automate Translation Memory Upload
In this post, I’m going to cover how to actually create jobs in the GlobalSight system via the Web Services API. Creating jobs via the user interface works fine, but if you want to automate the process, this is fully supported via the API. This can be useful if for example you wanted to create a better experience for creating jobs, or a totally different interface – useful if you have people not experienced with GlobalSight who may want to submit content translation or review jobs.
I’ll assume you’re all setup to interact with the API from C# (see the first post above for a basic introduction if you are not).
There are a couple of API calls relevant to job creation:
- getFileProfileInfo – This returns the list of File Profiles currently available in the system. The response is XML format, listing all File Profiles available in the system, each having an ID, Name and Description. The File Profile is a required parmeter to both the uploadFile and createJob functions.
- uploadFile – This facilitates upload of a single file to GlobalSight (note it does not actually create a job). This needs to be called once per file.
- getUniqueJobName – This function essentially takes a job name, and adds a nine digit unique ID to the name. Each job in GlobalSight must have a unique name. If you already have some unique identifier in your job name, you will not need to call this function, but otherwise it is useful for ensuring that there aren’t any clashes between job names.
- createJob – This is the function that actually creates the job in GlobalSight.
Let’s look at some simple code for job creation using the above listed functions.
GS_API.AmbassadorService client = new GS_API.AmbassadorService(); string jobName = "Demo Job (Ignore)"; string textFilePath = @"C:\Users\Jimmy\Desktop\strings.txt"; string fileProfileID = "37"; byte[] fileContents = System.IO.File.ReadAllBytes(textFilePath); // Authenticate string auth = client.login("TestUser1", "password"); // Here you would get the file profiles, and find the apt. one for this job // I'll leave this to the reader as an exercise, I've assigned a variable above // Next, lets ensure uniqueness of our job name string uniqueJobName = client.getUniqueJobName(auth, jobName); // Upload the file client.uploadFile(auth, uniqueJobName, "/files/strings.txt", fileProfileID, fileContents); // Create the Job - ensure to use the same job name as your call the uploadFile client.createJob(auth, uniqueJobName, "Demo Job", "/files/strings.txt", fileProfileID, "");
A couple of points to note:
- Each file you upload needs to be converted to a byte array. C# provides the handy function I’ve used above for this purpose.
- The third parameter to uploadFile, (in this case ‘files/strings.txt‘), is the location to upload the file on the GlobalSight server. There are a few folders created by default for any job, the language code, ‘webservice‘ which indicates the files were uploaded via the API, and a folder named after the job ID. The parameter above is the directory structure inside the job ID folder, this is whatever you want it to be. This is useful, as the files are exported in that same structure post translation, so you can for example retain the directory structure of a translation kit if you so wish. Here’s an example of how the file we uploaded above is stored on the GlobalSight server:
- The job name you pass to createJob, must be identical to the one you passed to uploadFile. This is how GlobalSight knows which files relate to this job.
- The final parameter in createJob is the target languages. Leave this empty (as I have above) and GlobalSight will assign all the languages contained in the Localization Profile that is associated with the File Profile you have specified.
That’s it, after you have run the above code, your job is now created in GlobalSight.
This was a very basic introduction to job creation in GlobalSight, showing how a single file can be submitted via the web services API.
I haven’t covered items such as error handling, or even creating jobs that have multiple files, not just one as in my simple example above – I will perhaps cover this in a future post.