I am receiving the No handler found for uri [/<url>/<url>] and method [PUT] error when sending a request via Elasticsearch.
I am using POST, not PUT, so I do not need to use _id. Using POST is mandatory. The following request worked until adding 'archive' index.
$params = [
'index' => 'servers',
'type' => 'servers',
'body' => [
'servername' => $servername,
'ip' => $ip,
'location' => $location,
'ping' => $ping,
'archive' => 0
]
];
$response = $client->index($params);
Rebuilding the index and changing archive to a string, as opposed to an int, resolved the issue.
$params = [
'index' => 'servers',
'type' => 'servers',
'body' => [
'servername' => $servername,
'ip' => $ip,
'location' => $location,
'ping' => $ping,
'archive' => "0"
]
];
$response = $client->index($params);
Related
I am using queue for the first time in Laravel.
I can't seem to get it work. I am sending an email and also calling a url with curl ().
I have even tried file_content_get(), yet it doesn't seem to work. The email seems to work just fine...
My question is: is there a different approach to calling an endpoint using Queue?
public function handle()
{
$email = new Airtime();
$ch = curl_init("some-url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// exec($ch);
curl_exec($ch);
Mail::to($this->details['email'])->send($email);
}
The email gets sent, but the curl is completely ignored.
Unless the function is disabled in php.ini in disable_functions directive or something blocks your requests on the network level, there is no specific reason this should not be executed. Are you sure that the endpoint being called did not in fact receive the request?
Calling remote endpoints from queues works fine for me. I just tested it now with a snippet below:
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
$result = \Http::get('https://api.publicapis.org/entries')->json('entries');
\Log::info($result);
}
Result:
[2022-10-01 11:12:25] local.INFO: array (
0 =>
array (
'API' => 'AdoptAPet',
'Description' => 'Resource to help get pets adopted',
'Auth' => 'apiKey',
'HTTPS' => true,
'Cors' => 'yes',
'Link' => 'https://www.adoptapet.com/public/apis/pet_list.html',
'Category' => 'Animals',
),
1 =>
array (
'API' => 'Axolotl',
'Description' => 'Collection of axolotl pictures and facts',
'Auth' => '',
'HTTPS' => true,
'Cors' => 'no',
'Link' => 'https://theaxolotlapi.netlify.app/',
'Category' => 'Animals',
),
2 =>
array (
'API' => 'Cat Facts',
'Description' => 'Daily cat facts',
'Auth' => '',
'HTTPS' => true,
'Cors' => 'no',
'Link' => 'https://alexwohlbruck.github.io/cat-facts/',
'Category' => 'Animals',
),
3 =>
array (
'API' => 'Cataas',
'Description' => 'Cat as a service (cats pictures and gifs)',
'Auth' => '',
'HTTPS' => true,
'Cors' => 'no',
'Link' => 'https://cataas.com/',
'Category' => 'Animals',
)
I'm trying to upload to s3 based on the documentation in Eventbrite but I'm getting nowhere. I think it's down to the structure of my request but I've tried multiple different things and nothing is really working and I get a 'Bucket POST must contain a field named 'key' error.
The instructions are here, so it provides you with a presigned POST object, but I can't figure out how to then provide those details in Guzzle
https://www.eventbrite.com/developer/v3/resources/uploads/
I would use the s3client but I don't think it's suitable, as I do not have the region name.
So this is the array back from EB, as given in the documentation
$postFields = [
'key' => $post_args['key'],
'AWSAccessKeyId' => $post_args['AWSAccessKeyId'],
'bucket' => $post_args['bucket'],
'acl' => $post_args['acl'],
'signature' => $post_args['signature'],
'policy' => $post_args['policy'],
];
and I've tried various structures:
$args = [
'query' => $postFields,
'multipart' => [
[
'name' => $instructions_response['body']['file_parameter_name'],
'Content-type' => 'multipart/form-data',
'contents' => $image,
]
],
]
Or
$args = [
'multipart' => [
[
'key' => $post_args['key'],
'AWSAccessKeyId' => $post_args['AWSAccessKeyId'],
'bucket' => $post_args['bucket'],
'acl' => $post_args['acl'],
'signature' => $post_args['signature'],
'policy' => $post_args['policy'],
'name' => $instructions_response['body']['file_parameter_name'],
'Content-type' => 'multipart/form-data',
'contents' => $image,
]
],
];
Or
$args = [
'key' => $post_args['key'],
'AWSAccessKeyId' => $post_args['AWSAccessKeyId'],
'bucket' => $post_args['bucket'],
'acl' => $post_args['acl'],
'signature' => $post_args['signature'],
'policy' => $post_args['policy'],
'multipart' => [
[
'name' => $instructions_response['body']['file_parameter_name'],
'Content-type' => 'multipart/form-data',
'contents' => $image,
]
],
];
(Plus a bunch of more spurious ones that I can't remember anymore)
Anyway, I'm stuck. I just can't think how this POST data is meant to be structured for it to post to S3. I've gone down the rabbit hole with Xdebug and it's still not clear what is even going on when it makes the request tbh
Request called like so
$upload_response = $this->client->request('POST', $upload_url, $args);
UPDATE: It was pointed out to me that whilst 'key' is lowercase in the error message and what comes back from aws, it's capitalised in the documentation. I changed it to 'Key' and now I get 'Conflicting query string parameters: acl, policy'
I'm in the process of convert from cURL to Guzzle, and got most of it working.
GET requests working great etc.
My problem is the POST request, getting Schema validation errors.
It works in curl, so I'm a bit confused... well, a lot.
Client error: `POST https://restapi.e-conomic.com/customers` resulted in a `400 Bad Request` response:
{"message":"Schema validation failed.","errorCode":"E00500"
I hope one of you can tell me, if I did something wrong in the convert? Maybe my arrays needs to be formatted in another way.
This is my old working "cURL code":
$data = array(
'name' => 'Test User',
'address' => 'Road 123',
'email' => 'morten#domain.com',
'zip' => '9000',
'city' => 'City',
'country' => 'Danmark',
'corporateIdentificationNumber' => '12345678',
'customerGroup' => array(
'customerGroupNumber' => 1
),
'currency' => 'DKK',
'paymentTerms' => array(
'paymentTermsNumber' => 1
),
'vatZone' => array(
'vatZoneNumber' => 1
)
);
$options = array(
CURLOPT_URL => 'https://restapi.e-conomic.com/customers',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
'X-AppSecretToken:[removed]',
'X-AgreementGrantToken:[removed]',
'Content-Type:application/json; charset=utf-8'
),
CURLOPT_POSTFIELDS => json_encode($data)
);
curl_setopt_array($ch, $options);
This is my new "guzzle code", that is causing me problems:
$client = new GuzzleHttp\Client();
$headers = [
'X-AppSecretToken' => '[removed]',
'X-AgreementGrantToken' => '[removed]',
'Content-Type' => 'application/json;charset=utf-8',
'debug' => false
];
$form_params = [
'name' => 'Test User',
'address' => 'Road 123',
'email' => 'test#email.dk',
'zip' => '9000',
'city' => 'City',
'country' => 'Danmark',
'corporateIdentificationNumber' => '12345678',
'customerGroup' => [
'customerGroupNumber' => 1
],
'currency' => 'DKK',
'paymentTerms' => [
'paymentTermsNumber' => 1
],
'vatZone' => [
'vatZoneNumber' => 1
]
];
$response = $client->post('https://restapi.e-conomic.com/customers', [
'headers' => $headers,
'form_params' => $form_params
]);
I tried to use the "body" parameter, as stated in the Guzzle documentation, but received this error:
Passing in the "body" request option as an array to send a POST request has been deprecated. Please use the "form_params" request option to send a application/x-www-form-urlencoded request, or the "multipart" request option to send a multipart/form-data request.
I'm not sure what to do and really hope, that one of you guys will tell me what i'm doing wrong.
https://restapi.e-conomic.com/schema/customers.post.schema.json#_ga=2.167601086.1488491524.1500877149-796726383.1499933074
https://restdocs.e-conomic.com/#post-customers
I had to post the quest as json:
$response = $client->post('https://restapi.e-conomic.com/customers', [
'headers' => $headers,
'json' => $form_params
]);
i have this perfectly working curl command:
curl -i --data "site=walletgroove.com&placement=above&device=desktop&source=*&campaign=*&url=*&country=*&active=1" http://10.0.0.38/adserver/src/public/api/rule
which i tried to execute with guzzle but for some reason i keep getting error from my code, an exception to be more accurate. this exception is thrown when params are not passed properly.
this is one of few tries i had:
public function testApi_postRule()
{
$client = new Client();
$client->post('http://10.0.0.38/adserver/src/public/api/rule',[ 'query' => [
'site' => 'walletgroove.com',
'placement' => 'guzzle_unique_placement',
'device' => 'desktop',
'source' => 'guzzource',
'campaign' => '*',
'country' => '*',
'url' => '*',
'active' => '1'
]]);
}
any idea what am i doing wrong here??
You are passing the query parameter, which appends a query string instead of sending in the request body. For a POST request, you probably want to use form_params as shown in the documentation.
$client->post('http://10.0.0.38/adserver/src/public/api/rule', [
'form_params' => [
'site' => 'walletgroove.com',
'placement' => 'guzzle_unique_placement',
'device' => 'desktop',
'source' => 'guzzource',
'campaign' => '*',
'country' => '*',
'url' => '*',
'active' => '1'
]
]);
I think I just have a problem with my syntax. I can add one user at a time no problem just fine:
$client = new \GuzzleHttp\Client();
$data = [
'api_user' => $this->api_user,
'api_key' => $this->api_key,
'list' => 'listname',
'data' => json_encode(array('email' => 'example#email.com', 'name' => 'example'))
];
$client->post('https://api.sendgrid.com/api/newsletter/lists/email/add.json', ['body' => $data]);
Now I can't figure out how to specify multiple emails using guzzle. Sendgrid's docs (https://sendgrid.com/docs/API_Reference/Marketing_Emails_API/emails.html) show a curl example using multiple data[]={..json..} params, which I can't figure out how to specify with Guzzle.
So far I've tried a multidimensional array, which doesn't work because I believe I need to pass them as separate params, not as one:
$data = [
'api_user' => $this->api_user,
'api_key' => $this->api_key,
'list' => 'listname',
'data' => json_encode(array(
array('email' => 'example1#email.com', 'name' => 'example1'),
array('email' => 'example2#email.com', 'name' => 'example2'),
array('email' => 'example3#email.com', 'name' => 'example3')
))
];