Getting parameter_rejected error in quickbook online integration - c#

I have done this code:
static void Main (string[] args)
{
Console.WriteLine("Authenticating..");
string consumerkey = "L0ORES0pf0uEody1YDI3sTkTpyBGaDVVnVRBb1krprkrghPWLQ";
string consumerSecret = "NAONcYrwGgpkFCJN2BgXZHjG8YLqn1JWMEPDXIMg";
string REQUEST_TOKEN_URL = "https://oauth.intuit.com/oauth/v1/get_request_token";
string ACCESS_TOKEN_URL = "https://oauth.intuit.com/oauth/v1/get_access_token";
string OauthLink = "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl";
var consumerContext = new OAuthConsumerContext
{
ConsumerKey = consumerkey,
ConsumerSecret = consumerSecret,
SignatureMethod = SignatureMethod.HmacSha1
};
IOAuthSession AuthSession = new OAuthSession(consumerContext,REQUEST_TOKEN_URL, OauthLink, ACCESS_TOKEN_URL);
IToken requestToken = AuthSession.GetRequestToken();
}
And I am getting error : An unhandled exception of type 'DevDefined.OAuth.Framework.OAuthException' occurred in DevDefined.OAuth.dll Additional information: parameter_rejected
I have attached screenshot of my error.
What is quickbook online Request token URL and Access token URL for OAuth 2.0?

Oauth2.0 //Refresh and Get New Access Token through WebClient and build ServiceContext for CRUD operations
Access Token will expire in every 60 minutes
string URI = "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer";
string myParameters = "grant_type=refresh_token&refresh_token=L0115-----------------------------------"; // Put Refresh Token
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.Headers[HttpRequestHeader.Accept] = "application/json";
wc.Headers[HttpRequestHeader.Authorization] = "Basic UT------------------------------hcW5SV---------------------Qg=="; // Add Auth Token
string HtmlResult = wc.UploadString(URI, myParameters);
wc.Dispose();
var jobject = JsonConvert.DeserializeObject<Test>(HtmlResult);
string accessToken = jobject.access_token;
string relmid = "123412341234123421341234"; // Relmid
OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(accessToken);
ServiceContext serviceContext = new ServiceContext(relmid, IntuitServicesType.QBO, oauthValidator);
serviceContext.IppConfiguration.BaseUrl.Qbo = "https://sandbox-quickbooks.api.intuit.com/";
//serviceContext.IppConfiguration.BaseUrl.Qbo = "https://quickbooks.api.intuit.com/";//prod
serviceContext.IppConfiguration.MinorVersion.Qbo = "23";
CustomerCRUD.CustomerAddTestUsingoAuth(serviceContext);
CustomerCRUD.CustomerFindAllTestUsingoAuth(serviceContext);

Related

MCAS REST API Limit issues(nextQueryFilters)

I am trying to collect Microsoft Defender for Cloud Activity Log using C#.
If you look at the Python example, the value of the nextQueryFilters item should be entered as a filter.
But when I run it in C# and check the test result, the items in nextQueryFilters themselves are not retrieved.
Please check if there is a problem with my code.
string tenantId = "mytenantId";
string appId = "myappId";
string appSecret = "myappSecret";
const string authority = "https://login.microsoftonline.com";
const string MCASResourceId = "myMCASResourceId";
AuthenticationContext auth = new AuthenticationContext($"{authority}/{tenantId}/");
ClientCredential clientCredential = new ClientCredential(appId, appSecret);
AuthenticationResult authenticationResult = auth.AcquireTokenAsync(MCASResourceId, clientCredential).GetAwaiter().GetResult();
string token = authenticationResult.AccessToken;
var httpClient = new HttpClient();
bool hasNextPage = false;
do
{
Url = "https://url.portal.cloudappsecurity.com/api/v1/activities/?filters={\"date\":{ \"gte_ndays\":1}}&isScan:True";
using (var request = new HttpRequestMessage(HttpMethod.Post, Url))
{
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
using (HttpResponseMessage respose = httpClient.SendAsync(request).GetAwaiter().GetResult())
{
string json = respose.Content.ReadAsStringAsync().Result;
}
}
} while (hasNextPage);

