Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Exporting to Excel from Assets error when using the API

Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2023

Hi,

Hi there,

Below is a function that was apparently previously working with Insight to export data to excel.

I have changed the Uri basically to match what the API says it should be but I am continually getting an error about and 'activationId' but not sure what to do to fix it.

Function Export-InsightWarrantyToExcel {
param(
[string]$ExcelFile
)
$AccessToken = "MY BEARER TOKEN"
$workspaceId = "WORKSPACE ID"
# Get the current date and add 60 days to it
$Date60DaysFromNow = (Get-Date).AddDays(60)

#$Uri = "https://api.atlassian.com/jsm/assets/workspace/{workspaceId}/v1/aql/objects?Warranty Expiry Date=$($Date60DaysFromNow.ToString("yyyy-MM-dd"))"
$Uri = "https://api.atlassian.com/jsm/assets/workspace/{workspaceId}/v1/aql/objects"

$Objects = Invoke-RestMethod -Uri $Uri -Headers @{Authorization = "Bearer $AccessToken"}

# Convert the objects to an array of objects with properties that match the Excel column names
$Data = $Objects.data | Select-Object Name, 'Warranty Expiry Date'

# Export the data to Excel
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $False
$Workbook = $Excel.Workbooks.Add()
$Sheet = $Workbook.Sheets.Item(1)
#$Sheet.Cells.Item(1,1) = "id"
$Sheet.Cells.Item(1,2) = "Name"
$Sheet.Cells.Item(1,3) = "Warranty Expiry Date"
$Data | ForEach-Object {
$Row = $_.PSObject.Properties["Name"].Value
#$Sheet.Cells.Item($Row+1,1) = $_.id
$Sheet.Cells.Item($Row+1,2) = $_.Name
$Sheet.Cells.Item($Row+1,3) = $_.'Warranty Expiry Date'
}
$Workbook.SaveAs($ExcelFile)
$Excel.Quit()
}

 

here is what I use to fire the command.

Export-InsightWarrantyToExcel -ExcelFile "C:\temp\Warranty.xlsx"

 

I am continually getting bounced here;

Invoke-RestMethod : {"code":400,"message":"activationId is not provided"}

 

Thanks

1 answer

0 votes
Bevan Mills March 16, 2023

I found your issue when I was troubleshooting the same thing. Mine turned out to be the variable I had for my workspaceID wasnt formatted properly. The "ActivationID" error had me thinking it was an Authentication problem, when it was just formatting. Which made me look back over your example

Not sure if you put the {workspaceID} in the URI in brackets just for the example during testing, but I believe it should be $workspaceId 

 


$Uri = "https://api.atlassian.com/jsm/assets/workspace/{workspaceId}/v1/aql/objects"

$Uri = "https://api.atlassian.com/jsm/assets/workspace/$workspaceId/v1/aql/objects"

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events