Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Felix_Hoffmann1
Participant
Jump to solution

using checkpoint management api web service with php

Hi,

has anybody some code examples how to use web service api with php. I think a good way is to use php cURL but i don't have a clue how to start. I think that Ekta Siwani‌ was using php with api.

Thanks in advance.

Felix

1 Solution

Accepted Solutions
VENKAT_S_P
Collaborator

I use PHP, post method, use cURL get request/response from json and display the error.

Do not verify the peer and verify host otherwise it will give the SSL error.

Sample code:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://Mgmt_IP/web_api/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",

CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POSTFIELDS => "{\r\n \"user\" : \"admin\",\r\n \"password\" : \"#@$1@#\"\r\n}",
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/json",
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

View solution in original post

3 Replies
PhoneBoy
Admin
Admin

I haven't seen many code examples with PHP.

We do have one with Python, though: CPAPI - Web API Tool

0 Kudos
VENKAT_S_P
Collaborator

I use PHP, post method, use cURL get request/response from json and display the error.

Do not verify the peer and verify host otherwise it will give the SSL error.

Sample code:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://Mgmt_IP/web_api/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",

CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POSTFIELDS => "{\r\n \"user\" : \"admin\",\r\n \"password\" : \"#@$1@#\"\r\n}",
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/json",
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

Felix_Hoffmann1
Participant

Thank you VENKAT S P, exactly what I was looking for!

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events