No session id found - Yodlee login IAV API - yodlee

I get a "No session id found" response when I invoke login API. I ensured the cobsessiontoken is valid and not empty but Yodlee's service thinks that the field is empty.
HttpPost httpPost2 = new HttpPost(yodleeURL+login);
List<NameValuePair> nvps2 =new ArrayList<NameValuePair>();
System.out.println(yodleeURL+login);
nvps2.add(new BasicNameValuePair("name", "cobSessionToken"));
System.out.println(sessionToken);
nvps2.add(new BasicNameValuePair("value", sessionToken));
nvps2.add(new BasicNameValuePair("name", "login"));
nvps2.add(new BasicNameValuePair("value", "xxxxxxx"));
nvps2.add(new BasicNameValuePair("name", "password"));
nvps2.add(new BasicNameValuePair("value", "xxxxxxx"));
UrlEncodedFormEntity encodedURL = new UrlEncodedFormEntity(nvps2);
httpPost2.setEntity(encodedURL);
CloseableHttpResponse response2 = httpclient.execute(httpPost2);
JsonElement element1 = new JsonParser().parse(EntityUtils.toString(response2.getEntity()));
JsonObject jobject1 = element1.getAsJsonObject();
System.out.println(jobject1.toString());

This response comes when you are not passing 'cobSessionToken' as an input param or passing it incorrectly.
If you are passing then please make sure its casing is also correct as it is case-sensitive.
Though, as per your code it seems like you are passing the param name correctly

Just in case you have not figured it out yet. Please use the code below
HttpPost httpPost2 = new HttpPost(yodleeURL+login);
List<NameValuePair> nvps2 =new ArrayList<NameValuePair>();
System.out.println(yodleeURL+login);
nvps2.add(new BasicNameValuePair("cobSessionToken", sessionToken));
nvps2.add(new BasicNameValuePair("login", "xxxxxxx"));
nvps2.add(new BasicNameValuePair("password", "xxxxxxx"));
UrlEncodedFormEntity encodedURL = new UrlEncodedFormEntity(nvps2);
httpPost2.setEntity(encodedURL);
CloseableHttpResponse response2 = httpclient.execute(httpPost2);
JsonElement element1 = new JsonParser().parse(EntityUtils.toString(response2.getEntity()));
JsonObject jobject1 = element1.getAsJsonObject();
System.out.println(jobject1.toString());

Related

WebClient or WebRequest to get the re-directed URL of the landing page

