I have been using the C# authentication examples on github:
This has worked fine, I can create an account, and used the code to create a wallet. When I use the C# authentication example code to create a transaction I get:
{StatusCode: 400, ReasonPhrase: ‘Bad Request’, Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Wed, 05 Jun 2024 14:34:02 GMT
Connection: keep-alive
X-Powered-By: Express
X-Request-ID: 999a84ba161a0ec49b942364d8a3701a
ETag: W/“83-hxj/FEidCiaj062wnON16m9/2pQ”
Strict-Transport-Security: max-age=15724800; includeSubDomains
CF-Cache-Status: DYNAMIC
Server: cloudflare
CF-RAY: 88f0e18e5a857ce8-EWR
Content-Type: application/json; charset=utf-8
Content-Length: 131
}}
The code:
static async Task CreateTransaction(string apiKey, string privateKey, string baseUrl)
{
string path = “/v1/transactions”;
ApiTokenProvider provider = new ApiTokenProvider(privateKey, apiKey);
FBTansaction fbTransaction = new FBTansaction();
fbTransaction.operation = "TRANSFER";
fbTransaction.assetId = "ETH_TEST5";
fbTransaction.amount = "0.001";
Source source = new Source();
source.id = "6";
source.type = "VAULT_ACCOUNT";
fbTransaction.source = source;
Destination destination = new Destination();
destination.id = "11";
destination.type = "VAULT_ACCOUNT";
fbTransaction.destination = destination;
string token = provider.SignJwt(path, JsonConvert.SerializeObject(fbTransaction));
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Add("X-API-Key", apiKey);
string jsonBody = JsonConvert.SerializeObject(fbTransaction);
HttpContent content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(baseUrl + path, content);
if (response.IsSuccessStatusCode)
{
var json = response.Content.ReadAsStringAsync();
string jsonString = json.Result.ToString();
return await response.Content.ReadAsStringAsync();
}
else
{
return "POST Request failed with status: " + response.StatusCode;
}
}
}
The json body that is sent from the above code:
“{
"operation":"TRANSFER",
"note":null,
"assetId":"ETH_TEST5",
"source":{
"type":"VAULT_ACCOUNT",
"id":"6",
"name":"TestFromAPI"},
"destination":{
"type":"VAULT_ACCOUNT",
"id":"11",
"name":"VaultTest1"},
"amount":"0.001"
}”
This works using postman and the above json body converts to C# classes fine using json2sharp.com. So cannot see what the problem is, when creating accounts and wallets using the example C# code works fine, but creating a transaction?
Any help would be great.
Regards
Danny