Hi Guys, Hope you are doing good, I am new to rest...
# general
m
Hi Guys, Hope you are doing good, I am new to restlet, i want to know some info, i am using dot net to integrate with restlet, i have below code
HttpClient client = new HttpClient(new WebRequestHandler());
string urlLink = " <https://rest.sandbox.netsuite.com/rest/roles%22;|https://rest.sandbox.netsuite.com/rest/roles";>
var uri = new Uri(urlLink);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("NLAuth", "nlauth_account=XXXXXX,nlauth_email=XXXXXXXX,nlauth_signature=XXXXXX,nlauth_role=3&compid=XXXXXXX");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var response = await client.GetAsync(uri);
var responseString = await response.Content.ReadAsStringAsync();
but i am getting below errori have checked user password compid account id everything , everything is fine {"error" : {"code" : "USER_ERROR", "message" : "You have entered an invalid email address or password. Please try again."}}
m
You are using role 3, which is Administrator. Administrator automatically requires 2-factor authentication, which cannot be provided in a RESTlet header. I recommend you create a custom role for your restlet user that does not require 2FA
n
Well, for me the role is working fine without any issues.
@MUHAMMAD MUBUSHER ASLAM 1.) Your RESTlet URL doesn't looks that good. Also, Please replace the ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; with ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
2.) &compid=XXXXX needs to be removed from Authorization header
The compid will be actually going into nlauth_account which will be actually your NS account id
Also, you might want to add: ServicePointManager.Expect100Continue = true; before the ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
Just noticed you haven't given NLauth before nlauth_account in the authorization header which again is malformed header
m
Thanks @Nik, how do i do this last point
m
@mattdahse just to nitpick because I found this out a couple days ago - you can actually create tokens for admin role via a link on the home dashboard
✔️ 1
n
Just remove the comma between NLauth and "nlauth_account=XXXXXX so it looks like: client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("NLAuth nlauth_account=XXXXXX,nlauth_email=XXXXXXXX,nlauth_signature=XXXXXX,nlauth_role=3");
@michoel That's the only way I know how to create tokens. Lol, Do you know any other way as well .Just to increase my not so vast knowledge.
m
Setup > Users/Roles > Access Tokens
n
Aha. Thanks @michoel
m
@Nik its still showing same error, i have done all the things you have mentioned above, any clue
n
Pinged a working piece of code in Personal Chat