I am trying to call an external API with a POST method which is working fine on Postman, but when trying to implement it in a custom module using drupal_http_request()
I am getting a strange error.
The requested resource does not support http method 'GET'.
This is the extracted cURL command from Postman: curl --location --max-time 2000 --request POST 'https://example.com/api' --header 'Authorization: [token]' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'subject=Lead XXX' --data-urlencode 'firstName=XXX' --data-urlencode 'lastName=XXX' --data-urlencode 'Email=test@test.test' --data-urlencode 'Mobile=XXX' --data-urlencode 'Interest=XXX ' --data-urlencode 'meetingdate=2020-04-20T13:00:00.000'
.
This is the code I am using.
$url = 'https://example.com/api';
$data = [
'subject' => 'XXX',
'firstName' => 'XXX',
'lastName' => 'XXX',
'Email' => 'test@test.test',
'Mobile' => 'XXXX',
'Interest' => 'Testing',
'meetingdate' => '2020-04-20T13:00:00.000',
];
$options = [
'method' => 'POST',
'headers' => array(
'Content-Type' => 'application/x-www-form-urlencoded',
'Authorization' => [token],
),
'data' => json_encode($data),
];
$request = drupal_http_request($url, $data);
I have the feeling this must be easy, but I couldn't figure out what I'm doing wrong. I search the documentation, searched here with no luck.
Any hit will be appreciated.
drupal_http_request($url, $options);
– Leigh May 12 '20 at 11:50