11using System . Collections . Generic ;
2- using System . Net . Http ;
3- using System . Text ;
4- using System . Threading . Tasks ;
2+ using System . Linq ;
53using Newtonsoft . Json ;
6- using PluginHubspot . API . Factory ;
74using PluginHubspot . API . Utility ;
85
96namespace PluginHubspot . API . Write
107{
118 public static partial class Write
129 {
13- public static string GetSchemaJson ( string [ ] listIds )
10+ public static string GetSchemaJson ( List < string > listIds )
1411 {
12+ // add empty string to the dropdown list
13+ var listIdsInDropdown = ( new string [ ] { "" } ) . Concat ( listIds ) . ToArray ( ) ;
14+
1515 var schemaJsonObj = new Dictionary < string , object >
1616 {
1717 { "type" , "object" } ,
1818 { "properties" , new Dictionary < string , object >
19+ {
20+ { "Endpoint" , new Dictionary < string , object >
21+ {
22+ { "type" , "string" } ,
23+ { "title" , "Endpoint" } ,
24+ { "enum" , new [ ] { Constants . EndpointMemberships } }
25+ } } ,
26+ } } ,
27+ { "required" , new [ ] { "Endpoint" } } ,
28+ { "dependencies" , new Dictionary < string , object >
29+ {
30+ { "Endpoint" , new Dictionary < string , object >
1931 {
20- { "Hubspot " , new Dictionary < string , object >
32+ { "oneOf " , new [ ] { new Dictionary < string , object >
2133 {
22- { "type" , "object" } ,
2334 { "properties" , new Dictionary < string , object >
2435 {
2536 { "Endpoint" , new Dictionary < string , object >
2637 {
27- { "type" , "string" } ,
28- { "title" , "Endpoint" } ,
2938 { "enum" , new [ ] { Constants . EndpointMemberships } }
3039 } } ,
31- } } ,
32- { "required" , new [ ] { "Endpoint" } } ,
33- { "dependencies" , new Dictionary < string , object >
34- {
35- { "Endpoint" , new Dictionary < string , object >
40+ { "MembershipsSettings" , new Dictionary < string , object >
3641 {
37- { "oneOf" , new [ ] { new Dictionary < string , object >
42+ { "type" , "object" } ,
43+ { "title" , "Target membership list in Hubspot" } ,
44+ { "description" , "Either select a target list from the dropdown below or manually enter a list ID within the field below." } ,
45+ { "properties" , new Dictionary < string , object >
3846 {
39- { "properties " , new Dictionary < string , object >
47+ { "IlsId " , new Dictionary < string , object >
4048 {
41- { "Endpoint" , new Dictionary < string , object >
42- {
43- { "enum" , new [ ] { Constants . EndpointMemberships } }
44- } } ,
45- { "EndpointSettings" , new Dictionary < string , object >
46- {
47- { "type" , "object" } ,
48- { "title" , "Endpoint Settings" } ,
49- { "properties" , new Dictionary < string , object >
50- {
51- { "MembershipsSettings" , new Dictionary < string , object >
52- {
53- { "type" , "object" } ,
54- { "title" , "" } ,
55- { "properties" , new Dictionary < string , object >
56- {
57- { "IlsId" , new Dictionary < string , object >
58- {
59- { "type" , "string" } ,
60- { "title" , "Target membership list in Hubspot" } ,
61- { "description" , "Name of the Hubspot target list with ID in parenthesis." } ,
62- { "enum" , listIds }
63- } } ,
64- } } ,
65- { "required" , new [ ] { "IlsId" } }
66- } }
67- } }
68- } }
69- } }
70- } } }
49+ { "type" , "string" } ,
50+ { "title" , "NAME OF THE HUBSPOT TARGET LIST WITH ID IN PARETHESIS (LIMITED UP TO 20 RESULTS)." } ,
51+ { "enum" , listIdsInDropdown }
52+ } } ,
53+ { "ManualIlsId" , new Dictionary < string , object >
54+ {
55+ { "type" , "string" } ,
56+ { "title" , "MANUALLY ENTER LIST ID." } ,
57+ } } ,
58+ } } ,
7159 } }
7260 } }
73- } }
74- }
75-
76- } ,
77- {
78- "required" , new [ ]
79- {
80- "Hubspot"
81- }
82- }
61+ } } }
62+ } }
63+ } }
8364 } ;
8465
8566 return JsonConvert . SerializeObject ( schemaJsonObj ) ;
8667 }
87-
88- public static async Task < string [ ] > GetAllListId ( IApiClient client )
89- {
90- var listIds = new List < string > ( ) ;
91- const string path = "crm/v3/lists/search" ;
92- var json = new StringContent (
93- "{\" listIds\" :[],\" offset\" :0,\" processingTypes\" :[\" MANUAL\" , \" SNAPSHOT\" ]}" ,
94- Encoding . UTF8 ,
95- "application/json"
96- ) ;
97- var response = await client . PostAsync ( path , json ) ;
98- var result = await response . Content . ReadAsStringAsync ( ) ;
99- var obj = JsonConvert . DeserializeObject < dynamic > ( result ) ;
100- var lists = obj ? . lists ;
101-
102- if ( lists == null ) return listIds . ToArray ( ) ;
103-
104- foreach ( var list in lists )
105- {
106- listIds . Add ( $ "{ list . name . ToString ( ) } ({ list . listId . ToString ( ) } )") ;
107- }
108- return listIds . ToArray ( ) ;
109- }
110-
11168 }
11269}
0 commit comments