3

I am trying to create a new 'Expression' in VersionOne - effectively adding a new 'comment' to a conversation.

In theory, the rest-1.v1/Data API should allow this, but I can't figure out how to do it - there is precious little documentation about using the API (using POST) to create objects.

FWIW, here's what I'm doing (after successfully accessing the server with valid credentials):

URL: /rest-1.v1/Data/Expression

XML:

<Asset href="<Server Base URI>/rest-1.v1/Data/Expression">
<Attribute name="AssetType">Expression</Attribute>
<Relation name="InReplyTo" />
<Attribute name="AuthoredAt">2014-05-28T21:48:37.940</Attribute>
<Attribute name="Content">A new comment</Attribute>
<Attribute name="AssetState">64</Attribute>
<Relation name="Author">
  <Asset href="<Server Base URI>/rest-1.v1/Data/Member/2015" idref="Member:2015" />
</Relation>
<Relation name="BelongsTo">
  <Asset href="<Server Base URI>/rest-1.v1/Data/Conversation/2018" idref="Conversation:2018" />
</Relation>
<Attribute name="Author.Name">user@example.com</Attribute>
<Attribute name="Author.Nickname">User Name</Attribute>
<Relation name="Mentions">
  <Asset href="<Server Base URI>/rest-1.v1/Data/Story/2017" idref="Story:2017" />
</Relation>
</Asset>

I keep getting a 400 Bad Request the following error:

<Error href="<Server Base URI>/rest-1.v1/Data/Expression">
<Message>Violation'Required'AttributeDefinition'Content'Expression</Message>
<Exception class="VersionOne.DataException">
<Message>Violation'Required'AttributeDefinition'Content'Expression</Message>
</Exception>
</Error>

I assume I'm missing something obvious - does anyone know what it is?

roryhewitt
  • 4,097
  • 3
  • 27
  • 33

1 Answers1

2

IF you examine the metadata for a VersionOne Expression, you will see 3 required fields (Author,AuthoredAt,Content). Logically this makes sense to be able to just create a single, zombie expression but I witnessed otherwise. This might be a mistake in the stylesheet or just my browser because it seems POSTing with only those three will return a 400 error. To get a guaranteed working payload, include the relation "inReplyTo" and that is all that you will need to create an expression within the context of a particular Conversation.

Given that you are responding to an existing expression (comment) This should work fine.

POST to rest-1.v1/Data/Expression

<Asset>
  <Relation name="Author" act="set">
     <Asset idref="Member:2015" />
  </Relation>

  <Attribute name="AuthoredAt">2014-05-02T21:48:37.940</Attribute>  

  <Attribute name="Content" act="set">A new comment</Attribute>

  <Relation name="InReplyTo" act="set">
     <Asset idref="Expression:xxxxx" /> 
  </Relation>
</Asset>

You don't need Asset state or mentions or belongs to. AssetState is readonly, and BelongsTo is filled in automatically after your Expression is created. It inherits a reference to the containing Conversation from the Expression object entered in the InReplyTo field and the Mentions relation is optional.

FYI, I believe that you didn't see the Legend on the right hand side of a the meta query output as seen in a browser. Real quick here, when you do a meta query, the items with * are required to Post, Bold items are Read/Write optional, the italicized items are readonly, and the bold items towards the bottom that are appended with ": operation" is the operation that you are allow to do against that particular asset.

Mark Irvin
  • 830
  • 1
  • 6
  • 16
  • 1
    Hey Mark, QQ: What if I am NOT replying to an existing expresssion (or if I am, but I don't know what the expression OID is? – roryhewitt Jun 03 '14 at 20:32
  • Actually, a better question might be "what if there is no existing conversation?" As background, I'm trying to mimic what we did with Mingle (which we are replacing with VersionOne) - simply add a comment to a story. It may be that all I know is the Story name (e.g. B-1234)... If it makes sense, I'll either update my original question or start a new one. – roryhewitt Jun 04 '14 at 17:13
  • An Expression cannot be created outside of the context of a Conversation. Your comment on a story is the beginning of a Conversation. An expression is basically a comment within the context of a Conversation. In the UI, As soon as you type a comment in the "Start a Conversation" box and click "Share", a container Conversation is created then an Expression, which is your comment, is created. An Expression can't stand alone. The API will not allow you circumvent this business rule. – Mark Irvin Jun 16 '14 at 01:07