How to get order via linnwork api with laravel php - php

I am trying to get the orders from Linnwork API. But I am not able to get anything. I am using laravel framework to do this task and here the error I am getting.
EDIT:
No it's not a duplicate question file_get_content is not the main issue for getting the result I can use curl but the problem is linnwork API format its also giving error like "token is wrong". and I have checked the linnwork API documentation to see what's the mandatory fields to pass but there is no luck.
public function getLinnworkOrders()
{
date_default_timezone_set('Europe/London');
$userId = Auth::id();
$tag = Tag::where('user_id', $userId)->where('market', 'Linnwork')->orderBy('created_at', 'desc')->first();
$url = 'https://eu1.linnworks.net/api/Orders/GetOpenOrders';
$token = $tag->token;
$opts = array(
'http'=>array(
'method'=>"POST",
'header'=> "Content-Type: application/x-www-form-urlencoded",
"Accept: application/json",
"url: https://eu-ext.linnworks.net//api/Orders/GetOpenOrders HTTP/1.1",
"Host: eu-ext.linnworks.net",
"Connection: keep-alive",
"Origin: https://www.linnworks.net",
"Accept-Language: en",
"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36",
"Referer: https://www.linnworks.net/",
"Accept-Encoding: gzip, deflate",
"Authorization: e2673790a8d866ae30968ea189add96a",
'content' => '',
'ignore_errors' => true
)
);
$count_json = file_get_contents($opts);
$count_json = json_decode($count_json);
print_r($count_json);die;
}
And its the error i am getting
"file_get_contents() expects parameter 1 to be a valid path, array given"

Related

PHP Read Online Excel File Without Download The File

