1

Hi i am using XE converter api and need to fetch data from the url, my code so far is

$new_url = "https://xecdapi.xe.com/v1/account_info/";
$getData = CurlSendPostRequest($new_url);

print_r($getData);


function CurlSendPostRequest($url)
{
        $ch = curl_init($url);
        $options = array(
                CURLOPT_RETURNTRANSFER => true,         // return web page
                CURLOPT_HEADER         => false,        // don't return headers
                CURLOPT_FOLLOWLOCATION => false,         // follow redirects
               // CURLOPT_ENCODING       => "utf-8",           // handle all encodings
                CURLOPT_AUTOREFERER    => true,         // set referer on redirect
                CURLOPT_CONNECTTIMEOUT => 20,          // timeout on connect
                CURLOPT_TIMEOUT        => 20,          // timeout on response
                CURLOPT_POST            => 1,            // i am sending post data
                CURLOPT_POSTFIELDS     => null,    // this are my post vars
                CURLOPT_SSL_VERIFYHOST => 0,            // don't verify ssl
                CURLOPT_SSL_VERIFYPEER => false,        //
                CURLOPT_VERBOSE        => 1,
                CURLOPT_HTTPHEADER     => array(
                    'account_id:mr.125620728',
                    'api_key:d36edshc876f0p5bjge2jujr45'
                )

        );

        curl_setopt_array($ch,$options);
        $data = curl_exec($ch);
        $curl_errno = curl_errno($ch);

        curl_close($ch);
        return $data;
    }

but i am getting an error Not Found. i have tried many functions but invain. looks like having problem in passing my headers

In documentation its written something like this

curl –i -u account_id:api_key "https://xecdapi.xe.com/v1/account_info/"

but not getting information

Thanks

Regards

Danish Ali
  • 11
  • 1

2 Answers2

0

The switch -u account_id:api_key is to specify a username:password. From curl --help

 -u, --user USER[:PASSWORD]  Server user and password

So you need to authenticate as mr.125620728 / d36edshc876f0p5bjge2jujr45

You haven't specified what authentication schemes the XE API supports, but suppose it's Basic Authentication, then you can use

CURLOPT_USERPWD => $username . ":" . $password

where in your case $username=mr.125620728 and $password=d36edshc876f0p5bjge2jujr45

Also see How do I make a request using HTTP basic authentication with PHP curl?

Spangen
  • 4,420
  • 5
  • 37
  • 42
0

I know i am late but below is a working example, Just change your account ID and api Key

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://xecdapi.xe.com/v1/account_info");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

curl_setopt($ch, CURLOPT_USERPWD, 'apifixer.com7390' . ':' . 'miso4ofghfghfh1jbp733jndg');

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo $result;