@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