Skip to content

Instantly share code, notes, and snippets.

@monoman
Last active December 28, 2020 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monoman/0c8fc7e3bef991ea3bb5fae85411e274 to your computer and use it in GitHub Desktop.
Save monoman/0c8fc7e3bef991ea3bb5fae85411e274 to your computer and use it in GitHub Desktop.
Trying to add a Document file to a chain through the IL2 Node’s REST API

FAQ - Document Registry on REST [DEPRECATED]

Scenario

Trying to add a Document file to a chain through the IL2 Node’s REST API

Questions

1 - Where should the document content be posted to?

The body content of the POST is the file content (as native unencoded bytes) and it should be posted to the URL built from the query parameters

Partial request path: /documents@t_HlFTTruR33B6_hsgfpq8bPCaADamwrfQy1stPJTkY?Cipher=None&Name=BlahBlah.txt

2 - What should be the value of the Cipher parameter? None?

Cipher must be 'None' or be omitted, for now

3 - What should be the value of the KeyId parameter?

KeyId can be omitted as it would be the identifier for the key used to cipher the content which currently is not fully supported, because the namespace for this identifier is not properly defined.

4 - Parameter Name, I assume, is the name of the file being uploaded (how we want to refer to it). Confirm?

Yes, the Name of the document can be the name of the file being uploaded and will be the suggested name when downloading the document.

5 - What is the PreviousVersion parameter?

PreviousVersion is a RecordReference to a previous stored version of the document. It is basically a pair ChainId+RecordSerial for the record where the previous version was stored, this allows to have the versioning history for a document.

This RecordReference is encoded as a string of this form: ChainId@RecordSerial. Example: t_HlFTTruR33B6_hsgfpq8bPCaADamwrfQy1stPJTkY@10

6 - I am still not sure on how I can pass the document content , as I can see from the Java code that I have generated out of swagger, I only have the option of specifying chain, cipher, keyId, name, previousVersion. How to call it properly?

/* ----------------- Small part of the generated code ------------------ */
/*** Store document on chain*  
* @param chain  (required)
* @param cipher Cipher algorithm used to cipher the document (optional)
* @param keyId Unique id of key that ciphers this (optional)
* @param name Document name (may be a file name with an extension) (optional)
* @param previousVersion A reference to a previous version of this document (ChainId and RecordNumber) (optional)
* @return DocumentDetailsModel
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public DocumentDetailsModel documentAdd(
  String chain, 
  CipherAlgorithm cipher, 
  String keyId, 
  String name, 
  String previousVersion) 
    throws ApiException 
{
  ApiResponse<DocumentDetailsModel> resp = documentAddWithHttpInfo(chain, cipher, keyId, name, previousVersion);
  return resp.getData();
}

Your java code generator from Swagger is doing it wrong.

To use the Store document on chain API

POST /documents@{chain}

You MUST be able to:

  1. Pass the body content of the post as a byte array
  2. Set the Content-Type header with the appropriate value
  3. Use the certificate provided to authenticate with the server

Think of this specific API more like a File Upload instead of a simple POST

7 - How do I use the certificate that you shared with me?

You must use as the TLS client-certificate in your https request. How to do that depends on how your API client calls into Java network code, but probably you’ll need to:

  1. Tweak any generated code, or
  2. Wait for our Java Client to be ready.

Example HTTP POST request

To store a text file BlahBlah.txt in the chain t_HlFTTruR33B6_hsgfpq8bPCaADamwrfQy1stPJTkY

Partial request path: /documents@t_HlFTTruR33B6_hsgfpq8bPCaADamwrfQy1stPJTkY?Cipher=None&Name=BlahBlah.txt

With header content-type=“plain/text” and body with the text characters from the file (encoded as utf-8)

Example HTTP response

Response Code: 200

{
  "contentType": "plain/text",
  "fileId": "pZknktTAjBky381FU4rZPrj-6J7VWbLsh0JpFSPoFIU#SHA256",
  "physicalDocumentID": "TWAxPEi341Dc5grZlAIG1FQ3zBf7mg8twMqGqD5EQ_I#HMAC-SHA256",
  "cipher": "None",
  "keyId": "47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU#SHA256",
  "name": "BlahBlah.txt"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment