Generate CSV report from manifest (API)
Within this guide we will take a list of manifest files, upload them to the system as artifacts, import the artifacts as a project and then generate a report for this project.
This guide will use these base parameters:
Parameter | Type | Explanation |
---|---|---|
instance_url | String | Instance URL for your SaaS deployment (eg: https://acme.illustria.io) |
auth_token | String | Authentication token, to generate a token please refer to this guide |
Upload manifests as artifacts
We are going to take the manifest files and upload them to the system as "artifacts".
Parameter | Type | Explanation |
---|---|---|
path_to_manifest_file | String | The location of your manifest file. |
Call:
curl --request POST \
--url <<instance_url>>/artifacts/upload \
--header 'Authorization: Bearer <<auth_token>>' \
--header 'Content-Type: multipart/form-data' \
--form files=@<path_to_manifest_file>
Response:
[
<<manifest_artifact_id>>,
...
]
This response contains the list of uploaded artifacts.
Import artifacts as a project
Parameter | Type | Explanation |
---|---|---|
package_manager | String | Package manager for the uploaded artifacts (One of: "npm", "yarn", "maven", "pip", "packagist") |
artifact_ids | List[String] | The list of artifact ids generated in the previous step |
Call:
curl --request POST \
--url <<instance_url>>/graphql \
--header 'Authorization: Bearer <<auth_token>>' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation ImportProjectFromManifest($packageManager: String!$artifactIds: [String!]) {importProjectFromManifest(packageManager: $packageManagerartifactIds: $artifactIds) {__typename... on GQLTask {id_}... on GQLError {codemessage}}}","operationName":"ImportProjectFromManifest","variables":"{\"packageManager\": \"<package_manager>\",\"artifactIds\": <<artifact_ids>>}"}'
The call data contains the following GraphQL mutation and variables:
mutation ImportProjectFromManifest(
$packageManager: String!
$artifactIds: [String!]
) {
importProjectFromManifest(
packageManager: $packageManager
artifactIds: $artifactIds
) {
__typename
... on GQLTask {
id_
}
... on GQLError {
code
message
}
}
}
{
"packageManager": <<package_manager>>,
"artifactIds": <<artifact_ids>>
}
Response
{
"data": {
"importProjectFromManifest": {
"__typename": "GQLTask",
"id_": <<import_from_manifest_task_id>>,
"status": "CREATED"
}
}
}
This response contains a GQLTask
. We will need to query the task periodically until it's finished.
Query Task Call
curl --request POST \
--url <<instance_url>>/graphql \
--header 'Authorization: Bearer <<auth_token>>' \
--header 'Content-Type: application/json' \
--data '{"query":"query GetTasks ($filters: GQLFilterParams){search (searchType: TASK, , filters: $filters) {__typename... on GQLSearchResults {records {__typename... on GQLTask {id_statusresultData {__typename... on GQLApplication {id_}... on GQLReport {id_artifacts {id_}}}}}}}}","operationName":"GetTasks","variables":"{\"filters\": {\"recordIds\": [\"<<import_from_manifest_task_id>>\"]}}"}'
Contains the following mutation and variables:
query GetTasks ($filters: GQLFilterParams){
search (searchType: TASK, , filters: $filters) {
__typename
... on GQLSearchResults {
records {
__typename
... on GQLTask {
id_
status
resultData {
__typename
... on GQLApplication {
id_
}
}
}
}
}
}
}
{
"filters": {
"recordIds": [
<<import_from_manifest_task_id>>
]
}
}
Query Task Response:
{
"data": {
"search": {
"__typename": "GQLSearchResults",
"records": [
{
"__typename": "GQLTask",
"id_": "2f91bb5f-ebc2-420a-a4f7-3785f9017ff5",
"status": "FINISHED",
"resultData": [
{
"__typename": "GQLApplication",
"id_": <<create_project_id>>
}
]
}
]
}
}
}
When the task has finished, resultData
will contain the created_project_id
we need for the next step.
Generate a report for project
Parameter | Type | Explanation |
---|---|---|
project_id | String | The project id to generate the report for. |
Call
curl --request POST \
--url <<instance_url>>/graphql \
--header 'Authorization: Bearer <<auth_token>>' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation GenerateReport($reportType: ReportTypes!$project_ids: [String!]) {reports {generateReport(reportType: $reportType, projects: $project_ids) {__typenameid_}}}","operationName":"GenerateReport","variables":"{\"reportType\": \"DETAILED\",\"project_ids\": [<<created_project_id>>]}"}'
This call contains the following mutation and variables:
mutation GenerateReport(
$reportType: ReportTypes!
$project_ids: [String!]
) {
reports {
generateReport(reportType: $reportType, projects: $project_ids) {
__typename
id_
}
}
}
{
"reportType": "DETAILED",
"project_ids": [<<project_id>>]
}
Response:
{
"data": {
"reports": {
"generateReport": {
"__typename": "GQLTask",
"id_": <<generate_report_task_id>>
}
}
}
}
We will now query the task by its id (generate_report_task_id
). When the task finishes it will contain the
report and the relevant artifacts:
Query Task Call
curl --request POST \
--url <<instance_url>>/graphql \
--header 'Authorization: Bearer <<auth_token>>' \
--header 'Content-Type: application/json' \
--data '{"query":"query GetTasks ($filters: GQLFilterParams){search (searchType: TASK, , filters: $filters) {__typename... on GQLSearchResults {records {__typename... on GQLTask {id_statusresultData {__typename... on GQLReport {id_artifacts {artifactFiletypeid_}}}}}}}}","operationName":"GetTasks","variables":"{\"filters\": {\"recordIds\": [<<generate_report_task_id>>]}}"}'
This call contains the following mutation and variables:
query GetTasks ($filters: GQLFilterParams){
search (searchType: TASK, , filters: $filters) {
__typename
... on GQLSearchResults {
records {
__typename
... on GQLTask {
id_
status
resultData {
__typename
... on GQLReport {
artifacts {
artifactFiletype
id_
}
}
}
}
}
}
}
}
{
"filters": {
"recordIds": [
<<generate_report_task_id>>
]
}
}
Query Task Response:
{
"data": {
"search": {
"__typename": "GQLSearchResults",
"records": [
{
"__typename": "GQLTask",
"id_": "2301f4c0-02ab-49a3-9318-0da1c85e4efd",
"status": "FINISHED",
"resultData": [
{
"__typename": "GQLReport",
"id_": "b2fdbc6a-bc15-4521-b37f-d127c947d0d7",
"artifacts": [
{
"artifactFiletype": "csv",
"id_": <<csv_report_artifact_id>>
},
{
"artifactFiletype": "pdf",
"id_": "d28c892a-6e2d-4b0d-937f-48356bc33163"
}
]
}
]
}
]
}
}
}
In resultsData
we now have a list of artifacts by type, select the csv
report and fetch it from the system using
the report_artifact_id
.
Fetch report artifact
curl --request GET \
--url '<<instance_url>>/artifacts/download?artifact_id=<<csv_report_artifact_id>>' \
--header 'Authorization: Bearer <<auth_token>>' \
-o "report.csv"
You now have the results inside the report.csv
file.