我正在尝试获取存储在加速器云中的文件的列表,这些文件已存在90天以上,因此可以删除这些文件。
我能够毫无问题地登录Powershell核心中的appcelerator云,而且我也没有问题可以获取JSON中的文件列表。问题始于获得Powershell核心以将正确的请求格式发送到加速器云。该过程应为:“显示文件,其中“ created_at”比日期少(时间戳记)....
#login
$url = https://api.cloud.appcelerator.com/..."
$auth = @{
login ='x'
password ='y'
}
$body = (ConvertTo-Json $auth)
$hdrs = @{}
$hdrs.Add("appkey","key")
Invoke-RestMethod -Uri $url - Method Post -Body $body -ContentType 'application/json' - Headers $hdrs
# now get the files and delete any older than 90 days
# (delete function not shown)
$deleteDate = (Get-Date).AddDays(-90)
$url = "https://api.cloud.appcelerator.com/v1/files....."
$hdrs =@{}
$formatendDate = @{"`$lt"= $deleteDate}
$fileDate = (ConvertTo-Json $formatendDate)
$whereclause = @{"created_at"= $fileDate}
$converted = (ConvertTo-Json $whereclause)
$request = @{where = $converted}
$body = (ConvertTo-Json $request)
Write-Host $body
Invoke-RestMethod -Uri $url -Method Get -Body $body -ContentType 'application/json' -Headers $hdrs | ConvertTo-Json
我希望它将显示的是只有与该查询匹配的文件。但是我得到的是下面的内容-所有新换行符我都不知道如何删除,并且时间戳与appcelerator时间戳格式匹配,但这就是所谓的“失败”。
实际结果:
{
"where": "{\r\n \"created_at\": \"{\\r\\n \\\"$lt\\\": \\\"2019-02-02T12:21:30.8111463-05:00\\\"\\r\\n}\"\r\n}"
}
meta response
---- --------
@{code=200; status=ok; method_name=loginUser; session_id=_2HUi15bp6S4wolPh3smySKukjA} @{users=System.Object[]}
Invoke-RestMethod : {
"meta": {
"code": 400,
"status": "fail",
"message": "Error: Invalid timestamp: {\r\n \"$lt\": \"2019-02-02T12:21:30.8111463-05:00\"\r\n} for key: created_at",
"method_name": "queryFiles"
}
}
At C:\Users\..
+ Invoke-RestMethod -Uri $url -Method Get -Body $body -ContentType 'app ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Method: GET, Reques\u2026application/json
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand