Last Updated Dec 01, 2015 — Enterprise Agile Planning expert
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):


          Create a New Asset from Java
           
             
           
    

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.


           Create a New Asset from Java
           
             
           
     

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 =    "Create a New Asset from Java";

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…

Are you ready to scale your enterprise?

Explore

What's New In The World of Digital.ai

May 19, 2023

What is SAFe PI Planning?

PI Planning aims to bring together all the people doing the work and empower them to plan, estimate, innovate, and commit to work that aligns with the business’s high-level goals, vision, and strategy.

Learn More
July 5, 2022

How to bring external data to Digital.ai Agility

Silvia Davis, Sr. Product Marketing Manager at Digital.ai, tells her story of how a positive app experience led to the realization that proper data integration is essential to the entire application lifecycle.

Learn More
April 19, 2022

Happy Anniversary Digital.ai!

This year, Digital.ai turns two! Continue reading for insight on Digital.ai’s journey and what plans we have for the future.

Learn More