# Posting Polls

**URL:** <https://forum.social.plus/t/posting-polls/1110>\
**Category:** General\
**Created:** [February 9, 2024, 4:47pm UTC](https://forum.social.plus/t/posting-polls/1110 "2024-02-09T16:47:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hossam](https://avatars.discourse-cdn.com/v4/letter/h/e8c25b/32.png) [@hossam](https://forum.social.plus/u/hossam)\
**Post date:** [February 9, 2024, 4:47pm UTC](https://forum.social.plus/t/posting-polls/1110/1 "2024-02-09T16:47:24Z")

</div>

hello, I am trying to a make a poll post and put the poll id in the data and I got this  
{  
“status”: “error”,  
“message”: “Parameters validation error!”,  
“code”: 500000,  
“data”: {  
“detail”: [  
“The ‘attachments[0].type’ field does not match any of the allowed values.”  
]  
}  
}

$data = [  
“data” =\> [  
“text” =\> $caption ?? “”,  
“streamId” =\> “”,  
“pollId” =\> $dataFromPoll[0][‘pollId’],  
“dataType” =\>“poll”  
],  
“attachments” =\> [  
[  
“fileId” =\> “”,  
“type” =\> “poll”  
]  
],  
“targetType” =\> “user”,  
“metadata” =\> [  
“pollId” =\> null,  
“addonCaption” =\> $addonsCaption,  
“pdfData” =\> $pdfData,  
“externalLinks” =\> $externalLinks,  
“background\_photo” =\> null,  
],  
“postId” =\> Str::uuid(),  
“tags” =\> [  
“string”  
],  
“mentionees” =\> [  
[  
“type” =\> “user”,  
“userIds” =\> [

```
                ]
            ]
        ],
        "createdAt" => now()
    ];
    return json_encode($data);

```

so why the error?

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 9, 2024, 5:16pm UTC](https://forum.social.plus/t/posting-polls/1110/2 "2024-02-09T17:16:38Z")

</div>

```auto
“attachments” => [
[
“fileId” => “”,
“type” => “poll”
]
]

```

From your request, “type” =\> “poll” is not supported, as indicated by the error. For the attachment type, you can only choose from the available types, such as **image, file, or video**.

![Screenshot 2567-02-09 at 17.00.19](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/f06866ff075d2ce996d94a5d9737165dd40b6705.png)

You can click on **schema** to see the structure of each field/api call:

 ![Screenshot 2567-02-09 at 17.03.45](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/27616275f57f339d960a9bccec2cca280a2871c3.png)

Please also note that for poll post:

- When put `dataType` as `poll` and `pollId` in `data`, post will be created as poll post
- `attachments` will be ignored
- Poll info will be in `polls` object in response

---

<div class="post-metadata">

**Author:** ![hossam](https://avatars.discourse-cdn.com/v4/letter/h/e8c25b/32.png) [@hossam](https://forum.social.plus/u/hossam)\
**Post date:** [February 9, 2024, 11:46pm UTC](https://forum.social.plus/t/posting-polls/1110/3 "2024-02-09T23:46:02Z")

</div>

@SocialPlus_Support

\<?php namespace App\Http\Controllers\Amity\Feed\Post; use App\Http\Controllers\Amity\Feed\Poll\PollController; use App\Http\Controllers\Amity\User\UploadFileController; use App\Http\Controllers\Controller; use App\Http\Requests\Amity\Feed\Poll\PollRequest; use App\Http\Requests\Amity\Feed\Post\PostPhotoRequest; use App\Traits\ApiResponder; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Http; use Illuminate\Support\Str; class PollPostController extends Controller { use ApiResponder; protected $user; public function \_\_construct() { $this-\>user = Auth::user(); } public function postPoll(PollRequest $request) { DB::beginTransaction(); // Data from request $data = $request-\>validated(); $accessToken = $request-\>header('accesstoken'); $template = $request-\>file('template'); $caption = null; $pdfData = null; $externalLinks = null; // get the caption if (array\_key\_exists('caption', $data)) { $caption = $data['caption']; } // create external links if (array\_key\_exists('arr', $data)) { $externalLinks = $data['arr']; } // If cv exist if (array\_key\_exists('exist\_cv', $data)) { $pdfData = json\_decode($data['exist\_cv']); } // upload the Market or CV $addonsCaption = $data['addons\_caption'] ?? null; if (array\_key\_exists('media', $data)) { $marketORCv = $request-\>file('media'); $responseForFile = $this-\>handleDataForCV($marketORCv, $accessToken); $pdfData = $responseForFile[0]; } // create the background template $responseForTemplateUpload = $this-\>UploadTemplateBackground($template, $accessToken); //create Poll $pollController = new PollController(); $responseForPoll = $pollController-\>createPoll($data, $accessToken); if ($responseForPoll-\>failed()) { return response()-\>json($responseForPoll-\>json(), $responseForPoll-\>status()); } $responseFinal = $this-\>handlePostData($responseForPoll['polls'], $responseForTemplateUpload[0], $caption, $pdfData, $addonsCaption, $externalLinks); $response = $this-\>integrate($responseFinal, $accessToken); if ($response-\>failed()) { DB::rollBack(); return response()-\>json($response-\>json(), $response-\>status()); } DB::commit(); return $this-\>respondWithCollection($response-\>json(), "Your Reels uploaded Successfully !"); } public function UploadPhotoFeed($file, $token = null) { $xApiKey = ''; $Api = 'https://api.eu.amity.co/api/v4/images'; $header = ['x-api-key' =\> $xApiKey, 'accept' =\> 'application/json',]; return Http::withToken($token)-\>withHeaders($header) -\>attach('files', file\_get\_contents($file), $file-\>getClientOriginalName()) -\>post($Api); } public function UploadTemplateBackground($file, $token = null) { $xApiKey = ''; $Api = 'https://api.eu.amity.co/api/v4/images'; $header = ['x-api-key' =\> $xApiKey, 'accept' =\> 'application/json',]; return Http::withToken($token)-\>withHeaders($header) -\>attach('files', file\_get\_contents($file), $file-\>getClientOriginalName()) -\>post($Api); } public function handlePostData($dataFromPoll, $dataFromTemplate, $caption = null, $pdfData = null, $addonsCaption = null, $externalLinks = null) { $data = ["data" =\> [ "text" =\> $caption ?? "", "streamId" =\> "", "dataType" =\> 'poll', "pollId" =\> $dataFromPoll[0]['pollId'], ], "attachments" =\> [[ "fileId" =\> "", "type" =\> ""] ], "targetType" =\> "user", "dataType" =\> "upstra.poll", "metadata" =\> ["pollId" =\> null, "addonCaption" =\> $addonsCaption, "pdfData" =\> $pdfData, "externalLinks" =\> $externalLinks, "background\_photo" =\> $dataFromTemplate,], "postId" =\> Str::uuid(), "tags" =\> ["string"], "mentionees" =\> [[ "type" =\> "user", "userIds" =\> [] ] ], "createdAt" =\> now() ]; return json\_encode($data); } public function integrate($data, $token = null) { $xApiKey = 'b0e9ec5d3eddf5641f328d4a555b168ed20c8bb0bf356b7a'; $Api = 'https://api.eu.amity.co/api/v4/posts'; $header = ['x-api-key' =\> $xApiKey, 'accept' =\> 'application/json', 'Content-Type' =\> 'application/json']; return Http::withToken($token)-\>withHeaders($header)-\>withBody($data, 'application/json')-\>post($Api); } public function handleDataForCV($file, $accessToken = null) { $uploadFile = new UploadFileController(); $response = $uploadFile-\>uploadFile($file, $accessToken); return $response['response']; } } I make this and also get { "status": "error", "message": "Parameters validation error!", "code": 500000, "data": { "detail": ["The 'attachments[0].type' field does not match any of the allowed values." ] } } and also make this \<?php namespace App\Http\Controllers\Amity\Feed\Post; use App\Http\Controllers\Amity\Feed\Poll\PollController; use App\Http\Controllers\Amity\User\UploadFileController; use App\Http\Controllers\Controller; use App\Http\Requests\Amity\Feed\Poll\PollRequest; use App\Http\Requests\Amity\Feed\Post\PostPhotoRequest; use App\Traits\ApiResponder; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Http; use Illuminate\Support\Str; class PollPostController extends Controller { use ApiResponder; protected $user; public function \_\_construct() { $this-\>user = Auth::user(); } public function postPoll(PollRequest $request) { DB::beginTransaction(); // Data from request $data = $request-\>validated(); $accessToken = $request-\>header('accesstoken'); $template = $request-\>file('template'); $caption = null; $pdfData = null; $externalLinks = null; // get the caption if (array\_key\_exists('caption', $data)) { $caption = $data['caption']; } // create external links if (array\_key\_exists('arr', $data)) { $externalLinks = $data['arr']; } // If cv exist if (array\_key\_exists('exist\_cv', $data)) { $pdfData = json\_decode($data['exist\_cv']); } // upload the Market or CV $addonsCaption = $data['addons\_caption'] ?? null; if (array\_key\_exists('media', $data)) { $marketORCv = $request-\>file('media'); $responseForFile = $this-\>handleDataForCV($marketORCv, $accessToken); $pdfData = $responseForFile[0]; } // create the background template $responseForTemplateUpload = $this-\>UploadTemplateBackground($template, $accessToken); //create Poll $pollController = new PollController(); $responseForPoll = $pollController-\>createPoll($data, $accessToken); if ($responseForPoll-\>failed()) { return response()-\>json($responseForPoll-\>json(), $responseForPoll-\>status()); } $responseFinal = $this-\>handlePostData($responseForPoll['polls'], $responseForTemplateUpload[0], $caption, $pdfData, $addonsCaption, $externalLinks); $response = $this-\>integrate($responseFinal, $accessToken); if ($response-\>failed()) { DB::rollBack(); return response()-\>json($response-\>json(), $response-\>status()); } DB::commit(); return $this-\>respondWithCollection($response-\>json(), "Your Reels uploaded Successfully !"); } public function UploadPhotoFeed($file, $token = null) { $xApiKey = ''; $Api = 'https://api.eu.amity.co/api/v4/images'; $header = ['x-api-key' =\> $xApiKey, 'accept' =\> 'application/json',]; return Http::withToken($token)-\>withHeaders($header) -\>attach('files', file\_get\_contents($file), $file-\>getClientOriginalName()) -\>post($Api); } public function UploadTemplateBackground($file, $token = null) { $xApiKey = ''; $Api = 'https://api.eu.amity.co/api/v4/images'; $header = ['x-api-key' =\> $xApiKey, 'accept' =\> 'application/json',]; return Http::withToken($token)-\>withHeaders($header) -\>attach('files', file\_get\_contents($file), $file-\>getClientOriginalName()) -\>post($Api); } public function handlePostData($dataFromPoll, $dataFromTemplate, $caption = null, $pdfData = null, $addonsCaption = null, $externalLinks = null) { $data = ["data" =\> [ "text" =\> $caption ?? "", "streamId" =\> "", "dataType" =\> 'poll', "pollId" =\> $dataFromPoll[0]['pollId'], ], "attachments" =\> [[ "fileId" =\> "", "type" =\> ""] ], "targetType" =\> "user", "dataType" =\> "poll", "metadata" =\> ["pollId" =\> null, "addonCaption" =\> $addonsCaption, "pdfData" =\> $pdfData, "externalLinks" =\> $externalLinks, "background\_photo" =\> $dataFromTemplate,], "postId" =\> Str::uuid(), "tags" =\> ["string"], "mentionees" =\> [[ "type" =\> "user", "userIds" =\> [] ] ], "createdAt" =\> now() ]; return json\_encode($data); } public function integrate($data, $token = null) { $xApiKey = 'b0e9ec5d3eddf5641f328d4a555b168ed20c8bb0bf356b7a'; $Api = 'https://api.eu.amity.co/api/v4/posts'; $header = ['x-api-key' =\> $xApiKey, 'accept' =\> 'application/json', 'Content-Type' =\> 'application/json']; return Http::withToken($token)-\>withHeaders($header)-\>withBody($data, 'application/json')-\>post($Api); } public function handleDataForCV($file, $accessToken = null) { $uploadFile = new UploadFileController(); $response = $uploadFile-\>uploadFile($file, $accessToken); return $response['response']; } } and get the same error can you please help me how can make a post as poll

---

<div class="post-metadata">

**Author:** ![hossam](https://avatars.discourse-cdn.com/v4/letter/h/e8c25b/32.png) [@hossam](https://forum.social.plus/u/hossam)\
**Post date:** [February 11, 2024, 8:40am UTC](https://forum.social.plus/t/posting-polls/1110/4 "2024-02-11T08:40:20Z")

</div>

Hello is there any answer ?

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 12, 2024, 8:54am UTC](https://forum.social.plus/t/posting-polls/1110/5 "2024-02-12T08:54:25Z")

</div>

Hello, have you tried creating poll post using postman? Are you facing the same error as you’re experiencing with your php request?
