CRM show data using PHP CURL - php

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)

Related

Problem to get Data with CURL from an API "*.glitch.me" Domain

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

WordPress JSON API AUTH with PHP Curl

I am working with wordpress and using this plugin https://wordpress.org/plugins/json-api-auth/ for JSON API Auth and I am trying to return success with curl in PHP but whenever I run the code I am getting {"status":"error","error":"Invalid username and\/or password."}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://example.com/api/auth/generate_auth_cookie/?username="abcd"&password="abcd"',
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);
echo $response;
?>
But when I put this in the browser url https://example.com/api/auth/generate_auth_cookie/?username=abcd&password=abcd I am getting success
{"status":"ok","cookie":"xyz","cookie_name":"xyzxyz","user":{"id":1,"username":"abcd","nicename":"abcd","email":"abcd#abcd.com","url":"","registered":"2020-09-10 10:42:41","displayname":"abcd","firstname":"abcd","lastname":"abcd","nickname":"abcd","description":"","capabilities":{"administrator":true},"avatar":null}}
Can you help me what I am doing wrong with curl in PHP?
Original version of CURLOPT_URL that I have used in code
CURLOPT_URL => 'https://example.com/api/auth/generate_auth_cookie/?username="'.$this->input->post('email').'"&password="'.$this->input->post('password').'"',
Remove the " from the cURL url query string. The WordPress PHP handling your request would read your username as "abcd" instead of abcd as you are trying to achieve.
CURLOPT_URL => 'https://example.com/api/auth/generate_auth_cookie/?username="abcd"&password="abcd"'
Should be
CURLOPT_URL => 'https://example.com/api/auth/generate_auth_cookie/?username=abcd&password=abcd'

Netsuite API throws 400 bad request

I am trying to connect with Netsuite Customer API but it throws "400 bad request"
Here is my code in PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://xxxxxxx-sb1.suitetalk.api.netsuite.com/services/rest/record/v1/customer/1",
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_FAILONERROR => true,
CURLOPT_SSL_VERIFYHOST=>false,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_HTTPHEADER => array(
"Authorization: OAuth realm=\"xxxxxxx_SB1\",oauth_consumer_key=\"consumer_key_xxxxxx\",oauth_token=\"auth_token_xxxxxxxx\",oauth_version=\"1.0\""
),
));
$response = curl_exec($curl);
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
}
var_dump($error_msg);
curl_close($curl);
var_dump($response);
?>
Here above code I copied from postman. In a postman, it returns data but when I copied code for php in a file it is not working, Could anyone suggest me where I am going to wrong ?
My localhost url : localhost/netsuite_api.php
For whatever reason, the netsuite API returns 400 even where it should be a 401 according to the docs.
From the docs about the Authentication, you need to send more fields (see page 169 following):
Authorization:
OAuth realm="12345",
oauth_consumer_key="4a3ff6c251a55057bb1e62d8dc8998a0366e88f3a8fe735265fc425368b0f154",
oauth_token="52cfe88fecf2e2b74e833e7dfc4cae79ff44c3ca9f696d61e2a7eac6c8357c3c",
oauth_nonce="qUwlmPvtGCS4sHJe8F7x",
oauth_timestamp="1462453273",
oauth_signature_method="HMAC-SHA1", oauth_version="1.0",

Requesting a cURL GET Request in PHP outputs garbage

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

AtTask API 'PUT' CURL Fails to Update

I have been working on some code to automate an update to a specific task in AtTask using the API. I am finding some problems using PHP's CURL request for a PUT command. Here is a copy of the code:
$updateURL = "https://[COMPANYURL].attask-ondemand.com/attask/api/v4.0/task?updates={'ID':'TASKID','name':'Ok. Here we go again','commitDate':'2015-10-27T17:30'}";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $updateURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => array(
"sessionid: " . $this->sessionId
),
));
$attask_update_json = curl_exec($curl);
The code executes with out any errors being reported, but the return response is blank. I have verified my URL using postman and it processes correctly, but I can not get the code to process in PHP. Any help would be appreciated.

Categories