REST API knowledge exchange
			
		
		
			
				
																			
								dannordquist 							 
						Enthusiast 			
		Posts:  27Liked:  2 times Joined:  Oct 23, 2014 3:39 pmFull Name:  Dan Nordquist
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by dannordquist  Oct 23, 2014 3:49 pm 
				
			
			
			
			I've tried many variations of code but this is the gist:
Code: Select all 
HttpWebRequest httpWReq = (HttpWebRequest)HttpWebRequest.Create("http://mysite:9399/api/sessionMngr/");
                httpWReq.Method = "POST";
                ASCIIEncoding encode = new ASCIIEncoding();
                string _auth = string.Format("{0}:{1}", "user", "pass");
                string _enc = Convert.ToBase64String(encode.GetBytes(_auth));
                string _cred = string.Format("{0} {1}", "Basic", _enc);
                byte[] data = encode.GetBytes(_cred);
                httpWReq.ContentLength = _cred.Length;
                httpWReq.Headers[HttpRequestHeader.Authorization] = _cred;
                
                string responseString = new StreamReader(httpWReq.GetResponse().GetResponseStream()).ReadToEnd();
                Console.WriteLine(responseString);
I get a 500 error from the server.
Any ideas?
Thanks!
 
		 
				
		
		 
	 
				
		
		
			
				
																			
								dannordquist 							 
						Enthusiast 			
		Posts:  27Liked:  2 times Joined:  Oct 23, 2014 3:39 pmFull Name:  Dan Nordquist
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by dannordquist  Oct 23, 2014 4:21 pm 
				
			
			
			
			I've replied to several posts with related comments and they are getting deleted.
			
			
									
						
										
						 
		 
				
		
		 
	 
				
		
		
			
				
																			
								dannordquist 							 
						Enthusiast 			
		Posts:  27Liked:  2 times Joined:  Oct 23, 2014 3:39 pmFull Name:  Dan Nordquist
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by dannordquist  Oct 23, 2014 4:33 pm 
				
			
			
			
			Here's the header text being sent to the server, which is exactly the correct format specified in the documentation:
			
			
									
						
										
						 
		 
				
		
		 
	 
				
		
		
			
				
																			
								veremin 							 
						Product Manager 			
		Posts:  20736Liked:  2403 times Joined:  Oct 26, 2012 3:28 pmFull Name:  Vladimir Eremin
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by veremin  Oct 23, 2014 4:33 pm 
				
			
			
			
			Your post were deleted, because they were the same. Meanwhile, your original topic has been preserved. Please, don't overfill multiple topics with the same issue, and keep posting in this thread. 
			
			
									
						
										
						 
		 
				
		
		 
	 
				
		
		
			
				
																			
								dannordquist 							 
						Enthusiast 			
		Posts:  27Liked:  2 times Joined:  Oct 23, 2014 3:39 pmFull Name:  Dan Nordquist
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by dannordquist  Oct 23, 2014 4:35 pm 
				
			
			
			
			I posted on several threads because people will get notification of the post, and if they found an answer it might prompt them to post it.
			
			
									
						
										
						 
		 
				
		
		 
	 
				
		
		
			
				
																			
								poulpreben 							 
						Certified Trainer 			
		Posts:  1028Liked:  448 times Joined:  Jul 23, 2012 8:16 amFull Name:  Preben Berg
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by poulpreben  Oct 24, 2014 2:22 pm 
				
			
			
			
			Hi Dan,
You probably want to have a look at this thread over at StackOverflow: 
C# webrequest authentication 
I would love to try, but I never did much C# programming, so please post your findings in this thread!
Thanks,
Preben
 
		 
				
		
		 
	 
				
		
		
			
				
																			
								dannordquist 							 
						Enthusiast 			
		Posts:  27Liked:  2 times Joined:  Oct 23, 2014 3:39 pmFull Name:  Dan Nordquist
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by dannordquist  Oct 24, 2014 2:31 pm 
				
			
			
			
			Thanks poulpreben.  I've found that there's nothing wrong with my code, however.  It works just fine, but the server returns a 500 error because we don't have the Enterprise Plus license.  It doesn't indicate anything about licensing or why it got the 500 error, so it was difficult to find that it was just a licensing issue (wasted two days thinking it was a code issue).
			
			
									
						
										
						 
		 
				
		
		 
	 
				
		
		
			
				
																			
								veremin 							 
						Product Manager 			
		Posts:  20736Liked:  2403 times Joined:  Oct 26, 2012 3:28 pmFull Name:  Vladimir Eremin
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by veremin  Oct 24, 2014 2:36 pm 
				
			
			
			
			What about using PowerShell, instead of parsing DB? Not only will be more convenient, from my perspective, but also it will not be read-only stuff, as changes are totally possible via PS. Thanks.
			
			
									
						
										
						 
		 
				
		
		 
	 
				
		
		
			
				
																			
								dannordquist 							 
						Enthusiast 			
		Posts:  27Liked:  2 times Joined:  Oct 23, 2014 3:39 pmFull Name:  Dan Nordquist
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by dannordquist  Oct 24, 2014 2:42 pm 
				
			
			
			
			Thank you v.Eremin.  Would you mind posting some example PS code to get me started on the right path?  Just login and reading data (current jobs with failure/warnings and job duration would be awesome) will get me started and then I hope to find information on adding commands and/or changes after proving the functionality.
			
			
									
						
										
						 
		 
				
		
		 
	 
				
		
		
			
				
																			
								veremin 							 
						Product Manager 			
		Posts:  20736Liked:  2403 times Joined:  Oct 26, 2012 3:28 pmFull Name:  Vladimir Eremin
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by veremin  Oct 24, 2014 3:01 pm 
				
			
			
			
			The best idea would be to check both 
PowerShell subforum  and 
our online Help Center. 
As to the script examples, the following ones should be helpful:
Get all jobs that failed during the last run 
Code: Select all 
Asnp VeeamPSSnapin
Get-VBRJob | where {$_.GetLastResult() -eq "Failed"}Select all jobs along with the start and end time of their latest sessions: 
Code: Select all 
Asnp VeeamPSSnapin
Get-VBRJob | select name, {$_.Findlastsession().creationTime}, {$_.Findlastsession().EndTime}
If you want to continue discussion regarding PS, please, create a separate topic on the said subforum.
Thanks.
 
		 
				
		
		 
	 
				
		
		
			
				
																			
								dannordquist 							 
						Enthusiast 			
		Posts:  27Liked:  2 times Joined:  Oct 23, 2014 3:39 pmFull Name:  Dan Nordquist
				Contact: 
				
			 
				
		 
		
						
					
																		
							
						
									
						Post 
					 
								by dannordquist  Oct 24, 2014 3:29 pm 
				
			
			
			
			Excellent!  thank you!
			
			
									
						
										
						 
		 
				
		
		 
	 
				
		
		
			
				
																			
								veremin 							 
						Product Manager 			
		Posts:  20736Liked:  2403 times Joined:  Oct 26, 2012 3:28 pmFull Name:  Vladimir Eremin
				Contact: 
				
			 
				
		 
		
						
					
																			
						
									
						Post 
					 
								by veremin  Oct 27, 2014 7:17 am 
				
			
			
			
			You're welcome. Should other questions arise, feel free to contact us. Thanks.
			
			
									
						
										
						 
		 
				
		
		 
	 
	
	
	
		
		Users browsing this forum: No registered users and 2 guests