Skip to content

Commit

Permalink
Adding examples for the new marketing campaigns
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarcet committed Dec 18, 2021
1 parent 54a33bb commit ee4de8f
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/new_marketing_campaigns/contacts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'sendgrid-ruby'

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])

##################################################
# Add or Update a Contact #
# POST /marketing/contacts #

data = JSON.parse('{
"list_ids": [
"ca7a3796-e8a8-4029-9ccb-df8937940562"
],
"contacts": [
{
"address_line_1": "123 Elm St.",
"address_line_2": "Apt. 456",
"city": "Denver",
"country": "United States",
"email": "[email protected]",
"first_name": "User",
"last_name": "Example"
}
]
}')

response = sg.client.marketing.contacts.put(request_body: data)
puts response.status_code
puts response.body
puts response.headers
49 changes: 49 additions & 0 deletions examples/new_marketing_campaigns/customfields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'sendgrid-ruby'

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])

##################################################
# Create Custom Field Definition #
# POST /marketing/field_definitions #

data = JSON.parse('{
"name": "pet",
"field_type": "Text"
}')

response = sg.client.marketing.field_definitions.post(request_body: data)
puts response.status_code
puts response.body
puts response.headers

##################################################
# Get All Field Definitions #
# GET /marketing/field_definitions #

response = sg.client.marketing.field_definitions.get
puts response.status_code
puts response.body
puts response.headers

##################################################
# Update Custom Field Definition #
# PATCH /marketing/field_definitions/{custom_field_id} #

data = JSON.parse('{
"name": "new_custom_field_name"
}')
custom_field_id = 'e1_T'
response = sg.client.marketing.field_definitions._(custom_field_id).patch(request_body: data)
puts response.status_code
puts response.body
puts response.headers

##################################################
# Delete Custom Field Definition #
# DELETE /marketing/field_definitions/{custom_field_id} #

custom_field_id = 'e1_T'
response = sg.client.marketing.field_definitions._(custom_field_id).delete
puts response.status_code
puts response.body
puts response.headers
35 changes: 35 additions & 0 deletions examples/new_marketing_campaigns/lists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'sendgrid-ruby'

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])

##################################################
# Create List #
# GET /marketing/lists #

data = JSON.parse('{
"name": "list-name"
}')

response = sg.client.marketing.lists.post(request_body: data)
puts response.status_code
puts response.body
puts response.headers

##################################################
# Get All Lists #
# GET /marketing/lists #

response = sg.client.marketing.lists.get
puts response.status_code
puts response.body
puts response.headers

##################################################
# Get a List by ID #
# GET /marketing/lists/{id} #

list_id = 'ca7a3796-e8a8-4029-9ccb-df8937940562'
response = sg.client.marketing.lists._(list_id).get
puts response.status_code
puts response.body
puts response.headers
28 changes: 28 additions & 0 deletions examples/new_marketing_campaigns/singlesends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'sendgrid-ruby'

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])

##################################################
# Create Single Send #
# POST /marketing/singlesends #

data = JSON.parse('{
"name": "Example API Created Single Send",
"categories": [
"unique opens"
],
"send_to": {
"all": true
},
"email_config": {
"design_id": "<your-design-id>",
"editor": "design",
"suppression_group_id": 12,
"sender_id": 10
}
}')

response = sg.client.marketing.singlesends.post(request_body: data)
puts response.status_code
puts response.body
puts response.headers

0 comments on commit ee4de8f

Please sign in to comment.