I am working on sending data to Spiff (https://app.getguru.com/card/iXpEBagT/How-to-send-data-to-Spiffs-API) but I'm having trouble getting the headers they want added. From the linked site here is their example:
curl -X PUT -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Signature: t=1606767397,v1=DIGEST' -d '{"Id":"Thor","nickname":"Strongest Avenger"}' https://app.spiff.com/_webhook/mapping/123
So using VB.Net (Core 6) I'm attempting to do this with a HttpClient but keep getting a Status Code 400: Bad Response. Here is my sample code:
Public Async Function SendRequest(uri As Uri, data As String, signature As String) As Task(Of JsonObject)
Dim httpClient = New HttpClient()
httpClient.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Signature", signature)
Dim content = New StringContent(data, Encoding.UTF8, "application/json")
Dim response = New HttpResponseMessage
response = Await httpClient.PutAsync(uri, content)
response.EnsureSuccessStatusCode()
End Function
I'm guessing the BadRequest is due to the extra Signature header but I can't figure out what I'm doing wrong. I'm using the default request headers since the program executes, sends the data, then ends so I have no need to keep the httpclient around or reuse it. I tried using a WebRequest but on top of being depreciated I had the same issues. I thought maybe I'm messing up the signature as they use HMAC verification but I'm pretty sure that is correct also based on their documentation:
Private Sub SendDataButton_Click(sender As Object, e As EventArgs) Handles SendDataButton.Click
Dim myKey As String = HMACKeyTextBox.Text
Dim myUnixTime As Long = New DateTimeOffset(Date.Now.ToUniversalTime).ToUnixTimeSeconds
Dim myData as String = "{""PrimaryKey"":""2""}"
Dim myPreDigestString = $"{myUnixTime}.{myData}"
Dim myDigest As String = GetHMACSHA256Hash(myPreDigestString, myKey)
Dim myURI As New Uri(URITextBox.Text)
Dim mySignature As String = $"t={myUnixTime},v1={myDigest}"
Dim result_post = SendRequest(myURI, myData, mySignature)
End Sub
Which is based on some other posts on here. Am I adding the headers wrong or does this look correct? The test data is what they are expecting from me for testing, a single record setting a PrimaryKey. I should be getting back a 200 OK.