Skip to content

Instantly share code, notes, and snippets.

@kstrauss
Last active October 4, 2016 16:51
Show Gist options
  • Save kstrauss/bb49b368d03f72084699 to your computer and use it in GitHub Desktop.
Save kstrauss/bb49b368d03f72084699 to your computer and use it in GitHub Desktop.
GetEventstore (GES) powershell Http api examples
#$esCred = get-credential -UserName admin
<# Set automatic credentials - obviously just using the defaults#>
$username= "admin"
$password = "changeit"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$escred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
<#
Need to Reset the checkpoint for the RequestedAddition -> ContractAccepted service
http://localhost:2113/streams/Checkpoints-Xi::ServeGroupRequests_CreateContractAcceptedFromRequestedAdditionForMongoSvc
Need To Reset the checkpoint for the AcceptFromXiServiceToMongo service
http://localhost:2113/streams/Checkpoints-Xi::PublishStream_AcceptFromXiServiceToMongo
#>
$position = 0
$eventType = "PackageCreated"
$checkpointData = (gc C:\tfs\RealgyFirst\MainBranch\Main\Infrastructure\Scripts\Configuration\postData.json)|ConvertFrom-Json
#$checkpointMeta = {MaxCount:3}
$esContentType="application/vnd.eventstore.atom+json"
#$headers = @{"Accept" = "application/atom+xml"}
$headers = @{"Accept" = "application/json"}
$postHeaders = @{"Accept" = "application/json";"ES-EventType" = "$eventType";"ES-EventId"= [Guid]::NewGuid().ToString()}
#Invoke-RestMethod http://localhost:2113/streams/Checkpoints-Xi::PublishStream_AcceptFromXiServiceToMongo -ContentType "application/json" -Method Post -Body $checkpointData -Headers $postHeaders -Credential $esCred
#Invoke-RestMethod http://localhost:2113/streams/Checkpoints-Xi::PublishStream_AcceptFromXiServiceToMongo/MetaData -ContentType "application/json" -Method Post -Body $checkpointMeta -Headers $headers -Credential $esCred
$id = [Guid]::NewGuid().ToString("N")
$checkpointData.Id = $id
$(ConvertTo-Json $checkpointData) | Out-File x.json
#Invoke-RestMethod "http://dmitriydev:2113/streams/Xi::Comed-SentPackage_$id" -ContentType "application/json" -Method Post -Body $(ConvertTo-Json $checkpointData) -Headers $postHeaders -Credential $esCred
<#
$r = Invoke-RestMethod http://prodmirror:2113/streams/Xi::ReceivedPackageDecodingSet-ReceivedPackage_c218b89b8cf45988a0b10b1bed8e5070 -Method Get -Headers $headers #-Credential $esCred
#$x = (
$r.entries | sort | Select-Object -Skip 1 | %{
$url = $_.id
$url
Invoke-RestMethod $url -Method Get -Headers $headers -Credential $esCred -Verbose
}
#$x[0].Attributes
#>
@kstrauss
Copy link
Author

Shows examples of how to both read from both the regular eventstore stream and the metadata associated with a stream.

Also shows posting an event to GES

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment