-
Notifications
You must be signed in to change notification settings - Fork 199
/
CreateProposals.cs
executable file
·114 lines (101 loc) · 4.24 KB
/
CreateProposals.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Google.Api.Ads.AdManager.Lib;
using Google.Api.Ads.AdManager.v202402;
using System;
namespace Google.Api.Ads.AdManager.Examples.CSharp.v202402
{
/// <summary>
/// This example creates a proposal.
/// </summary>
public class CreateProposals : SampleBase
{
/// <summary>
/// Returns a description about the code example.
/// </summary>
public override string Description
{
get
{
return "This example creates a proposal";
}
}
/// <summary>
/// Main method, to run this code example as a standalone application.
/// </summary>
public static void Main()
{
CreateProposals codeExample =
new CreateProposals();
Console.WriteLine(codeExample.Description);
long primarySalespersonId = long.Parse(_T("INSERT_PRIMARY_SALESPERSON_ID_HERE"));
long primaryTraffickerId = long.Parse(_T("INSERT_PRIMARY_TRAFFICKER_ID_HERE"));
// Set the ID of the programmatic buyer. This can be obtained through the
// Programmatic_Buyer PQL table.
long programmaticBuyerId = long.Parse(_T("INSERT_PROGRAMMATIC_BUYER_ID_HERE"));
long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
codeExample.Run(new AdManagerUser(), primarySalespersonId, primaryTraffickerId,
programmaticBuyerId, advertiserId);
}
/// <summary>
/// Run the code example.
/// </summary>
public void Run(AdManagerUser user, long primarySalespersonId, long primaryTraffickerId,
long programmaticBuyerId, long advertiserId)
{
using (ProposalService proposalService = user.GetService<ProposalService>())
{
// Create a proposal with the minimum required fields.
Proposal proposal = new Proposal()
{
name = "Programmatic proposal #" + new Random().Next(int.MaxValue),
// Set required Marketplace information
marketplaceInfo = new ProposalMarketplaceInfo()
{
buyerAccountId = programmaticBuyerId
}
};
// Set fields that are required before sending the proposal to the buyer.
proposal.primaryTraffickerId = primaryTraffickerId;
proposal.sellerContactIds = new long[] { primarySalespersonId };
proposal.primarySalesperson = new SalespersonSplit()
{
userId = primarySalespersonId,
};
proposal.advertiser = new ProposalCompanyAssociation()
{
type = ProposalCompanyAssociationType.ADVERTISER,
companyId = advertiserId
};
try
{
// Create the proposal on the server.
Proposal[] proposals =
proposalService.createProposals(new Proposal[] { proposal });
foreach (Proposal createdProposal in proposals)
{
Console.WriteLine("A programmatic proposal with ID \"{0}\" " +
"and name \"{1}\" was created.",
createdProposal.id, createdProposal.name);
}
}
catch (Exception e)
{
Console.WriteLine("Failed to create proposals. Exception says \"{0}\"",
e.Message);
}
}
}
}
}