Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using Newtonsoft.Json;
- namespace ConsoleApplication1
- {
- internal class Program
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Started.");
- httpClient.BaseAddress = new Uri($"https://fotoware--FluidoDev.my.salesforce.com");
- var url = string.Format(UsernamePasswordUrlTemplate, ClientId, ClientSecret,
- WebUtility.UrlEncode("sarabjeet.pal@fotoware.com.fluidodev"), WebUtility.UrlEncode("Denmark!456"));
- Console.Write("Authentication with login sarabjeet.pal@fotoware.com.fluidodev and password Denmark!456... ");
- var response = httpClient.PostAsync(url, null).Result;
- var responseMessage = response.Content.ReadAsStringAsync().Result;
- if (!response.IsSuccessStatusCode)
- throw new InvalidOperationException($"Occured exception: {responseMessage}");
- Console.WriteLine("ok");
- var authenticationData = JsonConvert.DeserializeObject<OAuthResponse>(responseMessage);
- httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authenticationData.AccessToken);
- Console.Write("/DupeChecker?email=john.smith@example.com ...");
- var dupCheckerResult = httpClient.GetAsync(
- "services/apexrest/FotowareSubscriptionServices/DupeChecker?email=john.smith@example.com").Result;
- if (dupCheckerResult.IsSuccessStatusCode)
- Console.WriteLine("ok! 200");
- else
- Console.WriteLine("not ok, status code " + dupCheckerResult.StatusCode);
- Console.Write("/Trial ...");
- var trialResult = httpClient.PostAsync(
- "services/apexrest/FotowareSubscriptionServices/Trial", new StringContent(JsonConvert.SerializeObject(new
- {
- Title = "",
- Telephone = "+47 00 00 00 00",
- Salutation = "Mr",
- FirstName = "John",
- LastName = "Smith",
- Industry = "Art",
- HostName = "hostname1.fotoware.com",
- EmailAddress = "john.smith1@example.com",
- Company = "Art Company Ltd."
- }))).Result;
- if (trialResult.IsSuccessStatusCode)
- Console.WriteLine("ok! 200");
- else
- {
- Console.WriteLine("not ok, status code " + dupCheckerResult.StatusCode);
- Console.WriteLine("Problem: \r\n" + trialResult.Content.ReadAsStringAsync().Result);
- }
- Console.Write("/Accounts ...");
- var accountsResult = httpClient.GetAsync(
- "services/apexrest/FotowareSubscriptionServices/Accounts").Result;
- if (accountsResult.IsSuccessStatusCode)
- Console.WriteLine("ok! 200");
- else
- {
- Console.WriteLine("not ok, status code " + dupCheckerResult.StatusCode);
- Console.WriteLine("Problem: \r\n" + trialResult.Content.ReadAsStringAsync().Result);
- }
- Console.WriteLine("Press any key");
- Console.ReadKey();
- }
- private const string ClientId =
- "3MVG9GXbtnGKjXe5.8qcOjMRKshBAKPonkV2bADoV.V_a..eEWOdH233sXA5FqejgN2ufaILk0vBSUSWiL8k1";
- private const string ClientSecret = "5217114035680202467";
- private const string UsernamePasswordUrlTemplate = "services/oauth2/token?grant_type=password&client_id={0}&client_secret={1}&username={2}&password={3}";
- private static readonly HttpClient httpClient = new HttpClient();
- }
- public class OAuthResponse
- {
- /// <summary>
- /// Access token.
- /// </summary>
- [JsonProperty("access_token")]
- public string AccessToken { get; set; }
- /// <summary>
- /// Bound instance url.
- /// </summary>
- [JsonProperty("instance_url")]
- public string InstanceUrl { get; set; }
- /// <summary>
- /// Token id.
- /// </summary>
- [JsonProperty("id")]
- public string Id { get; set; }
- /// <summary>
- /// Token type, should be "Bearer"
- /// </summary>
- [JsonProperty("token_type")]
- public string TokenType { get; set; }
- /// <summary>
- /// ?
- /// </summary>
- [JsonProperty("issued_at")]
- public string IssuedAt { get; set; }
- /// <summary>
- /// ?
- /// </summary>
- [JsonProperty("signature")]
- public string Signature { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement