Skip to Content
Technical Articles
Author's profile photo Shobhit Garg

Sprint RESTs on Android!

This blog  demonstrates how to create a bread and butter(no fancy UI!) android application to create activities in 12Sprint. The blog  would also discuss how to call RESTful services from an Android application.
Android comes with Apache Http Client api and we would use this api to make the rest service calls.
To create an activity  URL : (POST) /v1/activities <[https://beta.12sprints.com/api/Post_an_activity.html | https://beta.12sprints.com/api/Post_an_activity.html]> is used 0.1.
To get all the activities created by the user  : (GET) /v1/activities <[https://beta.12sprints.com/api/Get_all_activities.html | https://beta.12sprints.com/api/Get_all_activities.html]> is used.

Dealing with authentication specific stuff:

Since 12Sprints requires the user to be authenticated before he/she can play around with the activities we need to set the credentials for our user:

I managed to do this in the following manner with the android api:

DefaultHttpClient httpClient=new DefaultHttpClient();

UsernamePasswordCredentials cred=new UsernamePasswordCredentials(“user@domain.com“, “password”); //supply your 12Sprints id here

httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), cred);

Next lets see how to fire a post request to create an activity: String activityNameTxt=activityName.getText().toString();   //get the name of the activity that the user entered

+String newActivity = ”

</p><p>+ +“<activity name=\””activityNameTxt“\”></activity>”;

byte[] newActivityByteArray = newActivity.getBytes(Encoding.UTF_8.toString());

+ByteArrayEntity reqEntity = new ByteArrayEntity(newActivityByteArray);  +

reqEntity.setContentType(“application/xml”);

req.setEntity(reqEntity);

Finally execute the request:

HttpResponse res = httpClient.execute(req);

The response code can be fetched using:

int code = res.getStatusLine().getStatusCode();

and the response content using

res.getEntity().getContent();

This is how the final app for creating activity looked on the Android emulator:

The first screen of the application.

Enter activity name and click add.

!https://weblogs.sdn.sap.com/weblogs/images/251747517/Screen3-created.JPG|height=484|alt=|width=685|src=https://weblogs.sdn.sap.com/weblogs/images/251747517/Screen3-created.JPG|border=0!</body>

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jim Spath
      Jim Spath
      Hi Shobhit!

        In your blog, you say you want to "create activities in 12Sprint." For those of us unfamiliar with this site, what is it, what does an "activity" mean, and why would I want to create one?  Is it simply a calendar appointment?  Is it a project milestone?  Just wondering...

      Jim

      Author's profile photo Shobhit Garg
      Shobhit Garg
      Blog Post Author
      Hi Jim,
      In 12Sprints an activity is anything the user wants to discuss.(Something like a header item)
      The user could further add items to the activity like a descision item.Eg The team is planning an outbound. To discuss and decide they could create an activity named 'Team outbound' and add a decision item to it 'where should we go?'

      Shobhit

      Author's profile photo Former Member
      Former Member
      According to 12Sprints API pages is now oAuth required. (https://beta.12sprints.com/api/Authentication.html)

      Could it be that this simple solutions is not working any more?

      Author's profile photo Shobhit Garg
      Shobhit Garg
      Blog Post Author
      Hi,
      Thanks for pointing this out.The basic authentication doesn't work any more.
      Regards,
      Shobhit
      Author's profile photo Shobhit Garg
      Shobhit Garg
      Blog Post Author
      Hi,
      More on OAuth and 12Sprints here :
      SAP StreamWork OAuth, a code walk through.
      Regards,
      Shobhit