Tutorial: Using the MTurk API with the AWS SDK for Java

In previous blog posts,we've shown how to use the 万博体育网址Amazon Mechanical Turk (MTurk) Application Programming Interface (API) using the AWS Software Development Kits (SDKs) forNode.js,,Javascript with React,,Python,andRuby.We'll continue to post tutorials to help Requesters get started quickly with MTurk's API.

In today's tutorial,we will step through how to setup and make your first API calls again the MTurk API for Java.We will be using the popularEclipse Integrated Development Environment (IDE)and theAWS Toolkit for Eclipse.Let's get started.


To begin,we'll first download and install Eclipse here:


For this tutorial,we'll be using Eclipse Oxygen 3.A (April 2018).Once installed,we'll then install the AWS Toolkit for Eclipse by following these steps:

Now,let's go to theMenubar and selectNewthenProject.A dialog box should appear that will look similar to this:

SelectAWS Java Project,and clickNext >.Now we will be asked to provide a name for our new project (we'll name oursmturk-appfor this tutorial).It should look like this:

If you want to use different credentials than those found in your ~/.aws/credentials file,select them under theAWS Credentialsheader,在Select profile:dropdown.For this tutorial,we will use thedefaultcredentials as shown above.

Next clickFinishto proceed.Once complete,your screen should look similar to this:

Creating our first program

Often,the best place to start when configuring a new language and a new API is to write a simple program to ensure that we're correctly compiling,calling the API,and receiving the expected result.MTurk offers a simple,read-only API calledGetAccountBalancethat is useful to verify that our application is correctly calling the MTurk API.Our first program will be to call that API.

Let's use sample code that's already available in the MTurk Code Samples repository on GitHub here:

We'll be working with the sample app calledGetAccountBalanceSamplethat can be foundhere.First,let's create our GetAccountBalanceSample class by clicking the right mouse button on thesrc/main/javaand selectingNew > Class.It should look like this:

From there,we will delete all characters in thePackage:field,enter the class nameGetAccountBalanceSampleand clickFinishto proceed.It should look like this:

我们的Eclipse IDE屏幕现在应该如下所示:

Next,we will open the sample code from GitHub for GetAccountBalanceSample found here:


and paste it into our editor,completely replacing any existing code in the GetAccountBalanceSample.java file.Once you've pasted it in,your Eclipse IDE screen should look like this:


Now we'll actually run our first program.To do this,click the right mouse button anywhere in the GetAccountBalanceSample.java code editor window.A menu will appear and you'll selectRun AsthenJava Application.It should look like this:

You should see output that looks similar to the following:

SANDBOX - Your account balance is 10000.00
PRODUCTION - Your account balance is 384.72

And your screen should look similar to this:

Congratulations!You've just executed your first Java program calling the MTurk API with the AWS SDK.Nice work.

Wrapping up

Today,we've just scratched the surface of what's possible with the AWS SDK for Java and the MTurk Requester API.In future tutorials,we'll build on this to show readers how to do even more.In the meantime,you can learn more about the MTurk API by accessing the MTurk API documentationhere.You can also check out more Java sample code for the AWS SDK and MTurk APIhere.

We hope you enjoyed today's tutorial.If you have any questions,please post a question to ourMTurk论坛.To become a Requester,,sign up here.Want to contribute as a Worker customer??Get started here.

The author has chosen not to show responses on this story.You can still respond by clicking the response bubble.