From the string I parsed from Bing's Pic of the Day, I got the info of the pic to be downloaded, let's say today it is /az/hprichbg/rb/PearlHarborWindows_EN-US8565186567, then we will have full URL of the image be like http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1366x768.jpg
Usually Bing has an image of higher resolutions, so I will download the image 1920x1200 too. It's easy with the URL changed to be like http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1920x1200.jpg, then give the task to a WebClient such as client1.DownloadFile(url, fileName)
The issue here is, some days, the resolution 1920x1200 is not available, and the download URL of this res.(1920x1200) will be re-directed to the URL of the image /sa/simg/hpb/NorthMale_EN-US8782628354_1920x1200.jpg - as default (you can check it).
So my try was a function to get the return/re-directed URL from the input URL:
Public Function GetWebPageURL(ByVal url As String) As String
Dim Request As WebRequest = WebRequest.Create(url)
Request.Credentials = CredentialCache.DefaultCredentials
Return Request.RequestUri.ToString
End Function
and compare to the input URL to see it they are different, but the result was not as expected.
Could anyone let me know the method to check this re-directed URL, like the return URL after we press Enter and wait for the site to load.
Please give me idea to overcome this obstacle. Thank you!
Notes: Some issues related to access rights on different PCs cause me not to use HttpWebRequest, so I prefer the solution not using HttpWebRequest (WebClient or others are better).
With help from #IvanValadares #AlenGenzić, and suggestion of Proxy for HttpWebRequest from #Jimi, I have come to the fair solution, as the below code:
url1 = "http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1920x1200.jpg"
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url1), HttpWebRequest)
myHttpWebRequest.MaximumAutomaticRedirections = 1
myHttpWebRequest.AllowAutoRedirect = True
Dim defaultProxy As IWebProxy = WebRequest.DefaultWebProxy
If (defaultProxy IsNot Nothing) Then
defaultProxy.Credentials = CredentialCache.DefaultCredentials
myHttpWebRequest.Proxy = defaultProxy
End If
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse, HttpWebResponse)
url2 = myHttpWebResponse.ResponseUri.ToString
Label1.Text = url1
Label2.Text = url2
Use AllowAutoRedirect and check the StatusCode.
var webRequest = (HttpWebRequest)System.Net.WebRequest.Create("http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1920x1200.jpg");
webRequest.AllowAutoRedirect = false;
using (var response = (HttpWebResponse)webRequest.GetResponse())
{
if (response.StatusCode == HttpStatusCode.Found)
{
// Have been redirect
}
else if (response.StatusCode == HttpStatusCode.OK)
{
// Have not been redirect
}
}
Using HttpClient
var handler = new HttpClientHandler()
{
AllowAutoRedirect = false
};
HttpClient client = new HttpClient(handler);
HttpResponseMessage response = await client.GetAsync("http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1920x1200.jpg");
if (response.StatusCode == HttpStatusCode.Found)
{
// Have been redirect
}
else if (response.StatusCode == HttpStatusCode.OK)
{
// Have not been redirect
}
With help from #IvanValadares #AlenGenzić, and suggestion of Proxy for HttpWebRequest from #Jimi, I have come to the fair solution as below:
url1 = "http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1920x1200.jpg"
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url1), HttpWebRequest)
myHttpWebRequest.MaximumAutomaticRedirections = 1
myHttpWebRequest.AllowAutoRedirect = True
Dim defaultProxy As IWebProxy = WebRequest.DefaultWebProxy
If (defaultProxy IsNot Nothing) Then
defaultProxy.Credentials = CredentialCache.DefaultCredentials
myHttpWebRequest.Proxy = defaultProxy
End If
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse, HttpWebResponse)
url2 = myHttpWebResponse.ResponseUri.ToString
Label1.Text = url1
Label2.Text = url2
The System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required. is no longer thrown.

c# console application returning no results

This code runs fine in my windows form application using .net framework 4.6.2 but when I go to make it a console application so it can be ran from the task scheduler I get no results. I think I am losing something in translation.
RestClient restClient = new RestClient("https://api.vault.com");
string refreshToken = #"abc";
string encodedClientIdSecret = Base64Encode("AP-123");
string responseStr = "";
string url = "/v1/OAuth";
dynamic jsonObj = "";
RestRequest request = new RestRequest(url, Method.POST);
request.AddHeader("Authorization", encodedClientIdSecret);
request.AddParameter("grant_type", "refresh_token");
request.AddParameter("refresh_token", refreshToken);
IRestResponse response;
restClient.Execute(request);
response = restClient.Execute(request);
Console.WriteLine(response.Content + " || " + encodedClientIdSecret);
Console.ReadKey();
jsonObj = JsonConvert.DeserializeObject(response.Content);
responseStr = jsonObj.access_token;
return responseStr;
It basically tells me the value cannot be null, and when I look at response.Content I get nothing and the status code comes back as "0". Any thoughts?
Just added:
//Required For SSL/TLS Error Start
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//Required For SSL/TLS Error End
and I got my results. Hope this helps someone else!

Zoho Creator API Integration Basic Authorization postUrl()

