forked from docusign/code-examples-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEg04RetrieveClickwrapsController.cs
71 lines (61 loc) · 2.53 KB
/
Eg04RetrieveClickwrapsController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Text;
using DocuSign.Click.Api;
using DocuSign.Click.Client;
using DocuSign.CodeExamples.Common;
using DocuSign.CodeExamples.Controllers;
using DocuSign.CodeExamples.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace DocuSign.CodeExamples.Click.Controllers
{
[Area("Click")]
[Route("[area]/Eg06")]
public class Eg06RetrieveClickwrapsController : EgController
{
public Eg06RetrieveClickwrapsController
(DSConfiguration dsConfig,
IRequestItemsService requestItemsService)
: base(dsConfig, requestItemsService)
{
}
public override string EgName => "Eg06";
protected override void InitializeInternal()
{
ViewBag.ClickwrapId = RequestItemsService.ClickwrapId;
ViewBag.AccountId = RequestItemsService.Session.AccountId;
}
[MustAuthenticate]
[Route("Retrieve")]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Retrieve()
{
// Step 1. Obtain your OAuth token
var accessToken = RequestItemsService.User.AccessToken;
var basePath = $"{RequestItemsService.Session.BasePath}/clickapi"; // Base API path
// Step 2: Construct your API headers
var apiClient = new ApiClient(basePath);
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
var clickAccountApi = new AccountsApi(apiClient);
var accountId = RequestItemsService.Session.AccountId;
try
{
// Step 3: Call the Click API to get the clickwraps
var clickwraps = clickAccountApi.GetClickwraps(accountId);
var messageBuilder = new StringBuilder();
clickwraps.Clickwraps.ForEach(cw => messageBuilder.AppendLine($"Clickwrap ID:{cw.ClickwrapId}, Clickwrap Version: {cw.VersionNumber}"));
//Show results
ViewBag.h1 = "Clickwraps were successfully retreived";
ViewBag.message = $"The clickwraps retrieved: {messageBuilder.ToString()}.";
ViewBag.Locals.Json = JsonConvert.SerializeObject(clickwraps.Clickwraps, Formatting.Indented);
return View("example_done");
}
catch (ApiException apiException)
{
ViewBag.errorCode = apiException.ErrorCode;
ViewBag.errorMessage = apiException.Message;
return View("Error");
}
}
}
}