Any Idea what to do with url files that come from The Canva data portal API

fpettigrosso
Community Novice

Hello,

I am experimenting with the Canvas data portal API and was successfully able to use it. The program that I made spits out the file URL link (Code below and is PowerShell).

$url = "https://portal.inshosteddata.com/api/account/self/file/byTable/assignment_fact"

$API_key = "insert key"

$secret = "insert secret"

function _url {

param($url,$secret)

function buffer

{

param ($string)

$c=@()

Foreach ($element in $string.toCharArray()) {$c+= [System.Convert]::ToSByte($element)}

return $c

}

#create url

$combo = "(\w+\:\/\/)?(\w+\.\w+\.\w+)([\/\w+]+)?((\?)([\w\=\&]+))?"

$regex = New-Object System.Text.RegularExpressions.Regex($combo,[System.Text.RegularExpressions.RegexOptions]::None)

$groups=$regex.Match($url).Groups

$protocol= $groups[1].value

$host_url=$groups[2].value

$pathname = $groups[3].value

$href = $groups[0].value

$query=$groups[6].value

#create timestamp

$time = Get-Date

$time = $time.ToUniversalTime()

$timestamp = $time.GetDateTimeFormats()[103]

#create message

$message = "GET`n$host_url`n`n`n$pathname`n$query`n$timestamp`n$secret"

$hmacsha = New-Object System.Security.Cryptography.HMACSHA256

$hmacsha.key = buffer -string $secret

$signature = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($message))

$signature = [Convert]::ToBase64String($signature)

#create hash

return @{

"protocol"= $groups[1].value;

"host"=$groups[2].value;

"pathname" = $groups[3].value;

"href" = $groups[0].value;

"query"=$groups[6].value

"timestamp" = $timestamp;

"message" = $message;

"secret" = $secret;

"_groups" = $groups;

"signature" = $signature

}

}

function call_canvas

{

param($API_key, $url_object)

$header = @{"Authorization"="HMACAuth "+ $API_key+":"+$url_object.signature; "Date" = $url_object.timestamp.ToString() }

$purlly=Invoke-WebRequest -Headers $header   -Method Get   -Uri $url_object.href

return ConvertFrom-Json $purlly.Content

}

$url_object = _url -url $url -secret $secret

$chubb =call_canvas -API_key $API_key -url_object $url_object

When I call $chubb.history[0].files.url I get this very long string (it doesn't work)

"https://hosted-data-work.s3.amazonaws.com/20161121T220310.324/dw_split/dddd/asignment_fact/part-0010... "

My question is what do I have to do to get the file at this point. I know If just copy and paste the link in a website it will download but if I call it with an invoke web request I just get a 403 error.

0 Likes