SOLVED

How can I post Yammer's Poll using the REST API

%3CLINGO-SUB%20id%3D%22lingo-sub-205529%22%20slang%3D%22en-US%22%3EHow%20can%20I%20post%20Yammer's%20Poll%20using%20the%20REST%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-205529%22%20slang%3D%22en-US%22%3E%3CP%3EHi!%20Everyone.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20am%20trying%20to%20create%20a%20java%20app%20that%20posts%20Poll%20using%20the%20REST%20API.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EWhen%20I%20set%20%22poll%22%20to%20%22message_type%22%20and%26nbsp%3BPOST%20%22%3CA%20href%3D%22https%3A%2F%2Fwww.yammer.com%2Fapi%2Fv1%2Fmessages%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.yammer.com%2Fapi%2Fv1%2Fmessages%3C%2FA%3E%22%20but%20status%20400%20Bad%20Request%26nbsp%3Bis%20returned.%3C%2FSPAN%3E%3C%2FP%3E%3CPRE%3E%2F%2F%20Post%3CBR%20%2F%3E%20HttpPost%20httpPost%20%3D%20new%20HttpPost(%3CSPAN%3E%22https%3A%2F%2Fwww.yammer.com%2Fapi%2Fv1%2Fmessages%22%3C%2FSPAN%3E)%3B%3CBR%20%2F%3E%20%2F%2F%20Add%20header%3CBR%20%2F%3E%20httpPost.addHeader(%22Authorization%22%2C%20%22Bearer%20%22%20%2B%20accessAuthToken)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%20%20List%3CNAMEVALUEPAIR%3E%20nvps%20%3D%20new%20ArrayList%26lt%3B%26gt%3B()%3B%3CBR%20%2F%3E%20%20nvps.add(new%20BasicNameValuePair(%22group_id%22%2C%20group))%3B%3CBR%20%2F%3E%26nbsp%3B%20nvps.add(new%20BasicNameValuePair(%22body%22%2C%20%22message%20body%201%22))%3B%3CBR%20%2F%3E%26nbsp%3B%20nvps.add(new%20BasicNameValuePair(%22message_type%22%2C%20%22poll%22))%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%20%2F%2F%26nbsp%3Bset%20entity%3CBR%20%2F%3E%20httpPost.setEntity(new%20UrlEncodedFormEntity(nvps%2C%20UTF8))%3B%3CBR%20%2F%3E%20%2F%2F%26nbsp%3Bexecute%3CBR%20%2F%3E%20HttpResponse%20response%20%3D%20httpclient.execute(httpPost)%3B%3C%2FNAMEVALUEPAIR%3E%3C%2FPRE%3E%3CP%3E%3CSPAN%3EHow%20can%20I%20post%20Poll%20using%20the%20REST%20API%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EBest%20Regards.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-205529%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EApp%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EREST%20API%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EYammer%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-207378%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20I%20post%20Yammer's%20Poll%20using%20the%20REST%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-207378%22%20slang%3D%22en-US%22%3E%3CP%3EHi!Simon.%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20reply.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20not%20that%20Poll%20can%20not%20be%26nbsp%3Bposted%20via%20the%20REST%20API%3F%3C%2FP%3E%3CP%3E%3CSPAN%3EIf%20that%20is%20the%20case%2C%20I%20consider%20another%20way.%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThank%20you%20very%20much.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-207079%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20I%20post%20Yammer's%20Poll%20using%20the%20REST%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-207079%22%20slang%3D%22en-US%22%3EI%20do%20not%20think%20a%20Poll%20is%20a%20valid%20end%20point.%20You%20can%20post%20messages%20and%20announcements%20plus%20work%20with%20topics.%20%3CA%20href%3D%22https%3A%2F%2Fdeveloper.yammer.com%2Fdocs%2Fmessages-json-post%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.yammer.com%2Fdocs%2Fmessages-json-post%3C%2FA%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi! Everyone.

 

I am trying to create a java app that posts Poll using the REST API.

When I set "poll" to "message_type" and POST "https://www.yammer.com/api/v1/messages" but status 400 Bad Request is returned.

// Post
HttpPost httpPost = new HttpPost("https://www.yammer.com/api/v1/messages");
// Add header
httpPost.addHeader("Authorization", "Bearer " + accessAuthToken);

List<NameValuePair> nvps = new ArrayList<>();
nvps.add(new BasicNameValuePair("group_id", group));
  nvps.add(new BasicNameValuePair("body", "message body 1"));
  nvps.add(new BasicNameValuePair("message_type", "poll"));

// set entity
httpPost.setEntity(new UrlEncodedFormEntity(nvps, UTF8));
// execute
HttpResponse response = httpclient.execute(httpPost);

How can I post Poll using the REST API?

 

Best Regards.

 

2 Replies
Best Response confirmed by のり 小林 (New Contributor)
Solution
I do not think a Poll is a valid end point. You can post messages and announcements plus work with topics. https://developer.yammer.com/docs/messages-json-post

Hi!Simon.

Thank you for your reply.

 

Is not that Poll can not be posted via the REST API?

If that is the case, I consider another way.

 

Thank you very much.