Here is my code and I am getting Internal Error for postural() call. By the way, one more thing I want to know how we can use verify_peer to 0(zero) for not using SSL things. What is wrong with my code?
void SendSMS(SMS SMSObject)
{
//CONFIGURATION
URL = "https://example.com/send_ack.php";
wbLogin = "wbLogin";
wbPwd = "wbPwd";
wbAccount = "wbAccount";
label = "label";
applicationName = "ADR SMS v1.0";
//BASE64 ENCODING
Base64Encoded = zoho.encryption.base64Encode("httpLogin:httpPwd");
AuthorizationBasic = "Authorization: Basic " + Base64Encoded;
//HEADER
HeaderMap = Map();
HeaderMap.put("content-type", "application/x-www-form-urlencoded");
HeaderMap.put("Authorization", AuthorizationBasic);
//REQUEST
RequestMap = Map();
RequestMap.put("compte", wbAccount);
RequestMap.put("op", 1);
RequestMap.put("type", 0);
RequestMap.put("dt", zoho.currentdate.getDay());
RequestMap.put("hr", zoho.currenttime.getHour());
RequestMap.put("mn", zoho.currenttime.getMinutes());
RequestMap.put("label", label);
RequestMap.put("dest_num", "phone_number");
RequestMap.put("msg", "ZC Testing");
RequestMap.put("ref", "ZC");
//CALL POSTURL
Result = postUrl(URL, RequestMap, HeaderMap, false);
//DEBUG
info Result;
}
Use Zoho Creator API for this purpose.

How to Add New TestCases to an existing Rally Folder

I tried the below code to create test cases under existing folder. I'm able to create the testcase but dont see it under the associated folder.
QueryRequest testFolderRequest = new QueryRequest("TestFolder");
testFolderRequest .setFetch(new Fetch("FormattedID", "Name"));
QueryResponse testFolderQueryResponse = restApi.query(testsetRequest);
// JsonObject testSetJsonObject =
// testSetQueryResponse.getResults().get(0).getAsJsonObject();
String testFolderReference = testFolderQueryResponse.getResults().get(0)
.getAsJsonObject().get("_ref").toString();
// System.out.println("TestFolder object: "+testSetRef);
JsonObject newTestCase = new JsonObject();
newTestCase.addProperty("Name", "Newly added testcase in a folder");
newTestCase.addProperty("Test Folder", testFolderReference);
CreateRequest createRequest = new CreateRequest("testcase", newTestCase);
CreateResponse response = restApi.create(createRequest);
System.out.println(response.toString());
JsonObject json = response.getObject();
System.out.println(json);
Attributes in webservices API shouldn't have spaces. So:
newTestCase.addProperty("TestFolder", testFolderReference);
Should work.

How to add a new Test Case and associate it with User Story that already exists in Rally

I have used the following code to Add a new Test Case and associate to an existing UserStory in Rally. It creates the new test case but does not associate with the existing User Story US4.Am I missing any references.Any Help would be highly appreciated
String storyFormattedID = "US4";
QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
storyRequest.setFetch(new Fetch("FormattedID", "Name", "Changesets"));
storyRequest.setQueryFilter(new QueryFilter("FormattedID", "=",
storyFormattedID));
QueryResponse storyQueryResponse = restApi.query(storyRequest);
JsonObject storyJsonObject = storyQueryResponse.getResults().get(0)
.getAsJsonObject();
String storyRef = storyJsonObject.get("_ref").toString();
JsonObject newTestCase = new JsonObject();
newTestCase.addProperty("Name", "Test Case");
newTestCase.addProperty("Requirement", storyRef);
newTestCase.addProperty("Name",
"Newly added testcase associated to a Story");
CreateRequest createRequest = new CreateRequest("testcase", newTestCase);
CreateResponse response = restApi.create(createRequest);
System.out.println(response.toString());
JsonObject json = response.getObject();
System.out.println(json);
The correct attribute to associate a TestCase to a HierarchicalRequirement is WorkProduct, since TestCases can associate either to HierarchicalRequirement or Defect. So:
newTestCase.addProperty("WorkProduct", storyRef);
Should do the trick for you.