Skip to content

Instantly share code, notes, and snippets.

@miller45
Last active May 30, 2023 13:19
Show Gist options
  • Save miller45/b1981fe238aab3a3e30fe7fae72cda45 to your computer and use it in GitHub Desktop.
Save miller45/b1981fe238aab3a3e30fe7fae72cda45 to your computer and use it in GitHub Desktop.
least friction commands to access topic data on kafka
curl \
-X POST \psot
-H "Content-Type: application/json" \
-H "Authorization: Basic <yourbase64encodedapikeyandapisecret>" \
https://pkc-zpjg0.eu-central-1.aws.confluent.cloud:443/kafka/v3/clusters/lkc-vrxdop/topics/myproxytest/records \
-d '{"value":{"type":"JSON","data": { "PrimaryId":1000, "Name":"Ramon Klein" } }}'
# you have to adapt the url if you not generated it via confluent cloud "new client"
# also then you have to encode you api key like this:
# prompt> echo "<apikey>:<apisecret>" | base64 -w0
# you have to store the output of that command after the "Authorization: Basic" part
# if you use that command multiple times its smarter to put the authorzation string into an environment variable e.g.
# prompt> export AUTHBASIC=<base64stuff>
# and then replace line 4 of the example with:
# -H "Authorization: Basic $AUTHBASIC" \
#if want to calculate base64 key diretly with powershell here is how it goes
$apikey="<yourapikey>"
$apisecret="<yourapisecret>"
$Bytes = [System.Text.Encoding]::ASCII.GetBytes($apikey+":"+$apisecret)
$AuthBasic =[Convert]::ToBase64String($Bytes)
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Authorization", "Basic "+$AuthBasic)
#Paste commands from producewithpowershell.ps1 example from 5 line yourself after this line
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Authorization", "Basic <yourbase64encodeapikeyandapisecret>")
$body = @"
{
`"value`": {
`"type`": `"JSON`",
`"data`": {
`"AddressId`": `"10000012`",
`"PostalCode`": `"10117`",
`"Street`": `"Leipziger Platz`",
`"HouseNumber`": `"30`",
`"Country`": `"Germany`"
}
}
}
"@
$response = Invoke-RestMethod 'https://pkc-zpjg0.eu-central-1.aws.confluent.cloud:443/kafka/v3/clusters/lkc-vrxdop/topics/fakeaddress/records' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment