While using the following in powershell its copied from a website to process online payments thro an application. I change the access token and unique key when writing this.
$authHeader = @{ Authorization = 'Bearer {0}' -f "{{ACCESS_TOKEN}}" }
$body = '{
"idempotency_key": "{{UNIQUE-KEY}}",
"autocomplete": true,
"amount_money": {
"amount": 100,
"currency": "USD"
},
"source_id": "cnon:card-nonce-ok"
}
}'
Invoke-RestMethod -Uri https://connect.squareupsandbox.com/v2/payments |
-Method Post |
-ContentType "application/json" |
-Headers $authHeader |
-Body $body
i get the following exception
-Method : The term '-Method' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:14 char:4
+ -Method Post |
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (-Method:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
or if i remove these | and use space instead like comment said,
$authHeader = @{ Authorization = 'Bearer {0}' -f "{{ACCESS_TOKEN}}" }
$body = '{
"idempotency_key": "{{UNIQUE-KEY}}",
"autocomplete": true,
"amount_money": {
"amount": 100,
"currency": "USD"
},
"source_id": "cnon:card-nonce-ok"
}
}'
Invoke-RestMethod -Uri https://connect.squareupsandbox.com/v2/payments
-Method Post
-ContentType "application/json"
-Headers $authHeader
-Body $body
i get the following exception and as shown the old -Method exception is still there.
Invoke-RestMethod : {"errors": [{"code": "UNAUTHORIZED","detail": "Your request did not include an `Authorization`
http header with an access token. The header value is expected to be of the format \"Bearer TOKEN\" (without
quotation marks), where TOKEN is to be replaced with your access token (e.g. \"Bearer {{Access token}}\"). For
more information, see https://docs.connect.squareup.com/api/connect/v2/#requestandresponseheaders. If you are seeing
this error message while using one of our officially supported client libraries, please report this to
[email protected]. ","category": "AUTHENTICATION_ERROR"}]}
At line:13 char:1
+ Invoke-RestMethod -Uri https://connect.squareupsandbox.com/v2/payment ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
-Method : The term '-Method' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:14 char:4
+ -Method Post
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (-Method:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
-ContentType : The term '-ContentType' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:15 char:4
+ -ContentType "application/json"
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (-ContentType:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
-Headers : The term '-Headers' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:16 char:4
+ -Headers $authHeader
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (-Headers:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
-Body : The term '-Body' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:17 char:4
+ -Body $body
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (-Body:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
|to separate your parameters, they should be space separated