Im trying to get all cities of a specific country from an API(https://countriesnow.space/). Im using Php and curl but the result says:
{
"error": true,
"msg": "missing param (country)"
}
Im using a script which is given by but it does not work: https://documenter.getpostman.com/view/1134062/T1LJjU52#4829d16f-0f4e-43ec-886e-68ebad1221d8
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://countriesnow.space/api/v0.1/countries/cities',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"country": "nigeria"
}',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Could anyone tell me whats wrong here? Really cant tell whats the issue.
cURL will automatically set the Content-Type to application/x-www-form-urlencoded, when you pass a string value for CURLOPT_POSTFIELDS.
But this is not supposed to be form data, but JSON. Add
CURLOPT_HTTPHEADER => ['Content-Type: application/json']
to your cURL options, to let the API know you are in fact sending JSON.
Related
The goal is to do a "POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA" so right now I'm trying to do a createFeedDocument which I believe is the 1st step.
There's few questions about this but none in PHP curl.
I spent hours....HOURS and still can't figure it out..
I get error:
"message": null,
"code": "InvalidInput"
I even tried removing "contentType" from the URL and put it in the header, but then I get error msg: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method."
Please....please is there anyone out there that knows what I need to change with code below?
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://sellingpartnerapi-na.amazon.com/feeds/2021-06-30/documents?contentType=text/tab-separated-values;charset=UTF-8',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'x-amz-access-token: the token<hidden>',
'X-Amz-Date: 20230125T073105Z',
'Authorization: AWS4-HMAC-SHA256 Credential=The_AccessKey/20230125/us-east-1/execute-api/aws4_request, SignedHeaders=accept;host;x-amz-access-token;x-amz-date, Signature=a6e8bdf306ea24438978a5fff961d08fc65d06c10f43c782af15a6a60<hidden>'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
I am trying to add a record to the database with POST operation via API and I generated the attached code from Postman.
On Postman, the process goes without any problem and user registration takes place.
But when I try to generate the code as "PHP cURL" via Postman and run it on PHP, I get the relevant error.
HTTP Error 411. The request must be chunked or have a content length.
I defined POSTFIELDS as array, calculated Content-Length using strlen function and added it to Headers. But it didn't work.
My PHP code;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://xxx.xxx/xxx/xxx/xxx',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"TokenKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"EmployeeList": [
{
"Example1": "1",
"Example2": "somedata2",
"Example3": "somedata3",
"Example4": "somedata4",
"Example5": "somedata5",
"Example6": "somedata6",
"Example7": "somedata7",
"Example8": "somedata8",
"Example9": "somedata9",
"Example10": "somedata10",
"Example11": "somedata11",
"Example12": "somedata12",
"Example13": "somedata13",
"Example14": "somedata14",
"Example15": "somedata15",
"Example16": "somedata16",
"Example17": "somedata17",
"Example18": "somedata18",
"Example19": "somedata19",
"Example20": "somedata20",
"Example21": "somedata21",
"Example22": "somedata22",
"Example23": "somedata23",
"Example24": "somedata24",
"Example25": "somedata25",
"Example26": "somedata26",
"Example27": "somedata27",
"Example28": "somedata28",
"Example29": "somedata29",
"Example30": "somedata30",
"Example31": "somedata31",
"Example32": null,
"Example33": null,
"Example34": null,
"Example35": "2022-12-06 22:05:22",
"Example36": false,
"Example37": true
}
]
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
echo "<br>";
echo $statusCode;````
I am trying to get the JSON data from a Website called
"https://thesimpsonsquoteapi.glitch.me/"
It has some sort of protection and take a while to open.
The Problem. After the site is loaded, you get access to some API calls like
"https://thesimpsonsquoteapi.glitch.me/quotes"
If I try it in Postman, I get back the right JSON response also if I open it up in the browser.
But if I try the to load the Data via curl in PHP i get the html code back from the first protection side. What can I do to get the JSON like in Postman.
$curl = curl_init();
$url = 'https://thesimpsonsquoteapi.glitch.me/quotes?count=1';
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
thx for any help
I'm trying to build a Connector to Dynamics 365 Business Central but I'm having problems getting the data. Please help me figure out why when I send a GET request using cURL and PHP, it produces the following output:
�S[O�0�+(��&��qB��i�t�F/���=�ا��Ďb�}N�"&�M�����������8�0% �;
Here is my code:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.businesscentral.dynamics.com/{tenantID}/customers/?$filter=displayName%20eq%20'Shawn%20Test'",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: {Auth Code}"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
It seems like a character encoding issue, or maybe you are receiving binary data.
What is this endpoint supposed to return? Check the response headers, it might give you a clue.
This is an encoding problem, try to remove CURLOPT_ENCODING line from your request or try to choose different encoding from your browser
I want to show my data on my CRM using PHP with curl and also using API.
If there is any other method. You can kindly show it to me
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://b.maxmind.ma/api/leads",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authtoken: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyfdfdiOjE1ODEwODk2MjJ9.Selc36cmT3XyXH6cGdJ3SN-332kx7"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
the response show : error code: 1020
I think the problem is that the website you are trying to request is protected by Cloudflare.
When i try by the postman , this is the header response a get :
The error code 1020 you got is from cloudflare .
First, you can try using this solution that bypasses the Cloudflare problem
KyranRana/cloudflare-bypass
If not working, in this case, you must contact the site owner to remove the block (more here)