Difference between revisions of "ShaleApps test"

From MPSWiki
Jump to: navigation, search
Line 2: Line 2:
  
 
<pre>
 
<pre>
 
 
$headers = @{"Authorization"="Bearer 7b727141-d4e9-8ed4-4160-10b9a020f609"}
 
$headers = @{"Authorization"="Bearer 7b727141-d4e9-8ed4-4160-10b9a020f609"}
 
$filter = "623360-101520190-B40"
 
$filter = "623360-101520190-B40"
$url = "https://api.shaleapps.com/v1/orders?product=sandi&createdSince=2020-07-07T06:30:00.000000Z&pageLimit=100&page=1&salesOrderNumber=$($filter)"
+
$Time = Get-Date
$result = Invoke-RestMethod -Uri $url -Method GET -Headers $headers
+
$Time = $Time.ToUniversalTime()
For ($i=0; $i -lt $result.Count; $i++) {
+
$Time = $Time.AddHours(-24).ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")
    $ticket = New-Object -TypeName psobject
+
 
    $ticket | Add-Member -MemberType NoteProperty -Name BOL -Value $result[$i].bolNumber
+
function Output-Data($result) {
    $ticket | Add-Member -MemberType NoteProperty -Name Tag -Value $result[$i].salesOrderNumber
+
    Write-Host $([Environment]::NewLine)
    $ticket | Add-Member -MemberType NoteProperty -Name Status -Value $result[$i].logisticsStatus
+
    For ($i=0; $i -lt $result.Count; $i++) {
    if ($ticket.Status -ne "completed") {continue}
+
        $ticket = New-Object -TypeName psobject
    $ticket | Add-Member -MemberType NoteProperty -Name Mileage -Value $result[$i].billing.loadedMileage
+
        $ticket | Add-Member -MemberType NoteProperty -Name ID -Value $result[$i].id
    For ($j=0; $j -lt $result[$i].tasks.Count; $j++) {
+
        $ticket | Add-Member -MemberType NoteProperty -Name createdTimestamp -Value $result[$i].createdTimestamp
        For ($k=0; $k -lt $result[$i].tasks[$j].subTasks.Count; $k++) {
+
        $ticket | Add-Member -MemberType NoteProperty -Name updatedTimestamp -Value $result[$i].updatedTimestamp
            if ($result[$i].tasks[$j].subTasks[$k].type -eq "pickup") {
+
        $ticket | Add-Member -MemberType NoteProperty -Name BOL -Value $result[$i].bolNumber
                $ticket | Add-Member -MemberType NoteProperty -Name LoadingFacility -Value $result[$i].tasks[$j].site.name
+
        $ticket | Add-Member -MemberType NoteProperty -Name Tag -Value $result[$i].salesOrderNumber
 +
        $ticket | Add-Member -MemberType NoteProperty -Name Status -Value $result[$i].logisticsStatus
 +
        if ($ticket.Status -ne "completed") {continue}
 +
        $ticket | Add-Member -MemberType NoteProperty -Name Mileage -Value $result[$i].billing.loadedMileage
 +
        For ($j=0; $j -lt $result[$i].tasks.Count; $j++) {
 +
            For ($k=0; $k -lt $result[$i].tasks[$j].subTasks.Count; $k++) {
 +
                if ($result[$i].tasks[$j].subTasks[$k].type -eq "pickup") {
 +
                    $ticket | Add-Member -MemberType NoteProperty -Name LoadingFacility -Value $result[$i].tasks[$j].site.name
 +
                }
 +
                if ($result[$i].tasks[$j].subTasks[$k].type -ne "dropoff") {continue}
 +
                if ($result[$i].tasks[$j].subTasks[$k].payload.unitOfMeasure -ne "pounds") {continue}
 +
                if ($result[$i].tasks[$j].subTasks[$k].payload.type -ne "sand") {continue}
 +
                $ticket | Add-Member -MemberType NoteProperty -Name Amount -Value $result[$i].tasks[$j].subTasks[$k].payload.actualAmount
 +
                $ticket | Add-Member -MemberType NoteProperty -Name Proppant -Value $result[$i].tasks[$j].subTasks[$k].payload.name
 +
                Write-Host $ticket
 
             }
 
             }
            if ($result[$i].tasks[$j].subTasks[$k].type -ne "dropoff") {continue}
 
            if ($result[$i].tasks[$j].subTasks[$k].payload.unitOfMeasure -ne "pounds") {continue}
 
            if ($result[$i].tasks[$j].subTasks[$k].payload.type -ne "sand") {continue}
 
            $ticket | Add-Member -MemberType NoteProperty -Name Amount -Value $result[$i].tasks[$j].subTasks[$k].payload.actualAmount
 
            $ticket | Add-Member -MemberType NoteProperty -Name Proppant -Value $result[$i].tasks[$j].subTasks[$k].payload.name
 
            Write-Host $ticket
 
 
         }
 
         }
 
     }
 
     }
 
}
 
}
 +
 +