I am creating a web stock apps.
I want to read this Excel or Google Sheet File in this link:
Link To Report
Without need to download the file first.
Is it possible for PHP to read and choose the sheet then read entire row and column in online ?
What library I should use ?
I try to use phpspreadsheet but I cannot make it. Not sure if i do it wrong or not.
Also i try to use Google Sheet API. But in the link i cannot find the google spreadsheet id.
So what is the solution in here to read the excel or google spreadsheet online using php ?
Update :
Suggest from #ADyson to use a same header to get the data download by php.
So this is my code :
function dfCurl($url){
$ch = curl_init($url);
$dir = '../';
$fileName = basename($url);
$saveFilePath = $dir . $fileName;
$fp = fopen($saveFilePath, 'wb');
$headers = [
':authority: www.idx.co.id',
':method: GET',
':path: /Portals/0/StaticData/ListedCompanies/Corporate_Actions/New_Info_JSX/Jenis_Informasi/01_Laporan_Keuangan/02_Soft_Copy_Laporan_Keuangan//Laporan%20Keuangan%20Tahun%202021/TW1/AALI/FinancialStatement-2021-I-AALI.xlsx',
':scheme: https',
'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'accept-encoding: gzip, deflate, br',
'accept-language: en-AU,en;q=0.9,id-ID;q=0.8,id;q=0.7,zh-CN;q=0.6,zh;q=0.5,ja-JP;q=0.4,ja;q=0.3,en-GB;q=0.2,en-US;q=0.1',
'cache-control: no-cache',
'cookie: _ga=GA1.3.1396311216.1625813381; skipFeedback=1; __cf_bm=mF3lXNPMKeLe1xFzY5eKQM1TFN.yz7lxgWMJEYWBcjA-1635412963-0-AUMv9HWMpGhIN6c7eDVT++ok0dYE1NL+PyRJBpNUfZviT8bNS5Zm4UQjAm7gUJad4Qv7h+Q9ak+u/Q18tGDx0pU=',
'pragma: no-cache',
'referer: https://www.idx.co.id/perusahaan-tercatat/laporan-keuangan-dan-tahunan/',
'sec-ch-ua: "Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
'sec-ch-ua-mobile: ?1',
'sec-ch-ua-platform: "Android"',
'sec-fetch-dest: document',
'sec-fetch-mode: navigate',
'sec-fetch-site: same-origin',
'sec-fetch-user: ?1',
'upgrade-insecure-requests: 1',
'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Mobile Safari/537.36'
];
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, $headers);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
And I call using :
public function Export() {
// Initialize a file URL to the variable
$url = 'https://www.idx.co.id/Portals/0/StaticData/ListedCompanies/Corporate_Actions/New_Info_JSX/Jenis_Informasi/01_Laporan_Keuangan/02_Soft_Copy_Laporan_Keuangan//Laporan%20Keuangan%20Tahun%202021/TW1/AALI/FinancialStatement-2021-I-AALI.xlsx';
dfCurl($url);
}
But unfortunetly I still cannot download the xlsx file properly.
I just got a 1 kb file and when open the file i got error from excel.
So what is the correct way to download from url using php ?
The link is :
https://www.idx.co.id/Portals/0/StaticData/ListedCompanies/Corporate_Actions/New_Info_JSX/Jenis_Informasi/01_Laporan_Keuangan/02_Soft_Copy_Laporan_Keuangan//Laporan%20Keuangan%20Tahun%202021/TW1/AALI/FinancialStatement-2021-I-AALI.xlsx
Thank You
Finally I can download using php from that site.
All I want to do is use a curl :
function dfCurl($url){
$ch = curl_init($url);
$dir = '../';
$fileName = basename($url);
$saveFilePath = $dir . $fileName;
$fp = fopen($saveFilePath, 'wb');
$headers = [
'authority: www.idx.co.id',
'method: GET',
'scheme: https',
'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'cache-control: no-cache',
'pragma: no-cache',
'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Mobile Safari/537.36',
'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
];
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
And that's all.

How to send the next cookies in get request?

I receive 503 error, but if i send it from inspect element its fine.
The code worked for me before, but in the last few hours the specific website added cf_clearance and I need to add it to the request as well
How do i send the both cookies?
$opts = array(
'http'=>array(
'method'=>"GET",
'proxy'=>"",
'header'=> "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0\r\n" .
"Cookie: cf_clearance=3de18fcd39d55ce82d9db-1529352303-31536000; PHPSESSID=oahfun4m7vi3edd71\r\n"
));
$context = stream_context_create($opts);
$url = "http://website.com";
$data = file_get_contents($url, false, $context);
echo $data;
There's a pretty good example in the documentation.
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
Add line breaks and concatenate. Your example right now should be resulting in a syntax error because you are not concatenating the two strings.

Lumen POST Issue

I'm working on setting up a quick REST service with Laravel Lumen. My very simple route list:
$router->group(['prefix' => 'v1', function() use ($router){
$router->get('status', function(){
return "ready";
});
$router->post('reading', function(){
return "Hello";
});
});
I installed https://github.com/appzcoder/lumen-route-list and when I run it, I see my two routes. When I issue my POST from my client (via C), which is:
#define POST_THING "POST /v1/reading HTTP/1.1\r\n"\
"Accept: */*\r\n"\
"Refer: exampledomain.ca\r\n"\
"Accept-Language: */*\r\n"\
"Content-Type: application/x-www-form-urlencoded\r\n"\
"Accept-Encoding: */*\r\n"\
"User-Agent: Mozilla/5.0\r\n"\
"Pragma: no-cache\r\n"\
"Connection: keep-alive\r\n"\
"key=101abc\r\n"\
"Content-Length: 11\r\n"\
"\r\n"
I get back a 400:
[02/Mar/2018:08:51:43 -0500] "POST /v1/reading HTTP/1.1" 400 3170 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36"
and from my client I get:
400 Bad Request
Bad Request Your browser sent a request that this server could not
understand.(Shortened)
The GET route works fine and I get "ready", before I try and preform the POST, I'm I doing something wrong?
Thanks
D
Figured out my issue! I changed the POST to:
#define POST_THING "POST /v1/reading HTTP/1.1\r\n"\
"Accept: */*\r\n"\
"Refer: exampledomain.ca\r\n"\
"Accept-Language: */*\r\n"\
"Content-Type: application/x-www-form-urlencoded\r\n"\
"Accept-Encoding: */*\r\n"\
"User-Agent: Mozilla/5.0\r\n"\
"Pragma: no-cache\r\n"\
"Connection: keep-alive\r\n"\
"Content-Length: 10\r\n"\
"\r\n"\
"key=101abc\r\n"
Now it works fine! Hopefully this helps some other people running into the same issue.

file_get_contents doesn't work with some links

I'm trying to take the content of a site by file_get_contents(), but it doesn't work. I already tried to follow these codes here, but it doesn't work.
This is the code I have:
$url = "https://www.cb01.uno/";
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n" . // check function.stream-context-create on php.net
"User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad
)
);
$context = stream_context_create($options);
echo $file = file_get_contents($url, false, $context);
It returns nothing. I tried with other site like https://www.w3schools.com and it works, so the problem isn't the HTTPS
EDIT: I tried this solution HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable and now it display:
Not Found
The requested URL /cdn-cgi/l/chk_jschl was not found on this server.

how to set ip in header and then run script with cron job?

i have script this code:
require_once 'Request2.php';
$request = new HTTP_Request2('http://fakevisit.blogfa.com/');
$request->setHeader(array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding: gzip, deflate',
'Accept-Language: en-US,en;q=0.5',
'Connection: keep-alive',
'Ip: 88.168.25.98',
'SomeBull: BeingIgnored',
'Referer: http://www.google.com',
'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'
));
$response = $request->send();
echo "Response body:\n" . $response->getBody();
The program is run once every 1 minute Is working correctly.
but in google analytics And other counter scripts Does not add to the visitors!
at this line
echo "Response body:\n" . $response->getBody();
The entire contents of the page with Script to display the number of visitors are displayed correctly in page.
Google Analytics and most others use Javascript to populate the hit. If you're calling this via Cron/Scheduled Tasks then you're doing a HTTP request and getting the response, but you aren't executing the Javascript for GA, therefore no hit is added.

Categories