Pagination with PHP and Curl


#1

Does anyone have any examples of using PHP and Curl to query API V2, return the first 100 results and if pagination is true, continue with requests until exhausted?

If there is a better way to access your API via PHP I am open to that as well.


#2

I guess really what I need to know, overall, is how to make a PHP curl post request for API v2 including PHP variables in the post request.

If I have curl post data like the following:

$curl_post_data = array("query" => '{
  b1: bill(id: "ocd-bill/064ab209-7a2b-4e44-ae86-953d156e3b03") {
    id
    identifier
    title
    classification
    updatedAt
    createdAt
    legislativeSession {
      identifier
      jurisdiction {
        name
      }
    }
    actions {
      date
      description
      classification
    }
    documents {
      date
      note
      links {
        url
      }
    }
    versions {
      date
      note
      links {
        url
      }
    }
    sources {
      url
      note
    }
  }
}
  ');

then how would I pass a PHP variable to bill like so:
bill(id: $variable)


#3

For those that were stuck and a bit new to programming this works fine:

$curl_post_data = array("query" => '{
  b1: bill(id: "' . $bill_id . '") {
    id
    identifier
    title
    classification
    updatedAt
    createdAt
    legislativeSession {
      identifier
      jurisdiction {
        name
      }
    }
    actions {
      date
      description
      classification
    }
    documents {
      date
      note
      links {
        url
      }
    }
    versions {
      date
      note
      links {
        url
      }
    }
    sources {
      url
      note
    }
  }
}
  ');