-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathDescribeOpportunity.cs
More file actions
65 lines (59 loc) · 2.45 KB
/
Copy pathDescribeOpportunity.cs
File metadata and controls
65 lines (59 loc) · 2.45 KB
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
/*
DescribeOpportunity.cs
Marketo REST API Sample Code
Copyright (C) 2016 Marketo, Inc.
This software may be modified and distributed under the terms
of the MIT license. See the LICENSE file for details.
*/
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace Samples
{
class DescribeOpportunity
{
private String host = "CHANGE ME"; //host of your marketo instance, https://AAA-BBB-CCC.mktorest.com
private String clientId = "CHANGE ME"; //clientId from admin > Launchpoint
private String clientSecret = "CHANGE ME"; //clientSecret from admin > Launchpoint
/*
public static void Main(string[] args)
{
var describe = new DescribeOpportunity();
String result = describe.getData();
Console.Write(result);
}
*/
public String getData()
{
var qs = HttpUtility.ParseQueryString(string.Empty);
qs.Add("access_token", getToken());
String url = host + "/rest/v1/opportunities/describe.json?" + qs.ToString();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/json";
request.Accept = "application/json";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
return reader.ReadToEnd();
}
private String getToken()
{
String url = host + "/identity/oauth/token?grant_type=client_credentials&client_id=" + clientId + "&client_secret=" + clientSecret;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/json";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
String json = reader.ReadToEnd();
//Dictionary<String, Object> dict = JavaScriptSerializer.DeserializeObject(reader.ReadToEnd);
Dictionary<String, String> dict = JsonConvert.DeserializeObject<Dictionary<String, String>>(json);
return dict["access_token"];
}
}
}