@michaelderekjones
Iβve made some progress but Iβm stuck at the last point. I followed your advice and hereβs what Iβve done:
Created a PowerShell script to read contents from the JSON file:
$jsonDirectory = "<ABSOLUTE-DIR-LOC>"
foreach ($jsonFile in Get-ChildItem -Path $jsonDirectory -Filter *.json ) {
$jsonContents = Get-Content -Path $jsonFile.FullName | Out-String
$newmanCommand = "newman run Polyline_Caching.postman_collection.json --folder `"Import from Waypoint Creation`" --env-var 'DATA=$jsonContents' --verbose"
try{
Write-Host $newmanCommand
Invoke-Expression $newmanCommand
} Catch {
Throw "Script failed with the following: $($_.exception.Message)"
}
}
The output of Write-Host $newmanCommand
(essentially a stdout) is:
newman run Polyline_Caching.postman_collection.json --folder "Import from Waypoint Creation" --env-var 'DATA=[
{
"id": null,
"geohash": null,
"latitude": 19.26362,
"sequence": 0,
"longitude": 73.07356,
"googleAddress": null
},
{
"id": null,
"geohash": null,
"latitude": 19.26045,
"sequence": 1,
"longitude": 73.06872,
"googleAddress": null
},
{
"id": null,
"geohash": null,
"latitude": 19.25907,
"sequence": 2,
"longitude": 73.06629,
"googleAddress": null
},
{
"id": null,
"geohash": null,
"latitude": 19.25679,
"sequence": 3,
"longitude": 73.06294,
"googleAddress": null
},
{
"id": null,
"geohash": null,
"latitude": 19.25558,
"sequence": 4,
"longitude": 73.06165,
"googleAddress": null
},
{
"id": null,
"geohash": null,
"latitude": 19.25434,
"sequence": 5,
"longitude": 73.06005,
"googleAddress": null
},
{
"id": null,
"geohash": null,
"latitude": 19.25354,
"sequence": 6,
"longitude": 73.0587,
"googleAddress": null
}
]
' --verbose
Which should work since the format seems correct.
However, newman fails with the following comment:
import
β Import from Waypoint Creation
POST 0.0.0.0:8000/import/ir
422 Unprocessable Entity β
22ms time β
311Bβ 302Bβ size β
10β 4β headers β
0 cookies
β β raw β
9B
β [
β {
β
β
β β application/json β
text β
json β
utf8 β
158B
β {"detail":[{"type":"json_invalid","loc":["body",9],"msg":"JSON decode error","input":{},"ctx":{"error":"Expecting pro
β perty name enclosed in double quotes"}}]}
β
prepare wait dns-lookup tcp-handshake transfer-start download process total
27ms 5ms (cache) 4ms 4ms 7ms 303Β΅s 49ms
1. Status Code is 201
2. Make sure some nodes are added
3. Make sure some relationships are added
βββββββββββββββββββββββββββ¬ββββββββββββββββββββ¬ββββββββββββββββββ
β β executed β failed β
βββββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββ€
β iterations β 1 β 0 β
βββββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββ€
β requests β 1 β 0 β
βββββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββ€
β test-scripts β 2 β 0 β
βββββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββ€
β prerequest-scripts β 2 β 0 β
βββββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββ€
β assertions β 3 β 3 β
βββββββββββββββββββββββββββ΄ββββββββββββββββββββ΄ββββββββββββββββββ€
β total run duration: 201ms β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β total data received: 158B (approx) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β average response time: 22ms [min: 22ms, max: 22ms, s.d.: 0Β΅s] β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β average first byte time: 4ms [min: 4ms, max: 4ms, s.d.: 0Β΅s] β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# failure detail
1. AssertionError Status Code is 201
expected response to have status code 201 but got 422
at assertion:0 in test-script
inside "import / Import from Waypoint Creation"
2. AssertionError Make sure some nodes are added
expected undefined to be a number or a date
at assertion:1 in test-script
inside "import / Import from Waypoint Creation"
3. AssertionError Make sure some relationships are added
expected undefined to be a number or a date
at assertion:2 in test-script
inside "import / Import from Waypoint Creation"
Even if I try to parse it in the Pre-request Script with JSON.parse()
I get the same error (at the level of Pre-request script rather than a 422). Iβm not sure why this is happening. Itβs evident that newman receives properties without any quotations but then the request body sent it to seems to contains double quotes.
Most of the similar problems in the forums are straightforward - and hence not applicable to this case.