I need to make a API request using CURL, the request are as follows:
{
"source":"0",
"custom":true,
"credit":"2",
"filetype":"2",
"ustate":"jkghlyt",
"service":"1234",
"templateid":"632",
"retryatmpt": 1,
"retryduration": 1,
"custretry": 1,
"refno":true,
"mslist":[{"phone1":"XXXXXXXXXXX","phone2":"XXXXXXXXXX"}]
}
I have the following PHP CURL code:
$phone1 = "XXXXXX";
$phone2 ="XXXXXXX";
//CURL
$url = 'http://api-ip-XXXX';
$param = array('source' => '0',
'custom' => true,
'credit' => '2',
'filetype' => '2',
'ustate' => 'jkghlyt',
'service' => '1234',
'templateid' => '632',
'retryatmpt' => '1',
'retryduration' => '1',
'custretryatmpt' => '1',
'refno' => true,
'mslist' => array(
urlencode($phone1),
urlencode($phone2)
)
);
$url = $url . "?" . http_build_query($param, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);
curl_close($ch);
I am confused regarding adding $phone1 & $phone2. It is not correct.
Requesting help from experts.
Related
I am using the following 'suggested' code to post a test order to Bybit.
(https://github.com/bybit-exchange/api-usage-examples/blob/master/api_demo/futures/Encryption.php)
<?php
function get_signed_params($public_key, $secret_key, $params) {
$params = array_merge(['api_key' => $public_key], $params);
ksort($params);
//decode return value of http_build_query to make sure signing by plain parameter string
$signature = hash_hmac('sha256', urldecode(http_build_query($params)), $secret_key);
return http_build_query($params) . "&sign=$signature";
}
$params = [
'symbol' => 'BTCUSDT',
'side' => 'Buy',
'order_type' => 'Limit',
'qty' => '1',
'price' => '30000',
'time_in_force' => 'GoodTillCancel',
'reduce_only' => false,
'close_on_trigger' => false,
'timestamp' => time() * 1000,
'position_idx' => 0
];
//$url = 'https://api-testnet.bybit.com/private/linear/order/create';
$url = 'https://api.bybit.com/v2/private/order/create';
$public_key = 'my_key_is_here_in_my_code';
$secret_key = 'my_secret_key_is_here_in_my_code';
$qs=get_signed_params($public_key, $secret_key, $params);
$curl_url=$url."?".$qs;
$curl=curl_init($curl_url);
echo $curl_url;
curl_setopt($curl, CURLOPT_URL, $curl_url);
#curl_setopt($curl, CURLOPT_POSTFIELDS, $qs);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
#curl_setopt($curl, CURLOPT_PROXY,"127.0.0.1:1087");
$response=curl_exec($curl);
echo $response;
However, I receive the following within the response: validation for 'symbol' failed on the 'symbol' tag"
https://api.bybit.com/v2/private/order/create?api_key=XXXXXX_my_key_XXXXX&close_on_trigger=0&order_type=Limit&position_idx=0&price=30000&qty=1&reduce_only=0&side=Buy&symbol=BTCUSDT&time_in_force=GoodTillCancel×tamp=1647644020000&sign=0e08e9f9be4cf5e4d7b1294d769ab4bf3b5b79ae9f92bab717670b3d95be0672{"ret_code":10001,"ret_msg":"Param validation for 'symbol' failed on the 'symbol' tag","ext_code":"","ext_info":"","result":null,"time_now":"1647644020.389465","rate_limit_status":99,"rate_limit_reset_ms":1647644020387,"rate_limit":100}
Could somebody pls suggest why Bybit is not recognising the 'BTCUSDT' symbol as expected. As everything seems setup on the exchange. Many thanks for your help.
BTCUSDT is not a valid symbol as per the documenation. These are the list of valid symbols that you can use.
I am trying to retrieve information from an API. The API requires authentication in order to access it. I have the tried the following, but it says that the Authentication has failed. I already confirmed that the credentials are correct, so that is not the problem. Any suggestions?
$pro = '0000000000';
$userName = 'userName';
$password = 'password';
$userPass = $userName.':'.$password;
$host = 'https://wardtlctools.com/wardtrucking/webservices/imaging';
$post = array(
'User' => array(
'UserName' => $userName,
'Password' => $password
),
'Reference' => array(
'RefNo' => $pro,
'RefType' => 'WARDPRO',
'DelMethod' => 'Link',
'Documents' => array(
'DocType' => 'BL',
'DocType' => 'DR'
)
)
);
$ch = curl_init($host);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_USERPWD, $userPass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($ch);
curl_close($ch);
print_r($return);
This is the documentation from the provider's website.
Hi I implement PayPal DoDirectPayment in my website, I want to required expire date And CVV but payment taking without those with this warning "This transaction was approved. However, the Card Security Code provided had too few, too many, or invalid character types but, as per your account option settings, was not required in the approval process"
I'm using PHP.
My Code is
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
$request = array
(
'METHOD' => 'DoDirectPayment',
'USER' => 'sell3_api1.pay.com',
'PWD' => '75DQHCABLDFSDF',
'SIGNATURE' => 'AFcWxV21C7fd0asdasdCpasdsdAtxzafSFsaKZ3unSUBjX9r-',
'VERSION' => '55.0',
'PAYMENTACTION' => 'Sale',
'FIRSTNAME' => $current_user->user_login,
'LASTNAME' => '.',
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'ACCT' => $acct,
'CREDITCARDTYPE'=>
'EXPDATE' => $month.$year,
'CVV2' => $cvv,
'AMT' => $amt,
'CURRENCYCODE' => 'USD',
);
$nvp_string = '';
foreach ($request as $key => $value) {
$nvp_string .= '&'.$key.'='.urlencode($value);
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
$result = curl_exec($curl);
curl_close($curl);
parse_str($result);
How can I solve It.
I am able to get the GET request working but having issues related to authentication in POST and PUT request. I am getting the error "You must log in before using this part of Bugzilla". I have provided the correct username and password. I have tried CURLAUTH_ANY as well as CURLAUTH_BASIC. I have tried both PUT and POST request. Any help is appreciated.
$url ="http://localhost:8080/bugzilla/rest/bug/2";
$apikey = "IZC4rs2gstCal0jEZosFjDBRV9AQv2gF0udh4hgq";
$data = array(
"product" => "TestProduct",
"component" => "TestComponent",
"version" => "unspecified",
"summary" => "This is a test bug - please disregard",
"alias" => "SomeAlias",
"op_sys" => "All",
"priority" => "P1",
"rep_platform" => "All"
);
$str_data = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$str_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-Type: application/json", "Accept: application/json"));
$username = 'ashish.sureka#in.abb.com';
$password = 'abbincrc';
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo $result
Following code solved my problem. I have written a blog on it which might be useful to others encountering the same problem.
<?php
$url = 'http://localhost:8080//bugzilla/xmlrpc.cgi';
$ch = curl_init();
$header = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt_array($ch, $header);
$bugreport = array(
'login' => 'ashish.sureka#in.abb.com',
'password' => 'abbincrc',
'product' => "TestProduct",
'component' => "TestComponent",
'summary' => "Bug Title : A One Line Summary",
'assigned_to' => "ashish.sureka#in.abb.com",
'version' => "unspecified",
'description' => "Bug Description : A Detailed Problem Description",
'op_sys' => "All",
'platform' => "All",
'priority' => "Normal",
'severity' => "Trivial"
);
$request = xmlrpc_encode_request("Bug.create", $bugreport);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_exec($ch)
?>
I was trying to retrieve data from remote server but it wasn't working & sending empty data. Here is the code that I tried:
define('WWW_PATH', dirname(__FILE__) . '/../..');
set_include_path(implode(PATH_SEPARATOR, array(realpath(WWW_PATH . '/library'), get_include_path())));
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Zend_');
$data = array(
'sr' => '3',
'et' => '3',
'exam' => 'ssc',
'year' => '2007',
'board' => 'dhaka',
'roll' => '494548'
);
$client = new Zend_Http_Client();
$client->setUri('http://www.educationboardresults.gov.bd/regular/result.php');
$client->setParameterPost($data);
$response = $client->request('POST');
$result = array('data'=>$response->getBody());
echo json_encode($result);
When I tried to echo the result it's redirecting to index.php page. Any suggestion how to get data.
I tried with curl but same problem here also :(
$post_data['sr'] = '3';
$post_data['et'] = '3';
$post_data['exam'] = 'ssc';
$post_data['year'] = '2007';
$post_data['board'] = 'dhaka';
$post_data['roll'] = '494548';
foreach ( $post_data as $key => $value)
{
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);
$curl_connection = curl_init('http://www.educationboardresults.gov.bd/regular/result.php');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_POST, 1);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($curl_connection);
curl_close($curl_connection);
//var_dump($result);
$data= array('data'=>$result);
echo json_encode($data);
and
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => "http://www.educationboardresults.gov.bd/regular/result.php",
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => array(
'sr' => '3',
'et' => '3',
'exam' => 'ssc',
'year' => '2007',
'board' => 'dhaka',
'roll' => '494548',
),
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
$data= array('data'=>$result);
echo json_encode($data);
I think this is because of the authentication process in http://www.educationboardresults.gov.bd. When i tried to access the url in the browser it is redirecting to the www.educationboardresults.gov.bd/regular/index.php. You have to use $client->setAuth(); method to login to the site and then get the response body. I haven't used it personally, but Zend_Http_Client - Advanced Usage will give a better idea on that.