[Azure DataCatalog]: Read the data from Azure data catalog glossary Unauthorized error?

I was try to post the excel data in azure data catalog. i was written in console Application.
my code is
static void Main()
{
string DefaultCatalog = "DefaultCatalog";
string DefaultGlossary = "DefaultGlossary";
string fullUri = string.Format("https://api.azuredatacatalog.com/catalogs/{0}/glossaries/{1}/terms?api-version=2016-03-30",
DefaultCatalog, DefaultGlossary);
HttpWebRequest request = WebRequest.Create(fullUri) as HttpWebRequest;
request.KeepAlive = true;
request.Method = "GET";
request.Accept = "application/json;adc.metadata=full";
request.Headers.Add("Authorization", AccessToken().Result.CreateAuthorizationHeader());
request.AllowAutoRedirect = false;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
if (response != null && response.StatusCode == HttpStatusCode.Redirect)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
var itemPayload = reader.ReadToEnd();
JToken terms;
JObject.Parse(itemPayload).TryGetValue("value", out terms);
if (terms != null)
{
var r = JsonConvert.DeserializeObject<JArray>(terms.ToString());
}
}
}
}
static async Task<AuthenticationResult> AccessToken()
{
string clientId = "MyClientId";
string client_secret = "MyClientSecret";
string tenentId = "MytenentId";
if (_authResult == null)
{
// Resource Uri for Data Catalog API
string resourceUri = "https://api.azuredatacatalog.com/";
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
string authorityUri = "https://login.windows.net/MytenentId/oauth2/authorize";
AuthenticationContext authContext = new AuthenticationContext(authorityUri);
_authResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Always));
//ClientCredential cc = new ClientCredential(clientId, client_secret);
//_authResult = await authContext.AcquireTokenAsync(resourceUri, cc);
}
return _authResult;
}
I want to get the list of glossary from my azure datacatalog. But it always returning Unauthorized error.
"The remote server returned an error: (403) Forbidden."
my error is
You'll need to use to get the correct token:
string authorityUri = "https://login.windows.net/common/oauth2/authorize";
Hope this helps,
Monica
make sure you are in the list of glossary admins.
Also ADC has great code samples in github which does what you want to do, check it out:
https://github.com/Azure-Samples/data-catalog-bulk-import-glossary
The Data Catalog contains only delegate permission.
But, I tried using Application permission. So, It throws Unauthorized after I changed it into user login based (Delegated Permission).
Now it's fixed.
Thanks for sharing the answer #Monica and #Max

How to pass body data with UploadStringAsync C#

I'm trying pass a string in the body of my POST request using WebClient class. Below is my code:
protected void GetAccessToken(string client_id, string secret)
{
var urlEncodedSecret = HttpUtility.UrlEncode(secret);
var urlEncodedSid = HttpUtility.UrlEncode(client_id);
string bodyData = String.Format("grant_type=client_credentials&client_id=ms-app%3a%2f%2f{0}&client_secret={1}&scope=notify.windows.com", client_id, secret);
string address = "https://login.live.com/accesstoken.srf";
string myParameters = "param1=value1&param2=value2&param3=value3";
Uri URI = new Uri(address);
System.Net.WebClient webClient = new WebClient();
webClient.BaseAddress = address;
webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
webClient.Headers["Content-Length"] = "211";
webClient.Headers["Host"] = "https://login.live.com";
webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(uploadStringCompleted);
webClient.UploadStringAsync(URI, "POST", bodyData);
}
private void uploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
string json = e.Result.ToString();
_oAuthToken = GetOAuthTokenFromJson(json);
}
When i run the application, i received the exception "The remote server returned an error: NotFound.".
I succeeded to make the same request using the Postman:
Anyone know something wrong about my request? Or something that puting me on a right way!?

