cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Diagram API : Dowload a diagram by REST API

oguimard
Retired

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 :

  1. The selection of the diagram in HOPEX via the GraphQL API
  2. 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 :

  1. Make a graphQL query to get the download URL the diagram
  2. 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
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 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 :

 

graphiQLgraphiQL

 

Get a bearerGet a bearer

 

query and resultquery 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 :

 

Screen Shot 05-15-20 at 09.38 AM.PNG

 

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
}

 

 

 

0 Replies