sanjayacloud's avatar

Clicksend Pagination does not work on Laravel

Hi Guys, I am working on getting messages history from ClickSend API, I am trying to message from it API as there documentation. But pagination doesn't work. It's only getting the first 15 recorded. Not getting page number as parameter what I send it. Anyone know how does it do? Can I know where I am wrong?

This is my controller Method.

    public function index(Request $request)
    {
        $config = ClickSend\Configuration::getDefaultConfiguration()
            ->setUsername('user-name')
            ->setPassword('password');

        $apiInstance = new ClickSend\Api\SMSApi(new GuzzleHttp\Client(),$config);
        $page = $request->page ? $request->page: 1; // int | Page number
        $limit = 10; // int | Number of records per page

        try {

            $result = $apiInstance->smsHistoryGet($page, $limit);
            $dt = json_decode($result);
            $current_page = $dt->data;
            $current_page = $current_page->current_page;
            $next_page = $current_page+1;
            $prev_page = $current_page == 1 ? null : $current_page-1;
            $allMessages = $dt->data->data;
            return response()->json(['data' => view('staff.history.table', compact('allMessages', 'current_page', 'next_page', 'prev_page'))->render()]);
        } catch (Exception $e) {
            echo 'Exception when calling SMSApi->smsHistoryGet: ', $e->getMessage(), PHP_EOL;
        }
    }

This is my view files

<table id="sms-table" class="table table-hover datatable-User">
    <thead>
    <th>Date</th>
    <th>From</th>
    <th>Message</th>
    <th>Status</th>
    </thead>
    <tbody>
    @foreach($allMessages as $item)
        @if($item->status == "Received")
            <tr>
                @php $date = \Carbon\Carbon::createFromTimestamp($item->date ) @endphp
                <td>{{$date->toDayDateTimeString()}}</td>
                <td>{{$item->from}}</td>
                <td>{{$item->body}}</td>
                <td><span class="badge badge-success">{{$item->status}}</span> </td>
            </tr>
        @endif
    @endforeach
    </tbody>
</table>
<div class="mt-5">
    <nav aria-label="Page navigation example">
        <ul class="pagination justify-content-center">
            <li class="page-item {{$prev_page == null ? 'disabled' : ''}}" data-page="{{$prev_page == null ? null : $prev_page }}">
                <a class="page-link" {{$prev_page == null ? 'disabled' : ''}} href="" tabindex="-1">Previous</a>
            </li>
{{--            <li class="page-item"><a class="page-link" >1</a></li>--}}
{{--            <li class="page-item"><a class="page-link">2</a></li>--}}
{{--            <li class="page-item"><a class="page-link">3</a></li>--}}
            <li class="page-item" data-page="{{$next_page == null ? null : $next_page }}">
                <a class="page-link" href="#">Next</a>
            </li>
        </ul>
    </nav>
</div>
<script>
    $('.page-item').on('click', function () {
        var page = $(this).data('page')
        $.ajax({
            url: 'https://mydomain.com/api/all-inbound?page=' + page,
            type: 'GET',
            success: function (data) {
                $('#sms-data').html(data.data);
            },

        });
    })
</script>

0 likes
4 replies
ClickSend's avatar

Why are you wanting to paginate through history? I mean, what are you wanting to get out of it? If you want to get the status of message delivery, you can use the GET delivery receipt endpoints, or ClickSend can HTTP POST to your URL. If you want replies, you can poll the inbox, or ClickSend can HTTP POST to your URL.

sanjayacloud's avatar

Hi, I have sorted out this with StackOverflow answer. Nad you have got wrong my question. Anyway, I have sorted out this already.

Please or to participate in this conversation.