File tree Expand file tree Collapse file tree 4 files changed +141
-0
lines changed
examples/new_marketing_campaigns Expand file tree Collapse file tree 4 files changed +141
-0
lines changed Original file line number Diff line number Diff line change
1
+ require 'sendgrid-ruby'
2
+
3
+ sg = SendGrid ::API . new ( api_key : ENV [ 'SENDGRID_API_KEY' ] )
4
+
5
+ ##################################################
6
+ # Add or Update a Contact #
7
+ # POST /marketing/contacts #
8
+
9
+ data = JSON . parse ( '{
10
+ "list_ids": [
11
+ "ca7a3796-e8a8-4029-9ccb-df8937940562"
12
+ ],
13
+ "contacts": [
14
+ {
15
+ "address_line_1": "123 Elm St.",
16
+ "address_line_2": "Apt. 456",
17
+ "city": "Denver",
18
+ "country": "United States",
19
+ "email": "example@example.com",
20
+ "first_name": "User",
21
+ "last_name": "Example"
22
+ }
23
+ ]
24
+ }' )
25
+
26
+ response = sg . client . marketing . contacts . put ( request_body : data )
27
+ puts response . status_code
28
+ puts response . body
29
+ puts response . headers
Original file line number Diff line number Diff line change
1
+ require 'sendgrid-ruby'
2
+
3
+ sg = SendGrid ::API . new ( api_key : ENV [ "SENDGRID_API_KEY" ] )
4
+
5
+ ##################################################
6
+ # Create Custom Field Definition #
7
+ # POST /marketing/field_definitions #
8
+
9
+ data = JSON . parse ( '{
10
+ "name": "pet",
11
+ "field_type": "Text"
12
+ }' )
13
+
14
+ response = sg . client . marketing . field_definitions . post ( request_body : data )
15
+ puts response . status_code
16
+ puts response . body
17
+ puts response . headers
18
+
19
+ ##################################################
20
+ # Get All Field Definitions #
21
+ # GET /marketing/field_definitions #
22
+
23
+ response = sg . client . marketing . field_definitions . get
24
+ puts response . status_code
25
+ puts response . body
26
+ puts response . headers
27
+
28
+ ##################################################
29
+ # Update Custom Field Definition #
30
+ # PATCH /marketing/field_definitions/{custom_field_id} #
31
+
32
+ data = JSON . parse ( '{
33
+ "name": "new_custom_field_name"
34
+ }' )
35
+ custom_field_id = 'e1_T'
36
+ response = sg . client . marketing . field_definitions . _ ( custom_field_id ) . patch ( request_body : data )
37
+ puts response . status_code
38
+ puts response . body
39
+ puts response . headers
40
+
41
+ ##################################################
42
+ # Delete Custom Field Definition #
43
+ # DELETE /marketing/field_definitions/{custom_field_id} #
44
+
45
+ custom_field_id = 'e1_T'
46
+ response = sg . client . marketing . field_definitions . _ ( custom_field_id ) . delete
47
+ puts response . status_code
48
+ puts response . body
49
+ puts response . headers
Original file line number Diff line number Diff line change
1
+ require 'sendgrid-ruby'
2
+
3
+ sg = SendGrid ::API . new ( api_key : ENV [ "SENDGRID_API_KEY" ] )
4
+
5
+ ##################################################
6
+ # Create List #
7
+ # GET /marketing/lists #
8
+
9
+ data = JSON . parse ( '{
10
+ "name": "list-name"
11
+ }' )
12
+
13
+ response = sg . client . marketing . lists . post ( request_body : data )
14
+ puts response . status_code
15
+ puts response . body
16
+ puts response . headers
17
+
18
+ ##################################################
19
+ # Get All Lists #
20
+ # GET /marketing/lists #
21
+
22
+ response = sg . client . marketing . lists . get
23
+ puts response . status_code
24
+ puts response . body
25
+ puts response . headers
26
+
27
+ ##################################################
28
+ # Get a List by ID #
29
+ # GET /marketing/lists/{id} #
30
+
31
+ list_id = 'ca7a3796-e8a8-4029-9ccb-df8937940562'
32
+ response = sg . client . marketing . lists . _ ( list_id ) . get
33
+ puts response . status_code
34
+ puts response . body
35
+ puts response . headers
Original file line number Diff line number Diff line change
1
+ require 'sendgrid-ruby'
2
+
3
+ sg = SendGrid ::API . new ( api_key : ENV [ 'SENDGRID_API_KEY' ] )
4
+
5
+ ##################################################
6
+ # Create Single Send #
7
+ # POST /marketing/singlesends #
8
+
9
+ data = JSON . parse ( '{
10
+ "name": "Example API Created Single Send",
11
+ "categories": [
12
+ "unique opens"
13
+ ],
14
+ "send_to": {
15
+ "all": true
16
+ },
17
+ "email_config": {
18
+ "design_id": "<your-design-id>",
19
+ "editor": "design",
20
+ "suppression_group_id": 12,
21
+ "sender_id": 10
22
+ }
23
+ }' )
24
+
25
+ response = sg . client . marketing . singlesends . post ( request_body : data )
26
+ puts response . status_code
27
+ puts response . body
28
+ puts response . headers
You can’t perform that action at this time.
0 commit comments