$url = "https://api.shaleapps.com/v1/orders?product=sandi&createdSince=$($Time)&pageLimit=100&page=1&salesOrderNumber=$($filter)"
 +
Write-Host $([Environment]::NewLine)
 +
Write-Host Created Since
 +
$result = Invoke-RestMethod -Uri $url -Method GET -Headers $headers
 +
Output-Data $result
 +
 +
$url = "https://api.shaleapps.com/v1/orders?product=sandi&updatedSInce=$($Time)&pageLimit=100&page=1&salesOrderNumber=$($filter)"
 +
Write-Host $([Environment]::NewLine)
 +
Write-Host Updated Since
 +
$result = Invoke-RestMethod -Uri $url -Method GET -Headers $headers
 +
Output-Data $result
 +
 
</pre>
 
</pre>

Revision as of 16:53, 8 July 2020

Run powershell ISE or VS code

$headers = @{"Authorization"="Bearer 7b727141-d4e9-8ed4-4160-10b9a020f609"}
$filter = "623360-101520190-B40"
$Time = Get-Date
$Time = $Time.ToUniversalTime()
$Time = $Time.AddHours(-24).ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")

function Output-Data($result) {
    Write-Host $([Environment]::NewLine)
    For ($i=0; $i -lt $result.Count; $i++) {
        $ticket = New-Object -TypeName psobject
        $ticket | Add-Member -MemberType NoteProperty -Name ID -Value $result[$i].id
        $ticket | Add-Member -MemberType NoteProperty -Name createdTimestamp -Value $result[$i].createdTimestamp
        $ticket | Add-Member -MemberType NoteProperty -Name updatedTimestamp -Value $result[$i].updatedTimestamp
        $ticket | Add-Member -MemberType NoteProperty -Name BOL -Value $result[$i].bolNumber
        $ticket | Add-Member -MemberType NoteProperty -Name Tag -Value $result[$i].salesOrderNumber
        $ticket | Add-Member -MemberType NoteProperty -Name Status -Value $result[$i].logisticsStatus
        if ($ticket.Status -ne "completed") {continue}
        $ticket | Add-Member -MemberType NoteProperty -Name Mileage -Value $result[$i].billing.loadedMileage
        For ($j=0; $j -lt $result[$i].tasks.Count; $j++) {
            For ($k=0; $k -lt $result[$i].tasks[$j].subTasks.Count; $k++) {
                if ($result[$i].tasks[$j].subTasks[$k].type -eq "pickup") {
                    $ticket | Add-Member -MemberType NoteProperty -Name LoadingFacility -Value $result[$i].tasks[$j].site.name
                }
                if ($result[$i].tasks[$j].subTasks[$k].type -ne "dropoff") {continue}
                if ($result[$i].tasks[$j].subTasks[$k].payload.unitOfMeasure -ne "pounds") {continue}
                if ($result[$i].tasks[$j].subTasks[$k].payload.type -ne "sand") {continue}
                $ticket | Add-Member -MemberType NoteProperty -Name Amount -Value $result[$i].tasks[$j].subTasks[$k].payload.actualAmount
                $ticket | Add-Member -MemberType NoteProperty -Name Proppant -Value $result[$i].tasks[$j].subTasks[$k].payload.name
                Write-Host $ticket
            }
        }
    }
}

$url = "https://api.shaleapps.com/v1/orders?product=sandi&createdSince=$($Time)&pageLimit=100&page=1&salesOrderNumber=$($filter)"
Write-Host $([Environment]::NewLine)
Write-Host Created Since 
$result = Invoke-RestMethod -Uri $url -Method GET -Headers $headers
Output-Data $result

$url = "https://api.shaleapps.com/v1/orders?product=sandi&updatedSInce=$($Time)&pageLimit=100&page=1&salesOrderNumber=$($filter)"
Write-Host $([Environment]::NewLine)
Write-Host Updated Since 
$result = Invoke-RestMethod -Uri $url -Method GET -Headers $headers
Output-Data $result