File name doesnt read in the PHPcurl api - php-curl

I have a api integrated using phpcurl.Where there is upload file functionality .When using the PHP code to call a Webservices with the parameters.The file name doesnt get added
curl_setopt_array($curl, array(
CURLOPT_URL => "https://Xx.XXX.XXX.XX/demo/v1/uploadScannedDocs",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"preQualify\"\r\n\r\n" . $checkbox1 . "\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"demographicPid\"\r\n\r\n" . $patient_id . "\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"barcode\"\r\n\r\n" . $barcode . "\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"consentDate\"\r\n\r\n" . $consent_date . "\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"CSCDB_0523_TableDef.pdf\"\r\nContent-Type: false\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"hipa\"; filename=\"CSCDB_0523_TableDef.pdf\"\r\nContent-Type: false\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"medrioId\"\r\n\r\n" . $id . "\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=---011000010111000001101001",
"deviceid: 123",
"postman-token: 4655c7e4-f473-7383-6fd1-ef07ded61caf",
"token: 1234"
)));

Related

API Question - How to create relationships and query with multiple GET calls using cURL

I was just handed a project and not sure how to handle it. I have limited API experience, but have been able to pull the data using the code below. In this example I want to display a cruise sailing. I have an API endpoint url of https://api.website.com/sailing/123456 (example). This gives me a ton of data, but not everything i need. For example, it gives me the "supplier_id" (this would be something like 22). I want the supplier_name, so I can display "Carnival Cruise" instead of "22". Supplier_name is in another endpoint url - https://api.website.com/suppliers. This is where I am stuck. My thought is to bring in multiple GETS and then query it down. For example, If I brought in both endpoint URLs in this example and relate the two using supplier_id (exists in both examples), then I could bring in my Supplier Name. Am I way off here? I'm used to working with a DB and queries, so maybe I'm on the wrong path. Please help if you can. Thanks!
<?php
/* Sample call to get cruise sailings with filter/fields constraints */
$curl = curl_init();
$api_endpoint = "https://api.website.com/sailing/123456";
$api_key = "a57fecd04e71402fba73cb2e63a262aa";
$dataArray = array(
"start_at" => 1,
"max_return" => 170
);
$request_url = $api_endpoint . "?" . http_build_query($dataArray);
curl_setopt_array(
$curl,
array(
CURLOPT_URL => $request_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"accept: application/json",
"api_key: {$api_key}"
)
)
);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
/* SIMPLE DUMP OF DATA
echo $response;*/
}
$data = json_decode($response);
$total = $data->meta->total;
$startAt = $data->meta->start;
$maxReturn = $data->meta->count;
// Table view of data
echo '<table border=1><tr><th>Sailing ID</th><th>Title</th><th>Supplier ID</th><th>Supplier Name</th></tr>';
echo '<td>' .$item->sailing_id.'</td>';
echo '<td>' .$item->title.'</td>';
echo '<td>' .$item->supplier_id.'</td>';
echo '<td>' .$item->supplier_name.'</td></tr>';
echo '</table>';
?>

Mollie applicationfee's

for a customer I need to charge an applicationFee for each order that has been processed on their site from the sub customers. The whole code is working with authentication and everything.
But from the moment I'm adding:
'applicationFee' => $applicationFee
to the call I receive this error:
Error executing API call (422: Unprocessable Entity): Unable to process application request for this account. Documentation: https://docs.mollie.com/guides/handling-errors"
The content of "$applicationFee" is correct, that I was able to check already.
The $shop_mollie_data->profile_id containts the different websiteprofileId's found on the Mollie dashboard.
$provider = new MollieConnectProvider($request, $clientId, $clientSecret, $redirectUrl);
$newAccessToken = $provider->getRefreshTokenResponse($shop_mollie_data->refresh_token);
$mollie = new MollieApiClient();
$mollie->setAccessToken($newAccessToken['access_token']);
$payment = $mollie->payments->create([
'amount' => [
'currency' => 'EUR',
'value' => (string) (sprintf("%.2f", $order_total))
],
'description' => ucfirst($shop->name) . ' - Order #' . $order_nm,
'webhookUrl' => $url_callback,
'redirectUrl' => $url_success,
'method' => 'bancontact',
'locale' => $language_id,
'metadata' => [
"order_id" => $ref,
"shop id" => $shop->id
],
'profileId' => $shop_mollie_data->profile_id,
'testmode' => true,
'applicationFee' => $applicationFee
]);

