Get the message ID in the survey monkey response - surveymonkey

I am using survey monkey v3 API's to send survey emails. While sending a survey email from one collector, I am sending two different survey messages for the same recipient. However, while collecting the survey responses from survey monkey using the api "/surveys/{id}/responses/bulk", I couldn't find the messageID in it. So I how can I find which response belong to which message of the collector then? Is there a different API that I have to use?

What's the use case for tracking the specific message? You have the recipient_id, and first/last/email fields.
You can get recipient details at /collectors/{collector_id}/recipients/{recipient_id}. There's no way (as far as I can tell) to query for this other than searching your messages with /collectors/{collector_id}/messages/{message_id}/recipients
Generally speaking, when you add recipients to a message, they are shared with the collector. Which specific message was responded to is not really tracked, the tracking ID is the recipient_id with respect to the collector.
If you are interested in message stats (ex. which message gets a better response rate) you can use the message stats endpoint.
With regards to having a different message for say different products, unfortunately the message ID is not tied to a response, but two options are:
1) Use a different collector for each product (not ideal if there is a lot)
2) Use extra fields on the recipient (see example):
Example:
POST /v3/collectors/<collector_id>/messages/<message_id1>/recipients
{
"first_name": "Test",
"last_name": "Tester",
"email": "test#example.com",
"extra_fields": {
"product": "shoes"
}
}
POST /v3/collectors/<collector_id>/messages/<message_id2>/recipients
{
"first_name": "Test",
"last_name": "Tester",
"email": "test#example.com",
"extra_fields": {
"product": "shirts"
}
}
Then when you fetch the responses, you'll get that information in metadata, example:
{
"id": "<response_id>",
"recipient_id": "<recipient_id>",
"collector_id": "<collector_id>",
...
"metadata": {
"contact": {
"product": {
"type": "string",
"value": "shoes"
},
"email": {
"type": "string",
"value": "test#example.com"
}
}
}
}
One thing to watch out for is that the extra fields from the contact do not currently show up in the /responses/bulk endpoint, only individual responses/<id> endpoint. Also with extra fields you can't filter responses where product=shoes or whatnot. Those are some limitations with the current API - but hopefully it can at least be helpful for now.

Related

How can I filter calendar events with a specific email address or name using Microsoft graph api and OData?

I'm using the Microsoft graph api to fetch calendar events.
Now I would like to only fetch events where one of the attendees has a specific name or email address.
An example response describing such an event is
{
"subject": "General meeting",
"attendees": [
{
"emailAddress": {
"name": "Peter Pan",
"address": "peter.pan#neverland.org"
}
},
{
"emailAddress": {
"name": "Captain Hook",
"address": "captain.hook#neverland.org"
}
}
]
}
According to Microsofts documentation the likely way to achieve this is using OData and the any operator. However I can't find a way to access nested properties like name and address using query parameters.
I was hoping I could do something like this
https://graph.microsoft.com/v1.0/me/calendarview?startdatetime=2022-01-01T00:00:00.000Z&enddatetime=2022-31-01T00:00:00.000Z&$select=attendees,subject&$filter=attendees/any(var:var/emailAddress/address eq 'peter.pan#neverland.org')
but using subparam (emailAddress/address) like that leads to bad request.
If the emailAddress field was just an actual email and not another entity, filtering would work.
https://graph.microsoft.com/v1.0/me/calendarview?startdatetime=2022-01-01T00:00:00.000Z&enddatetime=2022-31-01T00:00:00.000Z&$select=attendees,subject&$filter=attendees/any(var:var/emailAddress eq 'peter.pan#neverland.org')
Is it possible to achieve what I want?
According this comment Graph API doesn't support drilling down multiple levels of relationships.

Microsoft Graph: insert a message (mail) to user inbox

I have a Microsoft application (with Mail.Read/Write permissions) and I need to insert a mail (.eml extension file) to a user inbox.
Is that possible? I know that with Gsuite that can be done using the 'insert' API and was wondering if something similar exist with Graph API.
I'm not talking about sending new mail to the user or about inserting an attachment to existing message in the user inbox, but to insert completely new email to his inbox (without having to go through SPF or whatever checks that take place before mails usually get into end users inboxes).
Looking into Mail section under Graph API documentation wasn't so helpful.
If that not possible, perhaps there is a workaround?
EDIT: seems like the best option is to use "send mail" API and specify "saveToSentItems": False.. the only issue here as that my application will need to request the Mail.Send permission as well..
Thanks
You don't need to use the send mail api as all your doing is creating an Item in the Mailbox. If you want it to appear as a Sent Mail (rather then a draft) you do need to set the PidTagMessageFlags extended property (the same as you would in EWS https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-import-items-by-using-ews-in-exchange). Also if you want it to appear if its been sent in the past there are few additional extended properties you need to set. eg
{
"Subject": "test1234",
"Sender": {
"EmailAddress": {
"Name": "blah",
"Address": "blah#blah.com"
}
},
"Body": {
"ContentType": "HTML",
"Content": "123Body"
},
"SingleValueExtendedProperties": [
{
"PropertyId": "Integer 0x0E07",
"Value": "1"
},
{
"PropertyId": "SystemTime 0x0039",
"Value": "2019-06-12T10:10:47.2048+10:00"
},
{
"PropertyId": "SystemTime 0x0E06",
"Value": "2019-06-12T10:10:47.2048+10:00"
}
]
}

