Response of REST (POST via Powershell) is not complete
I'm started working with the Invoke-RestMethod of Powershell and have now the probleme that the responses I got after my POST to the REST API of our Monitoring Tool is not complete. If I'am using other tools like a REST extension for the browser I got much more feedback:
Response REST Extension Webbrowser:
{
"entry": [
{
"@datatype": "int",
"@name": "CheckTime",
"value": {
"@type": "xs:int",
"$": "1542802849"
}
},
{
"@datatype": "int",
"@name": "AvailPageFile",
"value": {
"@type": "xs:int",
"$": "12345"
}
}
]
}
Response Powershell Invoke-RestMethod:
entry
-----
@{@datatype=int; @name=CheckTime; value=} @{@datatype=int; @name=AvailPageFile; value=}
so the 2nd Level of {} after Value= is missing.
Here is my Code:
$username = "user"
$password = "password"
$url = "http://urlREST"
$headers = @{
"Authorization" = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($username):$($password)"));
"Accept" = 'application/json ';
}
$data = @{}
$body = ConvertTo-Json $data
Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method Post -Body $body
Does somebody have a tipp for me?
Thanks
rest powershell response
add a comment |
I'm started working with the Invoke-RestMethod of Powershell and have now the probleme that the responses I got after my POST to the REST API of our Monitoring Tool is not complete. If I'am using other tools like a REST extension for the browser I got much more feedback:
Response REST Extension Webbrowser:
{
"entry": [
{
"@datatype": "int",
"@name": "CheckTime",
"value": {
"@type": "xs:int",
"$": "1542802849"
}
},
{
"@datatype": "int",
"@name": "AvailPageFile",
"value": {
"@type": "xs:int",
"$": "12345"
}
}
]
}
Response Powershell Invoke-RestMethod:
entry
-----
@{@datatype=int; @name=CheckTime; value=} @{@datatype=int; @name=AvailPageFile; value=}
so the 2nd Level of {} after Value= is missing.
Here is my Code:
$username = "user"
$password = "password"
$url = "http://urlREST"
$headers = @{
"Authorization" = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($username):$($password)"));
"Accept" = 'application/json ';
}
$data = @{}
$body = ConvertTo-Json $data
Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method Post -Body $body
Does somebody have a tipp for me?
Thanks
rest powershell response
Be aware that there are dozens of other PowerShell JSON serialization questions with one common cause:ConvertTo-Jsonhas a-Depthparameter that defaults to2.
– iRon
Nov 21 '18 at 15:45
add a comment |
I'm started working with the Invoke-RestMethod of Powershell and have now the probleme that the responses I got after my POST to the REST API of our Monitoring Tool is not complete. If I'am using other tools like a REST extension for the browser I got much more feedback:
Response REST Extension Webbrowser:
{
"entry": [
{
"@datatype": "int",
"@name": "CheckTime",
"value": {
"@type": "xs:int",
"$": "1542802849"
}
},
{
"@datatype": "int",
"@name": "AvailPageFile",
"value": {
"@type": "xs:int",
"$": "12345"
}
}
]
}
Response Powershell Invoke-RestMethod:
entry
-----
@{@datatype=int; @name=CheckTime; value=} @{@datatype=int; @name=AvailPageFile; value=}
so the 2nd Level of {} after Value= is missing.
Here is my Code:
$username = "user"
$password = "password"
$url = "http://urlREST"
$headers = @{
"Authorization" = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($username):$($password)"));
"Accept" = 'application/json ';
}
$data = @{}
$body = ConvertTo-Json $data
Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method Post -Body $body
Does somebody have a tipp for me?
Thanks
rest powershell response
I'm started working with the Invoke-RestMethod of Powershell and have now the probleme that the responses I got after my POST to the REST API of our Monitoring Tool is not complete. If I'am using other tools like a REST extension for the browser I got much more feedback:
Response REST Extension Webbrowser:
{
"entry": [
{
"@datatype": "int",
"@name": "CheckTime",
"value": {
"@type": "xs:int",
"$": "1542802849"
}
},
{
"@datatype": "int",
"@name": "AvailPageFile",
"value": {
"@type": "xs:int",
"$": "12345"
}
}
]
}
Response Powershell Invoke-RestMethod:
entry
-----
@{@datatype=int; @name=CheckTime; value=} @{@datatype=int; @name=AvailPageFile; value=}
so the 2nd Level of {} after Value= is missing.
Here is my Code:
$username = "user"
$password = "password"
$url = "http://urlREST"
$headers = @{
"Authorization" = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($username):$($password)"));
"Accept" = 'application/json ';
}
$data = @{}
$body = ConvertTo-Json $data
Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method Post -Body $body
Does somebody have a tipp for me?
Thanks
rest powershell response
rest powershell response
asked Nov 21 '18 at 12:35
Sebastian GrünebergSebastian Grüneberg
1
1
Be aware that there are dozens of other PowerShell JSON serialization questions with one common cause:ConvertTo-Jsonhas a-Depthparameter that defaults to2.
– iRon
Nov 21 '18 at 15:45
add a comment |
Be aware that there are dozens of other PowerShell JSON serialization questions with one common cause:ConvertTo-Jsonhas a-Depthparameter that defaults to2.
– iRon
Nov 21 '18 at 15:45
Be aware that there are dozens of other PowerShell JSON serialization questions with one common cause:
ConvertTo-Json has a -Depth parameter that defaults to 2.– iRon
Nov 21 '18 at 15:45
Be aware that there are dozens of other PowerShell JSON serialization questions with one common cause:
ConvertTo-Json has a -Depth parameter that defaults to 2.– iRon
Nov 21 '18 at 15:45
add a comment |
1 Answer
1
active
oldest
votes
You are basically getting the same response but it is inside a PSobject. Try the following:
$response = Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method Post -Body $body
Now play around with the $response parameter such as:
$response.entry
$response.entry.name
Etcetera. Also do a:
$response.gettype()
To learn more about PowerShell objects. If this still does not give you the right information, search for responseStream and how to get it!
1
$response | Format-List *
– DarkLite1
Nov 21 '18 at 12:49
Thanks Bernard, for your answer. That directly solve my problem. And also thanks for the keyword "responseStream". I was already reading a lot of information about the invoke command, but with the wrong keywords I wasn't able to find a solution.
– Sebastian Grüneberg
Nov 21 '18 at 12:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412169%2fresponse-of-rest-post-via-powershell-is-not-complete%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are basically getting the same response but it is inside a PSobject. Try the following:
$response = Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method Post -Body $body
Now play around with the $response parameter such as:
$response.entry
$response.entry.name
Etcetera. Also do a:
$response.gettype()
To learn more about PowerShell objects. If this still does not give you the right information, search for responseStream and how to get it!
1
$response | Format-List *
– DarkLite1
Nov 21 '18 at 12:49
Thanks Bernard, for your answer. That directly solve my problem. And also thanks for the keyword "responseStream". I was already reading a lot of information about the invoke command, but with the wrong keywords I wasn't able to find a solution.
– Sebastian Grüneberg
Nov 21 '18 at 12:51
add a comment |
You are basically getting the same response but it is inside a PSobject. Try the following:
$response = Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method Post -Body $body
Now play around with the $response parameter such as:
$response.entry
$response.entry.name
Etcetera. Also do a:
$response.gettype()
To learn more about PowerShell objects. If this still does not give you the right information, search for responseStream and how to get it!
1
$response | Format-List *
– DarkLite1
Nov 21 '18 at 12:49
Thanks Bernard, for your answer. That directly solve my problem. And also thanks for the keyword "responseStream". I was already reading a lot of information about the invoke command, but with the wrong keywords I wasn't able to find a solution.
– Sebastian Grüneberg
Nov 21 '18 at 12:51
add a comment |
You are basically getting the same response but it is inside a PSobject. Try the following:
$response = Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method Post -Body $body
Now play around with the $response parameter such as:
$response.entry
$response.entry.name
Etcetera. Also do a:
$response.gettype()
To learn more about PowerShell objects. If this still does not give you the right information, search for responseStream and how to get it!
You are basically getting the same response but it is inside a PSobject. Try the following:
$response = Invoke-RestMethod -Uri $url -Headers $headers -ContentType "application/json" -Method Post -Body $body
Now play around with the $response parameter such as:
$response.entry
$response.entry.name
Etcetera. Also do a:
$response.gettype()
To learn more about PowerShell objects. If this still does not give you the right information, search for responseStream and how to get it!
answered Nov 21 '18 at 12:42
Bernard MoeskopsBernard Moeskops
32327
32327
1
$response | Format-List *
– DarkLite1
Nov 21 '18 at 12:49
Thanks Bernard, for your answer. That directly solve my problem. And also thanks for the keyword "responseStream". I was already reading a lot of information about the invoke command, but with the wrong keywords I wasn't able to find a solution.
– Sebastian Grüneberg
Nov 21 '18 at 12:51
add a comment |
1
$response | Format-List *
– DarkLite1
Nov 21 '18 at 12:49
Thanks Bernard, for your answer. That directly solve my problem. And also thanks for the keyword "responseStream". I was already reading a lot of information about the invoke command, but with the wrong keywords I wasn't able to find a solution.
– Sebastian Grüneberg
Nov 21 '18 at 12:51
1
1
$response | Format-List *– DarkLite1
Nov 21 '18 at 12:49
$response | Format-List *– DarkLite1
Nov 21 '18 at 12:49
Thanks Bernard, for your answer. That directly solve my problem. And also thanks for the keyword "responseStream". I was already reading a lot of information about the invoke command, but with the wrong keywords I wasn't able to find a solution.
– Sebastian Grüneberg
Nov 21 '18 at 12:51
Thanks Bernard, for your answer. That directly solve my problem. And also thanks for the keyword "responseStream". I was already reading a lot of information about the invoke command, but with the wrong keywords I wasn't able to find a solution.
– Sebastian Grüneberg
Nov 21 '18 at 12:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412169%2fresponse-of-rest-post-via-powershell-is-not-complete%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Be aware that there are dozens of other PowerShell JSON serialization questions with one common cause:
ConvertTo-Jsonhas a-Depthparameter that defaults to2.– iRon
Nov 21 '18 at 15:45