kan ikke hente konto

Added by glenn over 4 years ago

Jeg sidder og køre denne GET

Dictionary<string, string> restParameters = new Dictionary<string, string>();
restParameters["service"] = "NEXTAPI";
restParameters["auth"] = session_key;
-->> min get request      string resl = SendRequest("GET", "https://api.test.nordnet.se:443/next/2/accounts", restParameters);

den svarer med fejl 404 Not found.

har i et eksempel på en GET funktion som virker imod version 2


Replies (12)

RE: kan ikke hente konto - Added by Nordnet Aleksandar over 4 years ago

Hi,

The 'service' and 'auth' rest parameters should only be sent with the login request.
In the answer from the login request you get a sessionkey which should then be passed with every request instead.

Feel free to take a look at our example codes to see how this should be done.
C# and vb.NET examples have not yet been updated for v2 but the other ones should give you a hint of how to implement it.
Otherwise please contact me on the forum again and I will help you further.

/Aleks

RE: kan ikke hente konto - Added by glenn over 4 years ago

ya did like described in exsamples also . it returns blank no matter what

RE: kan ikke hente konto - Added by glenn over 4 years ago

it just returns a 404

RE: kan ikke hente konto - Added by Nordnet Aleksandar over 4 years ago

Which example did you follow? I recently updated and tested all except for C# and vb.NET

Could you show me how your request looks when you follow the example

RE: kan ikke hente konto - Added by glenn over 4 years ago

Cant find a description who is with C#

this is how i make the request for getting my account number.
got this error

"The remote server returned an error: (406) Not Acceptable."

static string getaccount_numer(string addy, string sessionkeys)
       {
//https://api.test.nordnet.se:443/next/2/accounts
// Create a request for the URL.
WebRequest request = WebRequest.Create("https://api.test.nordnet.se:443/next/2/accounts?sessionkey=" + sessionkeys);
// If required by the server, set the credentials.
// request.Credentials = new NetworkCredential(api_brugernavn, api_password);
//request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Clean up the streams and the response.
reader.Close();
response.Close();
return responseFromServer;
}

RE: kan ikke hente konto - Added by glenn over 4 years ago

sorry changed the http adress now it just syas 404 not found again

WebRequest request = WebRequest.Create("https://api.test.nordnet.se:443/next/2/accounts+" + sessionkeys);

RE: kan ikke hente konto - Added by Nordnet Aleksandar over 4 years ago

I think you have a small typo with the '+', try with a questionmark instead:

WebRequest request = WebRequest.Create("https://api.test.nordnet.se:443/next/2/accounts?" + sessionkeys);

RE: kan ikke hente konto - Added by glenn over 4 years ago

with this

WebRequest request = WebRequest.Create("https://api.test.nordnet.se:443/next/2/accounts?" + sessionkeys);

now it gives me error 406 again. :)

RE: kan ikke hente konto - Added by Nordnet Aleksandar over 4 years ago

It is still more correct than before.

Do you set 'accept: application/json' in your headers, that should resolve the 406.

Does your login request work?

RE: kan ikke hente konto - Added by glenn over 4 years ago

yes i get sessionkey. so it is okey.

it tells me now i am uautorized

this i my complete request now

string a = SendRequest_get("GET", "accounts", "?" + session_key);

private static string SendRequest_get(string method, string requestPath, string sessionkey) {
string retVal = "";
try {
// Should ONLY be used in test where the certificate is not real.
ServicePointManager.ServerCertificateValidationCallback +=
delegate(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors) {
return true;
};

// Create the URL
Uri address = new Uri(BASE_URL + "/" + VERSION + "/" + requestPath + sessionkey); {
System.Console.WriteLine("REST call failed. Message: " + e.Message);
}
return retVal;
}
// Create request
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
request.Accept = "application/json";
request.ContentType = "application/x-www-form-urlencoded";
// Get response  
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) {
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Console application output  
retVal += reader.ReadToEnd();
}
}
catch (System.Net.WebException e)

and my variables is

static string BASE_URL = "https://api.test.nordnet.se/next";
static string VERSION = "2";

// The public key for NEXTAPI from the XML file
static string PUBLIC_KEY =
""
"<RSAParameters xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<Exponent>AQAB</Exponent>" +
"<Modulus>5td/64fAicX2r8sN6RP3mfHf2bcwvTzmHrLcjJbU85gLROL+IXclrjWsluqyt5xtc/TCwM" +
"TfC/NcRVIAvfZdt+OPdDoO0rJYIY3hOGBwLQJeLRfruM8dhVD
/Kpu8yKzKOcRdne2hBb/mpkVtIl5av" +
"JPFZ6AQbICpOC8kEfI1DHrfgT18fBswt85deILBTxVUIXsXdG1ljFAQ/lJd/62J74vayQJq6l2DT663Q" +
"B8nLEILUKEt/hQAJGU3VT4APSfT+5bkClfRb9+kNT7RXT/pNCctbBTKujr3tmkrdUZiQiJZdl/O7LhI9" +
"9nCe6uyJ+la9jNPOuK5z6v72cXenmKZw==</Modulus>" +
"</RSAParameters>";

RE: kan ikke hente konto - Added by glenn over 4 years ago

is it because of my origin. i am from denmark

??

RE: kan ikke hente konto - Added by glenn over 4 years ago

Found the solutin

needed this in my code to complete the get request code

byte[] authBytes = Encoding.UTF8.GetBytes((session_key + ":" + session_key).ToCharArray());
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(authBytes);

(1-12/12)