Salesforce type REST API

Hi,

I was wondering how to implement the following Powershell using new Web request and Iterate web request actions. I could go to initial authentication. Then I am confused with iterating the following data that URL gets updated each time. Please advice how to update the connectors.

$RequestBody = @{}
$RequestBody.username = "username"
$RequestBody.password = "password"
$UrlString = "https://somesite/token"
#=======================================
# 1. Authenticate and get the token
#=======================================
$response = Invoke-RestMethod -Method POST -Body $RequestBody -Uri $UrlString -ContentType "application/x-www-form-urlencoded; charset=utf-8"

$headers = @{}
$headers.Authorization = "Bearer " + $response.access_token

$InstanceUrl = $response.instance_url #<--------------- Intitial URL
#=======================================
# 2. Get the data 
#=======================================
$UrlString = $InstanceUrl + "QUERY OR REQUEST"
$response = Invoke-RestMethod -Method GET -Headers $headers -Uri $UrlString -ContentType "application/json; charset=utf-8"

$coll += $response.records
while ($response.done -ne $null -And  $response.done -ne "done" ) {
    #=======================================
    # 2. Loop if more data is availabale
    #=======================================
    $UrlString = $InstanceUrl + $response.nextRecordsUrl # <================= LOOP URL is different
    $response = Invoke-RestMethod -Method GET -Headers $headers -Uri $UrlString -ContentType "application/json; charset=utf-8" 
}

In the current implementation of web requests in EasyMorph there are no standard means of transferring state from a request to the next request. I would recommend sticking to your PowerShell script for now, if there is no critical need to get rid of it. There is a workaround such as saving state (e.g. next request URL) in a file in one iteration, then reading this file in next iteration but it’s cumbersome and have a limitation that the max possible number of responses should be known ahead of time.

We’re aware of this shortcoming and will be addressing it in the future.

Note also that a native connector + import action for Salesforce are planned for release next year.

2 Likes