Posting Polls

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?

“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

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

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

@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

Hello is there any answer ?

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