How to make php api call to CloudFlare to Purge individual files by URL from cache

this code worked good to Purge All files from cache .
Example:
$authKey = "MyKEY";
$authEmail = "myEMAIL";
$zoneId = "MYZONEID";
$endpoint = "purge_cache";
$data = [
"purge_everything" => true
];
$url = "https://api.cloudflare.com/client/v4/zones/{$zoneId}/{$endpoint}";
$opts = ['http' => [
'method' => 'DELETE',
'header' => [
"Content-Type: application/json",
"X-Auth-Key: {$authKey}",
"X-Auth-Email: {$authEmail}",
],
'content' => json_encode($data),
]];
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
But I need Purge individual files by URL how can I do that via PHP ?
On api page I found this link: https://api.cloudflare.com/#zone-purge-individual-files-by-url
but I don't now how to make it via php ?
You need to pass an array with files - like explained on the API Docs
In your example that would be something like
$data = '{"files":[
"http://www.example.com/css/styles1.css",
"http://www.example.com/css/styles2.css",
"http://www.example.com/css/styles3.css"
]}';

Is it still possible to use Itunes Connect API endpoints instead of Java Reporter tool?

Prior to the newest Itunes Connect update all requests were HTTP requests made through Curl in our application. After the update, Apple is recommending to use their new reporter tool.
https://github.com/mikebarlow/itc-reporter I want to do something similar to this if possible. This supposedly works without the reporter tool and it looks like it is still just making HTTP requests. I won't use this code in my project because it requires us to update PHP version which we have planned for another time.
Is it possible to make simple HTTP requests using Curl to get data? I don't want to use Guzzle if I don't have to!
$json = '{"userid":"{{USERNAME}}","password":"{{PASSWORD}}","version":"2.0","mode":"Robot.XML","account":"{{VENDOR_ID}}","queryInput":"[p=Reporter.properties, Sales.getReport, {{VENDOR_ID}},Sales,Summary,Weekly,20170108]"}'
CURLOPT_URL => 'https://reportingitc-reporter.apple.com/reportservice/sales/v1',
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => array('Accept: text/xml, text/plain', 'Content-Type: text/xml, text/plain'),
CURLOPT_USERAGENT => 'Java/1.8.0_92',
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $json,
this is the request I've made while testing and when I run it I get the HTML response saying "Forbidden, You do not have access to this page"
I tried this while urlencoding username and password but I get the same result. I would love to be able to still get this data using Curl or we will have to work on adding the reporter tool into our application.
the postfield just needed to be changed accordingly
function build_json_request(, $access_token, $account_id,
$args_arr=array())
{
$args = $args_arr;
$json = array(
'accesstoken' => urlencode($access_token),
'version' => '2.2',
'mode' => 'Robot.XML',
'account' => $account_id
);
$queryInput = array(
'p=Reporter.properties',
array_shift($args)
);
if(! empty($args))
$queryInput[] = implode(',', $args);
$json['queryInput'] = '[' . implode(', ', $queryInput) . ']';
return json_encode($json);
}
$json = build_json_request('Sales.getReport', $access_token, $account_id, array('Sales.getReport', $vendor_id, 'Sales', 'Summary', 'Daily', $date) );
$output = process_curl(array(
CURLOPT_URL => 'https://reportingitc-reporter.apple.com/reportservice/sales/v1',
CURLOPT_HEADER => false,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => 'jsonRequest='.$json,
));

POST Request to Spotify Web Api using Laravel 5.2 Request

I've been looking into this for a while, but cant seem to find a solution, or atleast not none I understand.
The main question here is, Can I send a POST request with body and header to Spotify web API, using only Laravels 5.2 Request?
Maybe something like this.
$parameters = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'code' => $request->input('code'),
'grant_type' => 'authorization_code',
'redirect_uri' => 'http://localhost/callback',
);
$headers = array(
'Authorization' => 'Basic ' . base64_encode($client_id. ':' . '$client_secret'),
);
return redirect('https://accounts.spotify.com/api/token')->withInput($headers, $parameters);
Thanks in advance.