New here, have read similar posts on the forum but still unclear how to proceed. I get an An Invalid API Key response when I try the following:
Endpoint
private string LIVE = "https://api.coinbase.com";
I created an API Key in my Coinbase account however it did not ask for a passphrase, so I guess I should remove sending that header?
And this invokes the endpoint for getting account info. Just starting with /account REST call to get things working… However, I’ve seen responses in the forum saying I should use the above endpoint base URL but the docs here (API Docs - https://docs.cloud.coinbase.com/exchange/reference), say I should use
https://api.exchange.coinbase.com/accounts
When I change the URL to include the “exchange” hostname in the path, I get a “Not found” response… Also, where in the world is my account ID listed in the CB website / portal? I had copied it months ago into my test code but now I’m getting back to doing more testing / learning with CB API and wanted to make sure I had my account ID correct. However, I looked everywhere and could not find it.
Not sure how to proceed. I’m not trying to use new(er) version of Pro / Advanced API, just the basic Exchange API. Here’s the connection code in C#
Thanks, here I’m creating the signature. I have IP restriction on my Key but I’m connecting from the correct IP. That’s only other thing I know to list here to figure out the issues.
I’m not decoding base64 on my access secret but am encoding the signature result before I attach to the REST header.
public static string Generate(string timestamp, string method, string requestPath, string body, string appSecret)
{
return Sign(appSecret, timestamp + method + requestPath + body);
}
internal static string Sign(string key, string data)
{
var hmacKey = Encoding.UTF8.GetBytes(key);
var dataBytes = Encoding.UTF8.GetBytes(data);
using (var hmac = new HMACSHA256(hmacKey))
{
var sig = hmac.ComputeHash(dataBytes);
return Convert.ToBase64String(sig);
}
}
From the original code above I posted, here’s how I use the API Key and the signature:
using (var request = new HttpRequestMessage(HttpMethod.Get, url))
{
request.Headers.Add(HeaderNames.AccessKey,ModelConfig.Key);
request.Headers.Add(HeaderNames.AccessSign,sign);
request.Headers.Add(HeaderNames.AccessTimestamp,timestamp);
Anyway, I’m still getting “Unauthorized” in my responses.
Are you sure that new key was enabled? There might be 48h wait time…
Otherwise provide all data - api key, api secret (that is no longer valid!), timestamp, method, path and signature you are generating with these data. I will use your provided data and check what signature is generated by my code. That way you will know if your code generates correct signature or not.
EDIT: key is not needed as it is not used in signature generation!