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

Trouble retrieving notebook results (or even notebook as a whole) via API

dcbarry
Visitor

I'm having trouble determining how to retrieve the results of an already defined DQL query in a notebook. I've reviewed docs everywhere, but can seem to get it functional.   My token has full read rights everywhere, and is the owner of the notebook (my personal api). The UUIDs are triple confirmed as valid. (Short and long form).

 

I keep getting 404 (not found) error, although the docs imply this is the way.  ("api/v1/documents").    

My code looks like this: (Fake tenant IDs) 

I am aware I'm supposed to be able to invoke DQL from my API call directly, this is not a desirable solution.   Wish to use what is already in the notebook. 

 

$DynaHost = "https://{environmentid}.live.dynatrace.com"

#Note: I've tried both the extended and short forms of the ID
#$NotebookId = "27268a8e-4667-4373-beda-dddb427f0ead#9b9fde91-f574-47bd-b89a-7c4584d1e02d"
$NotebookId = "27268a8e-4667-4373-beda-dddb427f0ead"

$ApiUrl = "$DynaHost/api/v1/documents/$NotebookId"

try {
    $notebookContent = Invoke-RestMethod -Uri $ApiUrl -Headers $Headers -Method Get
    Write-Host "Content for Notebook $NotebookId"
    $notebookContent | ConvertTo-Json -Depth 99 | Out-File -FilePath "C:\temp\$NotebookId.json"
} catch {
    Write-Host 'Error retrieving notebook content: $_.Exception.Message'
}

5 REPLIES 5

MaximilianoML
Champion

Hello @dcbarry 

Let me see if I can help you with this one...

I was checking your code and maybe miss the "platform" in the endpoint.

$DynaHost   = "https://{environmentid}.live.dynatrace.com"
$NotebookId = "27268a8e-4667-4373-beda-dddb427f0ead"

# Metadata
$MetaUrl = "$DynaHost/platform/document/v1/documents/$NotebookId"

# Content download
$ContentUrl = "$DynaHost/platform/document/v1/documents/$NotebookId/content"

try {
    $notebookMeta = Invoke-RestMethod -Uri $MetaUrl -Headers $Headers -Method Get
    $notebookMeta | ConvertTo-Json -Depth 99 | Out-File "C:\temp\$NotebookId-meta.json"

    Invoke-WebRequest -Uri $ContentUrl -Headers $Headers -Method Get -OutFile "C:\temp\$NotebookId-content.bin"

    Write-Host "Notebook metadata retrieved successfully."
    Write-Host "Notebook content downloaded to C:\temp\$NotebookId-content.bin"
}
catch {
    Write-Host ("Error retrieving notebook: " + $_.Exception.Message)
    if ($_.ErrorDetails.Message) {
        Write-Host $_.ErrorDetails.Message
    }
}

 And in my POV there is not a supported “give me the already-rendered result set from this notebook section” endpoint, unfortunately. The supported path is to read the notebook content, extract the DQL from the section, and execute that DQL through the Grail Query API.

I hope this helps you 😀

Max Lopes

Thanks for responding!

HHmm.. that gives me a 403 forbidden, error. However, I noted I accidentally deleted the build of headers in my original code.  Including:

    "Authorization" = "Bearer $Apitoken"
    "Content-Type"  = "application/json"
 
Applying them did not change the response though.  I'm wlking though it a bit more closely, I'll update again, just wanted to give a quick thanks, and note my other error.
 





My pleasure, happy to help. Keep us updated this topic is really interesting, actually

Max Lopes

hey, just thought you'd like to know, i decided to take the other approach, and directly do a DQL query as suggested.    However, now Im having token troubles. LOL.    so, i reposted with examples.

Heyy! Nice to know, could you gently attach the link to this new post, please? If this helped you, and if you think it's fair, Kudos helps me 😁

Max Lopes

Featured Posts