Create and Get Report

Last modified 08 Mar 2024 08:42 +01:00
Table of Contents

Description

The example describes a use-case when we want to create a new report definition, execute the task to create a new report and then fetch a report data object witch contains the file path to the report data.

  1. You have to create the new report definition, for this we use the example "Create a new Report regarding Error audit records in 24h".

  2. Based on the example "Create a new Task for Report Execution" a new task referencing the report definition is created and the report data is generated.

  3. A filter is used to fetch the report data, we use the query in the example "Search Report Data based on Report Reference".

  4. The report data contains the file path which we then can use to fetch the actual report CSV from the file system.

Authentication methods used to work with the REST api

Authentication methods

Example

In our examples we are authenticating with the credentials, name "administrator" and password "y0uR_P455woR*d" on a localhost instance running on port 8080.

For some help regarding the REST examples please see this link:

Create a new Report regarding Error audit records in 24h
curl --user administrator:y0uR_P455woR*d \
-H "Content-Type: application/json" \
-X POST http://localhost:8080/midpoint/ws/rest/reports \
-v \
--data-binary @./samples/rest/report-error-audit-records-24h.json
Show data source example for "Create a new Report regarding Error audit records in 24h" | GitHub
{
  "report" : {
    "name" : "All error audit records in 24h",
    "description" : "Report made from all audit records.",
    "assignment" : {
      "@id" : 1,
      "identifier" : "archetype",
      "targetRef" : {
        "oid" : "00000000-0000-0000-0000-000000000171",
        "relation" : "org:default",
        "type" : "c:ArchetypeType"
      }
    },
    "archetypeRef" : {
      "oid" : "00000000-0000-0000-0000-000000000171",
      "relation" : "org:default",
      "type" : "c:ArchetypeType"
    },
    "roleMembershipRef" : {
      "oid" : "00000000-0000-0000-0000-000000000171",
      "relation" : "org:default",
      "type" : "c:ArchetypeType"
    },
    "objectCollection" : {
      "collection" : {
        "baseCollectionRef" : {
          "collectionRef" : {
            "oid" : "00000000-0000-0000-0001-000000000004",
            "relation" : "org:default",
            "type" : "c:ObjectCollectionType"
          }
        }
      },
      "parameter" : [ {
        "@id" : 2,
        "name" : "outcome",
        "type" : "#OperationResultStatusType",
        "display" : {
          "label" : {
            "orig" : "outcome",
            "norm" : "outcome",
            "translation" : {
              "key" : "AuditEventRecordType.outcome"
            }
          }
        }
      }, {
        "@id" : 3,
        "name" : "eventType",
        "type" : "#AuditEventTypeType",
        "display" : {
          "label" : {
            "orig" : "eventType",
            "norm" : "eventtype",
            "translation" : {
              "key" : "AuditEventRecordType.eventType"
            }
          }
        }
      }, {
        "@id" : 4,
        "name" : "eventStage",
        "type" : "#AuditEventStageType",
        "display" : {
          "label" : {
            "orig" : "eventStage",
            "norm" : "eventstage",
            "translation" : {
              "key" : "AuditEventRecordType.eventStage"
            }
          }
        }
      }, {
        "@id" : 5,
        "name" : "from",
        "type" : "#dateTime",
        "display" : {
          "label" : {
            "orig" : "from",
            "norm" : "from",
            "translation" : {
              "key" : "AuditPopupPanel.dateFrom"
            }
          }
        }
      }, {
        "@id" : 6,
        "name" : "to",
        "type" : "#dateTime",
        "display" : {
          "label" : {
            "orig" : "to",
            "norm" : "to",
            "translation" : {
              "key" : "AuditPopupPanel.dateTo"
            }
          }
        }
      }, {
        "@id" : 7,
        "name" : "targetRef",
        "type" : "c:ObjectReferenceType",
        "display" : {
          "label" : {
            "orig" : "targetRef",
            "norm" : "targetref",
            "translation" : {
              "key" : "AuditEventRecordType.targetRef"
            }
          }
        }
      }, {
        "@id" : 8,
        "name" : "initiatorRef",
        "type" : "c:ObjectReferenceType",
        "display" : {
          "label" : {
            "orig" : "initiatorRef",
            "norm" : "initiatorref",
            "translation" : {
              "key" : "AuditEventRecordType.initiatorRef"
            }
          }
        }
      } ]
    }
  }
}

