RestMethod api response

{
“status”: “success”,
“messages”: {
“code”: “01010000”
},
“data”: {
“inquiryResponse”: “31-May-2023,CM,09701,09701,185,C,10002,U,01050100”
}
}

I want to write the file when the code under inquiryreponse is 01050100. Can any one please share with me the script

Hello, this forum is for helping people with scripting related questions only. We do not write scripts for people and we do expect some effort from users. If you have code you’re working with then post it and ask specific questions. Make sure to format code with the ‘</>’ button.

Hello, below is the code which push the data on real time basis. I need a help where if there is any error response It should break.

<
$headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$headers.Add(“nonce”, [convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(“30052023110446380:110446” )))
$headers.Add(“Content-Type”, “application/json”)
$headers.Add(“Authorization”, “Bearer “)
$headers.Add(“Cookie”, “HttpOnly; HttpOnly”)
$body = @”
{
"version”: "1.0",
"data": {
"msgId": "09701202305300000051","requestType": "I",
"allocationRequest": [
{"curDate": "30-May-2023","segment": "CM","cmCode": "09701","tmCode": "09701","cpCode": "“,"cliCode”: "KNL171","accType": "C","amt":777.00,"filler1": "“,"filler2”: "“,"filler3”: "“,"filler4”: "“,"filler5”: "“,"filler6”: "“,"action”: "U"}
]
}
}
"@
$response = Invoke-RestMethod ‘https://www.connect2nse.com/coll-allocation/allocation’ -Method ‘POST’ -Headers $headers -Body $body

$response | ConvertTo-Json | Out-File “D:\APIRESPONSE\09701202305300000051.txt”

/>

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

(Sometimes the “preformatted text” button hides behind the settings gear symbol :wink: )

You would want to add exception handling

Unless you’re talking about the API call itself in which case you would need to review the API docs for HTTP status codes for failures