skip to Main Content

I need to add BODY content with some filters in my PHP CODE of APi curl How can i do it

I need to be added in my API call

Here is API CAll Code

$chn = curl_init();
curl_setopt($chn, CURLOPT_POST, true);
curl_setopt($chn, CURLOPT_URL, 'https://api.livechatinc.com/v3.4/agent/action/list_archives');
curl_setopt($chn, CURLOPT_RETURNTRANSFER, true);
curl_setopt($chn, CURLOPT_POSTFIELDS, '{}');
curl_setopt($chn, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: Bearer ' . $token
    )
);

2

Answers


  1. $parameters = array( "key1" => val1, "key2" => val2);
    
    # your curl definition
    
    curl_setopt($chn, CURLOPT_POSTFIELDS, $parameters);
    
    Login or Signup to reply.
  2. You can add a request body to your API call by passing the data as a string in the CURLOPT_POSTFIELDS option.

    $filter = array(
    "page" => 1,
    "page_size" => 20,
    "start_time" => "2022-01-01T00:00:00Z",
    "end_time" => "2022-12-31T23:59:59Z",
    "sort_by" => "start_time",
    "sort_order" => "asc"
    );
    
    $chn = curl_init();
    curl_setopt($chn, CURLOPT_POST, true);
    curl_setopt($chn, CURLOPT_URL, 'https://api.livechatinc.com/v3.4/agent/action/list_archives');
    curl_setopt($chn, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($chn, CURLOPT_POSTFIELDS, json_encode($filter));
    curl_setopt($chn, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: Bearer ' . $token
    )
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search