The response is an HTTP 201 code in case of success without a response body. Also, the response contains a Location Header pointing to the location of the created user.

Example location header
Location: http://localhost:8080/midpoint/ws/rest/reports/4de173d5-4dff-4e4f-bfb8-47f951f26637
Create a new Task for Report Execution
curl --user administrator:y0uR_P455woR*d \
-H "Content-Type: application/json" \
-X POST http://localhost:8080/midpoint/ws/rest/tasks \
-v \
--data-binary @./samples/rest/task-report-create.json
Show data source example for "Create a new Task for Report Execution" | GitHub
{
  "task" : {
    "name" : "Export task for all error audit records in 24h ",
    "assignment" : {
      "targetRef" : {
        "oid" : "00000000-0000-0000-0000-000000000511",
        "relation" : "org:default",
        "type" : "c:ArchetypeType"
      }
    },
    "archetypeRef" : {
      "oid" : "00000000-0000-0000-0000-000000000511",
      "relation" : "org:default",
      "type" : "c:ArchetypeType"
    },
    "schedulingState" : "ready",
    "binding" : "loose",
    "activity" : {
      "work" : {
        "reportExport" : {
          "reportRef" : {
            "oid" : "04c476df-702d-4abf-aa77-c7384ee3b15c",
            "relation" : "org:default",
            "type" : "c:ReportType"
          }
        }
      }
    }
  }
}

The response is an HTTP 202 code in case of success without a response body. Also, the response contains a Location Header pointing to the location of the created user.

Example location header
Location: http://localhost:8080/midpoint/ws/rest/tasks/6d13632c-6b75-4a33-9744-ec9523375f6b
Search Report Data based on Report Reference
curl --user administrator:y0uR_P455woR*d \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-X POST http://localhost:8080/midpoint/ws/rest/reportData/search \
-v \
--data-binary @./samples/rest/query-report-data.json
Show data source example for "Search Report Data based on Report Reference" | GitHub
{
  "query": {
    "filter": {
      "text": "reportRef/@/name =\"All error audit records in 24h\""
    }
  }
}

The response is an HTTP 200 code in case of success with a response body containing the queried items.

Example Output is a list of objects.
{
  "@ns" : "http://prism.evolveum.com/xml/ns/public/types-3",
  "object" : {
    "@type" : "http://midpoint.evolveum.com/xml/ns/public/common/api-types-3#ObjectListType",
    "object" : [ {
      "@type" : "c:ReportDataType",
      "oid" : "1a1f8226-6b2d-4253-8714-f0a8e61179fb",
      "version" : "1",
      "name" : "All error audit records in 24h-EXPORT 08-03-2024 08-18-46.230 - CSV",
      "description" : "Report made from all audit records. - CSV",
      "metadata" : {},
      "operationExecution" : {},
      "iteration" : 0,
      "iterationToken" : "",
      "filePath" : "./foo/baar/All_error_audit_records_in_24h-EXPORT_08-03-2024_08-18-46.228.csv",
      "reportRef" : {
        "oid" : "579b3765-a2d3-46bc-98e5-3a2414d0accd",
        "relation" : "org:default",
        "type" : "c:ReportType"
      },
      "nodeRef" : {
        "oid" : "3f383096-0da2-42f5-97d5-cdc2da0f61db",
        "relation" : "org:default",
        "type" : "c:NodeType"
      }
    } ]
  }
}
Was this page helpful?
YES NO
Thanks for your feedback