June 17, 2022 . 2 MIN READ
Not tested as I don’t have an eBay developer account but perhaps the following might help. The code below will issue a GET request with the querystring as part of the url as the documentation suggests
<?php
error_reporting( E_ALL );
require_once("includes/config.php");
/*
you can download from https://curl.haxx.se/docs/caextract.html
*/
$cacert='c:/wwwroot/cacert.pem'; # edit as appropriate to point to valid `cacert.pem` file
$verbose=true;
$endpoint = "https://api.ebay.com/buy/browse/v1/item_summary/search?";
$args=array(
'q' => 'GTR',
'limit' => 3
);
$url=sprintf( '%s%s', $endpoint, http_build_query( $args ) );
/*
for advanced debug information we create a stream
and output to that during the request. At the end
of the request the stream is processed and we can
view that data.
*/
if( $verbose )$vbh = fopen('php://temp', 'w+');
$headers = array(
'X-EBAY-API-APP-ID: ' . $sapp_id,
'X-EBAY-API-DEV-NAME: ' . $dev_id,
'X-EBAY-API-CERT-NAME: ' . $cert_id,
'X-EBAY-C-ENDUSERCTX: 5337984774'
);
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $curl, CURLOPT_CAINFO, $cacert );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_USERAGENT, 'curl' );
if( $verbose ){
curl_setopt( $curl, CURLOPT_VERBOSE, true );
curl_setopt( $curl, CURLOPT_NOPROGRESS, true );
curl_setopt( $curl, CURLOPT_STDERR, $vbh ); # the stream object
}
/* make the request and get info */
$response = curl_exec( $curl );
$info=(object)curl_getinfo( $curl );
$errors=curl_error( $curl );
/* store the verbose debug info */
if( $verbose ){
rewind( $vbh );
$debug=stream_get_contents( $vbh );
fclose( $vbh );
}
curl_close( $curl );
if( $info->http_code==200 ){
printf( '<pre>%s</pre>', print_r( $response, 1 ) );
} else{
printf( '<pre>%s</pre>', print_r( $verbose ? $debug : $info ,1 ) );
printf( '<pre>%s</pre>', print_r( $errors, 1 ) );
Reference:
https://stackoverflow.com/questions/57839676/ebay-api-search-item
https://github.com/rickapps/eBay-API-PHP
https://php-mvc.rickapps.com/