cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1642
Views
1
Helpful
1
Replies

ACS REST API - Consume API using PHP CURL

amitking123
Level 1
Level 1

Has anyone tried PHP Curl to consume ASC API?

I have tried following code but getting following error, can anyone hep to fix this?

<errorCode>61000</errorCode><httpCode>400</httpCode><moreErrInfo>XML Parsing Error:  Premature end of file.. Premature end of file.. </moreErrInfo>

Following code is to fetch one record, I'm not sure that this API accept XML data as POST/PUT value.

---------------  PHP CUrl Code Start------------------------------------

$headers = array('Content-type: application/xml');

$url = 'https://SERVER/Rest/NetworkDevice/Device/op/query';

$username = 'some-user';

$password = 'password';

$data = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><ns2:query xmlns:ns2='query.rest.mgmt.acs.nm.cisco.com'><numberofItemsInPage>1</numberofItemsInPage><startPageNumber>1</startPageNumber></ns2:query>";

$data = urlencode(utf8_decode(trim($data)));

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);

curl_setopt($ch, CURLOPT_VERBOSE, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($ch, CURLOPT_PUT, 1);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$response->data = curl_exec($ch);

$response->httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

var_dump($response);

1 Reply 1

Geevarghese Cheria
Cisco Employee
Cisco Employee

Hi Amit,

   For XML format found one similar url -ACS REST API - Add Devices hope it helps. Just have a look .

Thanks and Regards,

Geevarghese

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: