Jump to content

cURL only returning 500 results, needing to loop through all “next_page”


Sema314

Recommended Posts

When using cURL, how would I be able to include a call inside my get_all that basically will loop through all the next_page, get and store the data and then output it to $response->data when the "next_page" parameter becomes null?

**Here is the method**:

    public function get_all()
    {
        return $response->data;
    }

**This is what $response->data is returning as of now** (The cURL code wasn't included here):

    "paginator": {
        "total": 3092,
        "per_page": 500,
        "current_page": 2,
        "last_page": 7,
        "prev_page": "https://oc.com/api/v1/employees/?page=1",
        "next_page": "https://oc.com/api/v1/employees/?page=3"
    },
    "data": [
            {
                "id": 1592,
            etc....

Here are all of my unsuccessful attempts:

        public function get_all()
        {
    
    //        $next_url = $response->paginator->next_page;
    //
    //        foreach ($response as $next => $next_page) {
    //            print_r2($next);
    //
    //            if ($next_url !== null) {
    //                $next_page = $response->data;
    //            }
    //        }
    
    //        foreach ($response as $paginator => $next_page) {
    //            if ($next_url !== null) {
    //                $return[] = $response->data;
    //            }
    //        }
    
    //        var_dump($response->paginator);
    
    //        if ($next_url !== null) {
    //            $this->get_all($path, $args, $next_url);
    //        }
    
            return $response->data;
        }

 

Edited by Sema314
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.