Diagram API : Dowload a diagram by REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
15-05-2020 09:19 AM - edited 15-05-2020 03:49 PM
HOPEX contains diagrams that have been designed or generated. Within the web front end you can see and download the diagrams as images. The REST API also provide the ability to export the diagram as a file.
3 format of files are supported : PNG, JPEG and SVG
Use case
You want to expose, as a read only, the diagrams of HOPEX into another application or an external website. This API is for download only, no updates on the diagram are allowed.
To perform this action there are 2 mains steps :
- The selection of the diagram in HOPEX via the GraphQL API
- The download of the images file via a dedicated endpoint.
Depending on the use case you are in you may call the endpoint in a synchronous or asynchronous way. Refer to https://community.mega.com/t5/REST-API/Asynchronous-versus-Synchronous-Web-service-call/m-p/21913#M6 for more details on how to call the API in asynchronous way.
Please note that the API respect confidentiality. If the diagram you try to access is confidential with the credential you used you won't be able to get the image.
Download a given diagram (Metaclass Diagram or System Diagram)
To get your diagram as an image follow the two steps :
- Make a graphQL query to get the download URL the diagram
- Call this URL to get the binary image file
Step 1 : Get the download URL
Execute a GraphQL query on the endpoint of your choice {{server_url}}/HOPEXGraphQL/api/{{schemaName}} :
Query | Result |
|
|
The download URL are like this :
{{server_url}}/hopexgraphql/api/diagram/{{diagramId}}/image
where {{diagramId}} represent the absolute identifier of the object in HOPEX. They must be called with GET verb.
Examples with GraphiQL and Postman :
graphiQL
Get a bearer
query and result
Step 2 : Get the image
When you call the download URL the header should contains, in addition to default headers :
- Accept : which define the format of the image you expect to get. If not defined, the default value is PNG.
- image/png
- image/jpeg
- image/svg+xml
As a result of the call the body will contains the picture of the diagram.
Example with Postman :
Result of the API :
- Status 200 : the diagram has been found and is returned in the body
- Status 500 : an error has occurred with a body that contains the following message.
- the absolute identifier you gave is not valid
- the absolute identifier yet the diagram you are trying to acces is not visible with your credentials.
Example of error message :
{
"Message": "An error has occurred.",
"ExceptionMessage": "Empty Object Invocation:Only default and GetID methods are available on a Empty Object",
"ExceptionType": "System.Exception",
"StackTrace": null
}
