Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update documentation for retrieving list of filtered emails #485

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1788,14 +1788,32 @@ For information about building combined queries, see [Building compound Email Ac

### GET /messages
```ruby
require 'erb'

filter_key = 'to_email'
filter_operator = ERB::Util.url_encode('=')
filter_value = '[email protected]'
filter_value = ERB::Util.url_encode(format('"%s"', filter_value))
filter_operator = '='
filter_value = "'[email protected]'"
query_params = {}
query_params['query'] = "#{filter_key}#{filter_operator}#{filter_value}"
query_params['limit'] = '1'

params = query_params
response = sg.client.messages.get(query_params: params)
puts response.status_code
puts response.body
puts response.headers
```

### Filter messages by unique arguments

For information about unique arguments, see [Sendgrid Unique Arguments](https://docs.sendgrid.com/for-developers/sending-email/unique-arguments)

For passing unique arguments when sending emails, refer to [Sending Custom Args Example](https://github.com/sendgrid/sendgrid-ruby/blob/main/examples/helpers/mail/example.rb#L41)

```ruby
filter_key = "unique_args['user_id']"
filter_operator = '='
filter_value = "'123456789'"
query_params = {}
query_params['query'] = format("%s%s%s", filter_key, filter_operator, filter_value)
query_params['query'] = "#{filter_key}#{filter_operator}#{filter_value}"
query_params['limit'] = '1'

params = query_params
Expand Down
26 changes: 20 additions & 6 deletions examples/emailactivity/emailactivity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@
# Filter all messages #
# GET /messages #

require 'erb'

filter_key = 'to_email'
filter_operator = ERB::Util.url_encode('=')
filter_value = '[email protected]'
filter_value = ERB::Util.url_encode(format('"%s"', filter_value))
filter_operator = '='
filter_value = "'[email protected]'"
query_params = {}
query_params['query'] = "#{filter_key}#{filter_operator}#{filter_value}"
query_params['limit'] = '1'

params = query_params
response = sg.client.messages.get(query_params: params)
puts response.status_code
puts response.body
puts response.headers

##################################################
# Filter messages by unique args #
# GET /messages #

filter_key = "unique_args['user_id']"
filter_operator = '='
filter_value = "'123456789'"
query_params = {}
query_params['query'] = format("%s%s%s", filter_key, filter_operator, filter_value)
query_params['query'] = "#{filter_key}#{filter_operator}#{filter_value}"
query_params['limit'] = '1'

params = query_params
Expand Down