12. Diagram API: dowloading a diagram by REST API
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 provides the ability to export the diagram as a file.
Supported formats are: PNG, JPEG and SVG.
12.1. 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, updates on the diagram are not allowed.
To perform this action:
1. Select the diagram in HOPEX via the GraphQL API.
2. Download the images file via a dedicated endpoint.
Note that the API complies with the confidentiality. If the diagram you try to access is confidential with the credential you used you will not be able to get the image.
12.1.1. Downloading a diagram (Metaclass Diagram or System Diagram)
To get your diagram as an image:
1. Make a graphQL query to get the download URL of the diagram.
2. Call this URL to get the binary image file.
Step 1: Getting the download URL
Execute a GraphQL query on the endpoint of your choice {{server_url}}/HOPEXGraphQL/api/{{schemaName}} :
|
Query
|
Result
|
|
query getDiagram {
application {
name
diagram {
name
downloadUrl
}
}
}
|
{
"data": {
"application": [
{
"name": "Excel Checker",
"diagram": [
{
"name": "Application Structure Diagram Excel Checker",
"downloadUrl": "http://w-ogd/hopexgraphql/api/diagram/uPRCRnJ(Hn95/image"
}
]
}
]
}
}
|
The download URL are like:
{{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.
• Example with GraphiQL:
• Examples with Postman:
Get a bearer
query and result
Step 2: Getting the image
When you call the download URL the header should contains, in addition to default headers:
• Accept: which defines the format of the image you expect to get. If not defined, the default value is PNG.
o image/png
o image/jpeg
o image/svg+xml
As a result of the call the body contains the picture of the diagram.
Example with Postman:
12.1.2. 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.
o the absolute identifier you gave is not valid
o 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
}