问题
we have a survey in surveymonkey and using c# to try and add the email addresses to the survey using the surveymonkey api. the api works fine for GETS but we have yet to get a POST to work. all we get back is
"docs": "https://developer.surveymonkey.com/api/v3/#error-codes", "message": "There was an error retrieving the requested resource.", "id": "1020", "name": "Resource Not Found", "http_status_code": 404
all of the id's are correct as we can GET information about the survey but cannot POST to it. we have granted all the scopes so there shouldn't be a limitation or restriction on that side. SurveyMonkey api support might as well not exist as they are a complete waste of time and cannot answer a single question about their api.
the code below is our latest attempt at calling out to the api with a POST. we put the actual ids in the uri instead of {id} I did not include our id's here for the obvious reasons.
using (var client = new HttpClient()) { var uri = new Uri("https://api.surveymonkey.net/v3/surveys/{id}/collectors/{id}/messages/{id}/recipients-d"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",ConfigurationManager.AppSettings["SurveyMonkeyAccessToken"]); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var content = new StringContent("{ \"email\": + " + emailAddress + " }", Encoding.UTF8, "application/json"); var response = client.PostAsync(uri,content); ParseSurveyPostResponses(response) }
anyone successfully post to a surveymonkey survey using their V3 api?
回答1:
What exactly are you trying to do? Are you trying to create an email collector? Are you trying to create a new message on that email collector? Are you trying to add recipients to that email? are you trying to send out the email?
Creating an email collector:
POST /v3/<survey_id>/collectors
{
"type": "email"
}
Adding a message to an email collector:
POST /v3/collectors/<collector_id>/messages
{
"type": "invite"
}
Add recipients to a message:
POST /collectors/<collector_id>/messages/<message_id>/recipients
{
"email": "test@example.com",
"first_name": "Test",
"last_name": "Example",
"custom_fields": {
"1": "First Value",
"2": "Second Value",
"3": "Third Value"
},
"extra_fields": {
"field_name1": "field_value1",
"field_name2": "field_value2"
}
}
NOTE: You can also add recipients in bulk
NOTE2: Custom fields are stored on the associated contact in your contact list, Extra Fields are only stored on the recipient for that message and only accessible through the API.
Sending out the email:
POST /v3/collectors/<collector_id>/messages/<message_id>/send
{
"scheduled_date": "2017-07-18T16:52:22"
}
NOTE: you can exclude the scheduled_date
and just send in {}
to send the message right away.
来源:https://stackoverflow.com/questions/45171381/post-an-email-to-a-survey-using-the-surveymonkey-api