お世話になっております。
APIチュートリアルに記載されているcurlコマンド(MAC)を
PowerShellにて実施できないか調査中です。
https://api-docs.sprinklr.com/#intro
以下のコマンドは一時拝借させていただいているMACにて実行し、結果が取得出来る事を確認済です。
terminal
1curl --location --request POST "https://api2.sprinklr.com/api/v1/reports/query" \ 2 --header "key: API_KEY" \ 3 --header "Authorization: Bearer API_TOKEN" \ 4 --header "Content-Type: application/json" \ 5 --data "{ 6 \"startTime\":1545000000000, 7 \"endTime\":1555600000000, 8 \"timeZone\":\"UTC\", 9 \"page\":0, 10 \"pageSize\":20, 11 \"reportingEngine\":\"PAID\", 12 \"report\":\"DAILY_AD_STAT\", 13 \"groupBys\":[ 14 { 15 \"heading\":\"adChannel\", 16 \"dimensionName\":\"adChannel\", 17 \"groupType\":\"FIELD\", 18 \"details\":{} 19 }, 20 { 21 \"heading\":\"DAY_OF_WEEK\", 22 \"dimensionName\":\"DAY_OF_WEEK\", 23 \"groupType\":\"FIELD\", 24 \"details\":{} 25 } 26 ], 27 \"projections\":[ 28 { 29 \"heading\":\"impressions\", 30 \"measurementName\":\"impressions\", 31 \"aggregateFunction\":\"SUM\" 32 }, 33 { 34 \"heading\":\"spent\", 35 \"measurementName\":\"spent\", 36 \"aggregateFunction\":\"SUM\" 37 }, 38 { 39 \"heading\":\"Post_Comment\", 40 \"measurementName\":\"actionsReportable.actionTypeValueMap.comment\", 41 \"aggregateFunction\":\"SUM\" 42 }, 43 { 44 \"heading\":\"Post_Like\", 45 \"measurementName\":\"actionsReportable.actionTypeValueMap.post_like\", 46 \"aggregateFunction\":\"SUM\" 47 }, 48 { 49 \"heading\":\"post_engagement\", 50 \"measurementName\":\"post_engagement\", 51 \"aggregateFunction\":\"SUM\" 52 } 53 ] 54} 55"
拝借したPCを返却し、WindowsOSのみでの運用を考えておりますので、以下PowerShellのcurlコマンドを作成しました。
PowerShell
1$l_ADHash = @{'key'='API_KEY'; 'Authorization'='Bearer API_TOKEN'; 'Content-Type'='application/json';} 2$l_ADReportProjections = @( 3 @{ 4 "heading" ="impressions"; 5 "measurementName" ="impressions"; 6 "aggregateFunction" ="SUM"; 7 }, 8 @{ 9 "heading" ="spent"; 10 "measurementName" ="spent"; 11 "aggregateFunction" ="SUM"; 12 }, 13 @{ 14 "heading" ="Post_Comment"; 15 "measurementName" ="actionsReportable.actionTypeValueMap.comment"; 16 "aggregateFunction" ="SUM"; 17 }, 18 @{ 19 "heading" ="Post_Like"; 20 "measurementName" ="actionsReportable.actionTypeValueMap.post_like"; 21 "aggregateFunction" ="SUM"; 22 }, 23 @{ 24 "heading" ="post_engagement"; 25 "measurementName" ="post_engagement"; 26 "aggregateFunction" ="SUM"; 27 } 28) 29$l_ADReportGroupBys = @( 30 @{ 31 'heading' ='adChannel'; 32 'dimensionName' ='adChannel'; 33 'groupType' ='FIELD'; 34 }, 35 @{ 36 'heading' ='DAY_OF_WEEK'; 37 'dimensionName' ='DAY_OF_WEEK'; 38 'groupType' ='FIELD'; 39 } 40) 41$l_ADReportBody = @{ 42 'reportingEngine' = 'PAID'; 43 'report' = 'DAILY_AD_STAT'; 44 'startTime' = 1545000000000; 45 'endTime' = 1555600000000; 46 'page' = 0; 47 'pageSize' = 20; 48 'timeZone' = 'UTC'; 49 'projections' = $l_ADReportProjections; 50 'groupBys' = $l_ADReportGroupBys; 51} 52curl -Method Post "https://api2.sprinklr.com/api/v1/reports/query" -Headers $l_ADHash -Body $l_ADReportBody 53###以下エラー 54curl : Developer Inactive 55発生場所 行:1 文字:1 56+ curl -Method Post "https://api2.sprinklr.com/api/v1/reports/query" -H ... 57+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 58 + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest]、WebException 59 + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand 60###
必要なデータは記載しきれたはずなのですが、、
curl : Developer Inactive
こちらはどの様なエラーなのでしょうか、、、
内側に
https://www.weblio.jp/content/Invalid+Operation+Exception
InvalidOperationException クラス
オブジェクトの現在の状態に対して無効なメソッド呼び出しが行われた場合にスローされる例外。
が存在している以上書き方の問題なのかなと考察しております。
1行目、terminal 2行目 powershell
\"projections\":[~~~~~] 'projections' = @(~~~~~)
備考 powershell -Bodyの中身
Name Value ---- ----- projections {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hashtable...} groupBys {System.Collections.Hashtable, System.Collections.Hashtable} timeZone UTC report DAILY_AD_STAT reportingEngine PAID page 0 pageSize 20 startTime 1545000000000 endTime 1555600000000
[]と()又は{}の括りが違うから、、、なのでしょうか。
丸投げな質問となりますが、ご助力お願いできればと思います。
何卒よろしくお願い致します。
追記:try{}catch{}の結果
powershell
1$_.Exception.Message 2リモート サーバーがエラーを返しました: (434) 3$_.Exception.Response.StatusCode.Value__ 4434 5$_.Exception.Response.StatusDescription 6
追記:解決
ご回答いただきました方法から、
bodyオプションの文字列をjson化し、比較しましたが違いは見られず。
curl実施時に
-Body $l_ADReportBody | ConvertTo-json でjson化した文字列を渡す
又は
PowerShell
1#json化 2$l_ADReportBody | ConvertTo-Json | Out-File hoge.json 3#jsonから取得 4$l_BodyJson = Get-Content .\hoge.json -Encoding UTF8
でjson化したファイル文字そのものを変数に詰めてパラメータ指定する事で解決しました。
ご回答ありがとうございました。また機会がありましたら是非よろしくお願い致します。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/22 08:47