· 9 years ago · Aug 11, 2017, 07:12 PM
1{
2"id": 8452,
3"creator_user_id": {
4"id": 46342,
5"name": "ADM. Suporte Comercial",
6"email": "*******@gmail.com",
7"has_pic": true,
8"pic_hash": "296e6514a7d0bf854fdcf22e60a19c9f",
9"active_flag": false,
10"value": 46342
11},
12"user_id": {
13"id": 1875524,
14"name": "09. Natália Grosso",
15"email": "*******@gmail.com",
16"has_pic": true,
17"pic_hash": "e4f326a72bc341c84e7608993435c509",
18"active_flag": true,
19"value": 1875524
20},
21"person_id": {
22"name": "Eng. Simone Biolo",
23"email": [
24{
25"label": "work",
26"value": "*******@gmail.com",
27"primary": true
28}
29],
30"phone": [
31{
32"label": "work",
33"value": "***********",
34"primary": true
35}
36],
37"value": 10044
38},
39"org_id": null,
40"stage_id": 45,
41"title": "161366 - Lavatório Cirúrgico (cópia)",
42"value": 25980,
43"currency": "BRL",
44"add_time": "2017-05-29 12:12:54",
45"update_time": "2017-08-02 17:38:47",
46"stage_change_time": "2017-07-24 11:52:56",
47"active": true,
48"deleted": false,
49"status": "open",
50"next_activity_date": "2017-08-16",
51"next_activity_time": null,
52"next_activity_id": 42869,
53"last_activity_id": null,
54"last_activity_date": null,
55"lost_reason": null,
56"visible_to": "3",
57"close_time": null,
58"pipeline_id": 6,
59"won_time": null,
60"first_won_time": null,
61"lost_time": null,
62"products_count": 0,
63"files_count": 0,
64"notes_count": 0,
65"followers_count": 1,
66"email_messages_count": 0,
67"activities_count": 1,
68"done_activities_count": 0,
69"undone_activities_count": 1,
70"reference_activities_count": 0,
71"participants_count": 1,
72"ac0ad7297e4688aec9d739f3bcc123d0e783b615": "53,25",
73"4c67dc6df0ef9892524aae24f65c28dc11d3b765": "41",
74"last_incoming_mail_time": null,
75"last_outgoing_mail_time": null,
76"stage_order_nr": 4,
77"person_name": "Eng. Simone Biolo",
78"org_name": null,
79"next_activity_subject": "Instalação",
80"next_activity_type": "call",
81"next_activity_duration": null,
82"next_activity_note": "Previsão de instalação em 15/08",
83"formatted_value": "R$****",
84"rotten_time": null,
85"weighted_value": 0,
86"formatted_weighted_value": "R$0",
87"owner_name": "09. Natália Grosso",
88"cc_email": "******@pipedrivemail.com",
89"org_hidden": false,
90"person_hidden": false
91}
92
93public class Projetos
94{
95 [Key]
96 public int id { get; set; }
97 public Creator_User_Id creator_user_id { get; set; }
98 public User_Id user_id { get; set; }
99 public Person_Id person_id { get; set; }
100 public object org_id { get; set; }
101 public int stage_id { get; set; }
102 public string title { get; set; }
103 public int value { get; set; }
104 public string currency { get; set; }
105 public string add_time { get; set; }
106 public string update_time { get; set; }
107 public string stage_change_time { get; set; }
108 public bool active { get; set; }
109 public bool deleted { get; set; }
110 public string status { get; set; }
111 public string next_activity_date { get; set; }
112 public object next_activity_time { get; set; }
113 public int next_activity_id { get; set; }
114 public object last_activity_id { get; set; }
115 public object last_activity_date { get; set; }
116 public object lost_reason { get; set; }
117 public string visible_to { get; set; }
118 public object close_time { get; set; }
119 public int pipeline_id { get; set; }
120 public object won_time { get; set; }
121 public object first_won_time { get; set; }
122 public object lost_time { get; set; }
123 public int products_count { get; set; }
124 public int files_count { get; set; }
125 public int notes_count { get; set; }
126 public int followers_count { get; set; }
127 public int email_messages_count { get; set; }
128 public int activities_count { get; set; }
129 public int done_activities_count { get; set; }
130 public int undone_activities_count { get; set; }
131 public int reference_activities_count { get; set; }
132 public int participants_count { get; set; }
133 public object ac0ad7297e4688aec9d739f3bcc123d0e783b615 { get; set; }
134 public string _4c67dc6df0ef9892524aae24f65c28dc11d3b765 { get; set; }
135 public object last_incoming_mail_time { get; set; }
136 public object last_outgoing_mail_time { get; set; }
137 public int stage_order_nr { get; set; }
138 public string person_name { get; set; }
139 public object org_name { get; set; }
140 public string next_activity_subject { get; set; }
141 public string next_activity_type { get; set; }
142 public object next_activity_duration { get; set; }
143 public string next_activity_note { get; set; }
144 public string formatted_value { get; set; }
145 public object rotten_time { get; set; }
146 public int weighted_value { get; set; }
147 public string formatted_weighted_value { get; set; }
148 public string owner_name { get; set; }
149 public string cc_email { get; set; }
150 public bool org_hidden { get; set; }
151 public bool person_hidden { get; set; }
152}
153
154public class Creator_User_Id
155{
156 public int id { get; set; }
157 public string name { get; set; }
158 public string email { get; set; }
159 public bool has_pic { get; set; }
160 public string pic_hash { get; set; }
161 public bool active_flag { get; set; }
162 public int value { get; set; }
163}
164
165public class User_Id
166{
167 public int id { get; set; }
168 public string name { get; set; }
169 public string email { get; set; }
170 public bool has_pic { get; set; }
171 public string pic_hash { get; set; }
172 public bool active_flag { get; set; }
173 public int value { get; set; }
174}
175
176public class Person_Id
177{
178 public string name { get; set; }
179 public Email[] email { get; set; }
180 public Phone[] phone { get; set; }
181 public int value { get; set; }
182}
183
184public class Email
185{
186 public string label { get; set; }
187 public string value { get; set; }
188 public bool primary { get; set; }
189}
190
191public class Phone
192{
193 public string label { get; set; }
194 public string value { get; set; }
195 public bool primary { get; set; }
196}
197
198public class ProjetosController : Controller
199{
200 private static HttpClient httpClient;
201
202 static ProjetosController()
203 {
204 httpClient = new HttpClient();
205 httpClient.BaseAddress = new Uri("https://*****.pipedrive.com/v1/");
206 httpClient.DefaultRequestHeaders.Accept.Clear();
207 httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
208 //Se precisar adicionar alguma autenticação, faça o aqui.
209 }
210
211 [HttpGet]
212 public async Task<ActionResult> Index()
213 {
214 var queryString = $"deals?stage_id=45&status=open&start=0&api_token=************************22f3a2c";
215 var response = await httpClient.GetAsync(queryString);
216 if (response.IsSuccessStatusCode)
217 {
218 var json = await response.Content.ReadAsStringAsync();
219 var model = Newtonsoft.Json.JsonConvert.DeserializeObject<Projetos>(json);
220 return Json(model, JsonRequestBehavior.AllowGet);
221 }
222 return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Erro ao acessar a API.");
223 }
224}