Getting respondent names and email addresses in SurveyMonkey's API v3

I'm upgrading my application from SurveyMonkey's API v2 to v3 and using the liogi/surveymonkey-api-v3 library to wrap around my API calls and am not sure if I'm understanding how respondent info is being handled now.
The v2 endpoint POST /surveys/get_respondent_list would return data.respondents[_].email, .first_name, and .last_name, but its v3 equivalent doesn't.
Is it the case that with the API v3, this data can only be pulled from pages[_].questions[_].answers[_].text?
I hope not, because that makes pulling respondent names and email addresses way more complicated and seemingly necessitates knowing the question IDs that correspond to the correct fields for every survey. Am I misinterpreting the API, or has that "get respondent's email address" feature been gutted?
The email, first_name, and last_name are now all in the contact data in the metadata field provided in the response body when fetching a response.
So a request like:
GET /v3/surveys/<survey_id>/responses/<response_id>
will return something like this in the body:
{
...
"metadata": {
"contact": {
"first_name": {
"type": "string",
"value": "Test"
},
"last_name": {
"type": "string",
"value": "Example"
},
"email": {
"type": "string",
"value": "test#example.com"
}
}
}
...
}
Those 3 fields will also show up in the same place for the bulk responses endpoint.

Survey Monkey API Questions

I have a couple questions regarding the survey monkey API. First, I've noticed that the categories that can be assigned to open ended questions don't come through when pulling the details of a response. Is there a way to do this and if not, when will it be added?
Secondly, I've attempting to update the metadata field of a response, yet I'm receiving an invalid schema era.
I'm sending this in the request body:
{
"id": "4472927205",
"metadata": { "category" : "test"
}
}
This is the response I receive:
{
"error": {
"http_status_code": 400,
"message": "Invalid schema in the body provided.",
"id": "1002",
"docs": "https://developer.surveymonkey.com/api/v3/#error-codes",
"name": "Bad Request"
}
}
What is the proper schema for a request?
Categories set in the analyze section are not currently accessible through the API. There is no ETA for that at the moment.
Also the metadata shown in the responses are auto-generated based on other factors (some page logic I believe, contact information - case email collector) and are not updateable at the moment either.
See the docs also you can watch the public docs repo to be notified when the changes you'd like have been released.

Set Message-Id with Mandrill for bulk emails

I am sending emails to lists of contacts based on templates using Mandrill. I would like to track if the contacts have replied to my email and, to do so, I would like to check whether the Message-Id of my sent emails appears in the In-Reply-To header field of new messages.
The problem is that I have to generate and set the Message-Id manually since Mandrill only gives me their internal _id. However, since I am sending emails to various contacts at the same time, I set preserve_recipients to false. But then I can only set one Message-Id, which will therefore become not globally unique.
Here is an example JSON that I'm sending:
{
"from_email": "itsme#email.com",
"from_name": "Its Me",
"headers": {"Message-Id": ["<20150528161426.4265.93582#email.com>"]},
"subject": "Thesubject",
"text": "Thebody",
"to": [
{
"email": "john#email.com",
"name": "John",
"type": "to"
},
{
"email": "patrick#email.com",
"name": "Patrick",
"type": "to"
}
],
"preserve_recipients": false
}
In this case, two messages will be sent, but they'll have the same Message-Id. If I don't set it, Mandrill will automatically assign one, but then I can't retrieve it.
Any idea what I could do ? Maybe my whole approach is incorrect...
I ended up looping over all the recipients and generating a new Message-Id at each iteration and send one email at a time. Probably not optimal since I'm not using Mandrill bulk capability, but at least now I can store the email id.
import email
import mandrill
mandrill_client = mandrill.Mandrill('YOUR_MANDRILL_KEY')
for recipient in recipients:
# Generate RFC 2822-compliant Message-ID header
message_id = email.Utils.make_msgid()
m = {
"headers": {"Message-Id": [message_id],
"from_email": "itsme#email.com",
"from_name": "Its Me",
"subject": "The subject",
"text": "The body",
"to": [{"email": recipient["email"],
"name": recipient["name"],
"type": "to"}],
"track_clicks": True,
"track_opens": True
}
result = mandrill_client.messages.send(message=m)
From mandrill documentation you can retrieve the _id from the return value of the message.

Resources