HTTP POST is giving unauthorized 401 Exception

When calling the same method on google chrome postman after logging in, i'm getting the json object as shown below.
but when i try to get the same json result in codebehind (C#). I'm getting Unauthorized 401 exception.
I'm using my code like this.
using (var clientSideTab = new WebClient())
{
var valSideTab = new System.Collections.Specialized.NameValueCollection { { "username", UserID }, { "Password", strPassword } };
string UpldDataSideTab = "https://resapistage.namechanged.com/v3/secure/Login.aspx?userId=" + UserID + "&passwd=" + strPassword + " ";
SystemComponentWrapper SPPostWrapper = new SystemComponentWrapper();
SystemComponentData request = new SystemComponentData();
SystemComponentaddressId addressId = new SystemComponentaddressId();
addressId.type = "AddressId";
addressId.id = 19863;
addressId.serial = "";
request.addressId = addressId;
request.compId = null;
request.getCompParams = true;
request.filterForAddress = false;
SPPostWrapper.request = request;
var postJson = JsonConvert.SerializeObject(SPPostWrapper);
Encoding encoding = new UTF8Encoding();
string postData = postJson.ToString();
byte[] bdata = encoding.GetBytes(postData);
string URI = "https://resapistage.namechanged.com/v3/api/secure/json/AddressInfo.svc/getSystemComponentsV2";
clientSideTab.UploadValues(UpldDataSideTab, "POST", valSideTab);
clientSideTab.Headers.Add("Content-Type","application/json; charset=utf-8");
clientSideTab.Headers.Add("Accept","application/json");
clientSideTab.UploadString(URI,"POST", postData);
//clientSideTab.UploadData(URI, "POST", bdata);
String jsonresponse = "failed";
Label1.Text = jsonresponse;
}
I'm getting this error everytime. please help me.
use like this.
string cookie = strCookie[0]; // fetch your cookie after logging in
clientSideTab.Headers.Add("Content-Type","application/json; charset=utf-8");
clientSideTab.Headers.Add("Accept","application/json");
clientSideTab.m_container.SetCookies(URI, cookie);
//clientSideTab.Headers.Add(HttpRequestHeader.Cookie, cookie);
String resultJSON = clientSideTab.UploadString(URI,"POST", jsonData);
this worked for me. hope this will help you.

c# - How to reply for comment in LinkedIn?

I'm trying to integrate LinkedIn in our application. I just want to know how to reply for comment in LinkedIn.
I've written this code.
protected void Page_Load(object sender, EventArgs e)
{
string data = "<comments><comment><text>Check out the Reply!</text></comment></comments>";
byte[] databytes = Encoding.UTF8.GetBytes(data);
var request = new RestRequest { Path = "comments" };
var credentials = new Hammock.Authentication.OAuth.OAuthCredentials
{
Type = OAuthType.AccessToken,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = "kmkzt9cqml1s",
ConsumerSecret = "hNiwIrZWGSMykoD2",
Token = "b3cbdca7-37a7-474f-a9a6-e21bb89917fe",
TokenSecret = "990f1b78-79de-4490-b4e3-893b4e020e45",
};
var client = new RestClient()
{
Authority = "http://api.linkedin.com/v1/posts/g-457832-S-454334",
Credentials = credentials,
Method = WebMethod.Post,
};
client.AddHeader("Content-Type", "text/xml");
client.AddPostContent(databytes);
RestResponse response = client.Request(request);
string content = response.Content;
}
I'm getting an error in content in the below format
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<error>
<status>400</status>
<timestamp>1374494502579</timestamp>
<request-id>QM4MYPEKJJ</request-id>
<error-code>0</error-code>
<message>Couldn't parse message document: error: Unexpected end of file after null</message>\n</error>\n"
Any ideas? Thanks in advance.

Categories

Resources