Skip to main content
Enterprise Agile Planning icon with arrows

This post is from the CollabNet VersionOne blog and has not been updated since the original publish date.

Last Updated Dec 01, 2015 — Enterprise Agile Planning expert

Building VersionOne Integrations with Java (Part 7: Submitting Data)

Enterprise Agile Planning

Building VersionOne Integrations with Java (Part 7: Submitting Data)

In this part of the series, we’re going to discuss how to submit data against the VersionOne API, with particular focus on doing so with the rest-1.v1/Data endpoint.

Here’s where we are at in this series:
Part 1: Introduction
Part 2: Handling Configurations
Part 3: Logging
Part 4: Parsing Data
Part 5: Using a HTTP Client
Part 6: Getting Data
Part 7: Submitting Data (YOU ARE HERE)
Part 8: Executing Operations
Part 9: Authenticating with OAuth
Part 10: Conclusion

If you’ve been following along with this series of articles, you should now have the basic building blocks of an integration including configurations, logging, parsing, a HTTP client used to make requests and getting data from the VersionOne API.

In order to create a new asset, we need to send an HTTP POST to the rest-1.v1/Data endpoint; we’ll use the following URL:

~/VersionOne/rest-1.v1/Data/Story

VersionOne has defined required fields so in order to have the correct format, the new Story definition should have at least the following info (using XML notation it should look like this):

<Asset href="/VersionOne/rest-1.v1/New/Story">
          <Attribute name="Name" act="set">Create a New Asset from Java</Attribute>
           <Relation name="Scope" act="set">
             <Asset href="/VersionOne/rest-1.v1/Data/Scope/0" idref="Scope:0"/>
           </Relation>
    </Asset>

Note: With the release of VersionOne Summer 2014, the rest.v1 endpoint supports all forms of authentication including Basic, Windows, and OAuth. See the Security topic in the VersionOne Developer Community for a complete list of endpoints and the authentication methods that they currently support.

The result of this http post will resemble the following.

<Asset href="/VersionOne/rest-1.v1/Data/Story/14191/21510" id="Story:14191:21510">
           <Attribute name="Name">Create a New Asset from Java</Attribute>
           <Relation name="Scope">
             <Asset href="/VersionOne/rest-1.v1/Data/Scope/0" idref="Scope:0" />
           </Relation>
     </Asset>

This result confirms the new asset was created.

Here’s what that looks like:

public static void createNewAsset() throws IOException {

CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(instaceUrl);
CloseableHttpResponse httpResponse = null;

String newAssetString =    "<Asset href='/VersionOne/rest-1.v1/New/Story'><Attribute name='Name' act='set'>Create a New Asset from Java</Attribute><Relation name='Scope' act='set'><Asset href='/VersionOne/rest-1.oauth.v1/Data/Scope/0' idref='Scope:0'/></Relation></Asset>";

try {

     String authString = "admin" + ":" + "admin";
     byte[] authEncodedBytes = Base64.encodeBase64(authString.getBytes());
     String authEncodedString = new String(authEncodedBytes);

     httpPost.setHeader("Authorization", "Basic " + authEncodedString);
     httpPost.setHeader("User-Agent", "com.mycompany.myapp/1.0");
     StringEntity newAsset = new StringEntity(newAssetString);
     httpPost.setEntity(newAsset);
     httpResponse = httpclient.execute(httpPost);

     HttpEntity entity = httpResponse.getEntity();
     String responseBody = EntityUtils.toString(entity, "UTF-8");
     System.out.println(httpResponse.getStatusLine());
     System.out.println(responseBody);

     checkResponseStatus(httpResponse, responseBody);
  } catch (ClientProtocolException e) {
                           e.printStackTrace();
  } catch (IOException e) {
                           e.printStackTrace();
  } finally {
              httpResponse.close();
}

In this code sample, I’m using an HttpPost object, and then after setting the header values for the request, I use the setEntity method to set the payload of the request.

Note: There is far more to the rest.v1 endpoint than can be covered in a blog post, be sure to see the tour of rest.v1 in the VersionOne Developer Community for more in-depth coverage.

Hopefully you now have a sense of how you can make use of different endpoints to submit data to VersionOne.

As always, stay agile my friend…

More from the Blog

View more
Digital.ai Government Cloud
Apr 12, 2022

Digital.ai Government Cloud receives FedRAMP Authorization through sponsorship from the United States Department of Veterans Affairs

Enterprise Agile Planning
Flagship Digital.ai Agility solutions can effectively scale agile deve ...
Read More
Nov 22, 2021

What are the qualities of highly effective agile teams?

Enterprise Agile Planning
A team is the core unit of productivity in an agile organization. Wher ...
Read More
Nov 15, 2021

How an open-first attitude revolutionized government tech development

Enterprise Agile Planning
Public perception of government is often that it is slow-moving, reluc ...
Read More
cross functional
Nov 08, 2021

6 best practices for building resilient cross-functional teams

Enterprise Agile Planning
Agile frameworks prize the quality of resilience within every facet of ...
Read More
Contact Us