AnsweredAssumed Answered

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

Question asked by Franco Pettigrosso on Nov 22, 2016


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 = ""
$API_key = "insert key"
$secret = "insert secret"
function _url {
function buffer 
 param ($string)
 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)

$protocol= $groups[1].value
$pathname = $groups[3].value
$href = $groups[0].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;
"pathname" = $groups[3].value; 
"href" = $groups[0].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)

"… "

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.