Creating entities and their children

In the scenario where one would want to create an entity and its child, it is important to remember to create the parent first and the child second.

The following examples shows how to create a Document in a Batch with GUID 00000000-0000-0000-0000-000000000000 and then create a Convert Word Document Document Operation for the document

For the JSON examples, remember to set your Basic Authentication credentials in the header

POST http://portal.xpertdoc.com/odata4/v6/Documents HTTP/1.1
Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/json; charset=utf-8
Host: preview.portal.xpertdoc.com
Content-Length: 133
Expect: 100-continue
Connection: Keep-Alive

{
  "BatchId":"00000000-0000-0000-0000-000000000000",
  "InputDocumentName":"Document Name",
  "Status":"Created",
  "InputDocumentType":"Docx"
}

Once the response is received, one can use the DocumentId and create the Document Operation. GUID 11111111-1111-1111-1111-111111111111 is used as example.

POST http://portal.xpertdoc.com/odata4/v6/DocumentOperations HTTP/1.1
Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/json; charset=utf-8
Host: portal.xpertdoc.com
Content-Length: 644
Expect: 100-continue

{
  "DocumentId":"11111111-1111-1111-1111-111111111111",
  "ContractName":"Xpertdoc.DocumentServices.Handler.Operations.ConvertWordDocumentOperation",
  "Status":"Created",
  "InputMetadata":"<!-- Optional metadata. -->\n<ConvertWordDocumentOperationMetadata>\n  <!-- Required. Valid conversion types are: Docx, Doc, Rtf, Odt, Txt, Html, Mhtml, Pdf, Xps. -->\n  <ConversionType>Pdf</ConversionType>\n  <!-- Optional. -->\n  <IncludeDocumentProperties>false</IncludeDocumentProperties>\n  <!-- Optional. -->\n  <UseIso19005>false</UseIso19005>\n  <!-- Optional. -->\n  <BitmapMissingFonts>true</BitmapMissingFonts>\n</ConvertWordDocumentOperationMetadata>"
}

The following example is in C#. Please note that JObject needs the following:

using Newtonsoft.Json.Linq;
// Create a Document and assign it to a Batch
var url = "http://portal.xpertdoc.com/odata4/v6/Documents";

var values = new Dictionary<string, string>
{		
		{ "BatchId", "00000000-0000-0000-0000-000000000000" },		
		{ "InputDocumentName", "Document Name" },
		{ "Status", "Created" },		
		{ "InputDocumentType", "Docx" }
};	
var result = await Post(url, values);
	
// Grab the result of the newly created Document and parse its elements
var jObject = JObject.Parse(result);
	
// Create a Document Operation and assign it to our previously created Document
url = "http://portal.xpertdoc.com/odata4/v6/DocumentOperations";
values = new Dictionary<string, string>
{		
		{ "DocumentId", jObject["DocumentId"].ToString() },		
		{ "ContractName", "Xpertdoc.DocumentServices.Handler.Operations.ConvertWordDocumentOperation" },
		{ "Status", "Created" },		
		{ "InputMetadata", "<!-- Optional metadata. -->\n<ConvertWordDocumentOperationMetadata>\n  <!-- Required. Valid conversion types are: Docx, Doc, Rtf, Odt, Txt, Html, Mhtml, Pdf, Xps. -->\n  <ConversionType>Pdf</ConversionType>\n  <!-- Optional. -->\n  <IncludeDocumentProperties>false</IncludeDocumentProperties>\n  <!-- Optional. -->\n  <UseIso19005>false</UseIso19005>\n  <!-- Optional. -->\n  <BitmapMissingFonts>true</BitmapMissingFonts>\n</ConvertWordDocumentOperationMetadata>" }
};	
result = await Post(url, values);