Attachment API : Upload or Download Business Document
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
15-04-2020 11:32 AM - edited 15-05-2020 09:08 AM
In HOPEX, you can store attachments in the concept called Business Document. The files supported are numerous (DOCX, XLSX, JPEG, PNG, PDF,...) which can be uploaded/downloaded from the web interface. You may want to access this information by REST API to perform the same upload/download action.
Use case
The API support the following features :
- Upload : it manage new business documents or new version of an existing document
- Download : it allows to download the latest version or a selected version of a business document.
To perform this action there are 2 mains steps :
- The creation or selection of the object in HOPEX via the GraphQL API
- The upload/download of the binary file via a dedicated endpoint.
Download an attachment (Business Document)
To download an attachment with the REST API you must follow the step :
- Make a GraphQL query to get the download URL for your document.
- Call the URL to download the file
GraphQL query executed on the {{server_url}}/HOPEXGraphQL/api/{{schemaName}} endpoint :
Query | Result |
|
|
The download URL are like this :
{{server_url}}/HOPEXGraphQL/api/attachment/{{documentId}}/file
where {{documentId}} represent the absolute identifier of the object in HOPEX. They must be called with GET verb. Should you wish to access a specific version of the business document, just use the absolute identifier of the version you want to download. You can make a graphQL query on the business document version.
Query | Result |
|
|
Example with Postman :
|
|
Upload an attachment (Business Document)
When you upload an attachment you need to know if the business document already exist or not in HOPEX. Below you will find the 2 cases.
Case 1 : Upload for a new business document
The step to follow are :
- Created the business document object via GraphQL
- Upload the binary content in this newly create via the dedicated endpoint
Query | Result |
|
|
You now have the ID and upload URL for your document. The upload URL are like this :
{{server_url}}/HOPEXGraphQL/api/attachment/{{documentId}}/file
where {{documentId}} represent the absolute identifier of the object in HOPEX. They must be called with POST verb.
Then follow the instruction described in final step below.
Case 2 : Update of an existing business document
The step to follow are :
- Get the business document upload URL
- Upload the binary content and decided to update or create a new version of the binary content
Query | Result |
|
|
Final step :
When you call the upload URL the header should contains :
- The document version : x-hopex-documentversion with possible value new or replace
- New : will upload a new binary content and thus create a new version of business document version
- Update : will upload a binary content and replace the current existing binary content for the latest business document version
- The document file name : x-hopex-filename that contain the name of the file with the extension
- Only the extension of the file is important as it will be used to defined the file content type
When you call the upload URL the body should contains :
- the binary content of the attachment
Example with Postman
|
|
- Labels:
-
Business Document
