“options”: {
“url”: “https://api.endpoint”,
“method”: “POST”,
“dataType”: “json”,
“data”: “{{$_POST}}”
}
you could edit the action file directly. Open the json in the editor and change the data there in the code.
“data”:"{{$_POST}}"
“options”: {
“url”: “https://api.endpoint”,
“method”: “POST”,
“dataType”: “json”,
“data”: “{{$_POST}}”
}
you could edit the action file directly. Open the json in the editor and change the data there in the code.
“data”:"{{$_POST}}"
Sounds like you are trying to help with an answer, not ask a question, so I will leave this for @sitestreet as I don’t have any issues myself.
this will be useful for future use.
Thanks @s.alpaslan for the help.
If I edit the action file directly, will that get overwritten in the future if I make changes in Wappler?
no . but if you have multi form field (maybe 30 40 fields in your form ) .. you can use like this syntax in your server action .. (easy way )
I’m processing the JSON sent by Stripe’s webhook. It’s all working perfectly if the headers don’t contain charset=utf-8
but Stripe insists on having that in there.
Edit dmxConnectLib/lib/core/Request.php
line 57, change strcasecmp
into stripos
. It should then work with the JSON from stripe.
Thanks @patrick. Did you mean strpos
? Sorry, I realise you did mean stripos
.
Also, changing this line breaks the field validations in the form.
They are the same, stripos
is case-insensitive while strpos
isn’t.
I also found that the ==
should be replaces with ===
, line should look like:
if (stripos($contentType, 'application/json') === 0) {
BRILLIANT!
I had just tried this before your latest post:
if((strcasecmp($contentType, 'application/json') == 0) OR ((strcasecmp($contentType, 'application/json; charset=utf-8') == 0))) {
but I much prefer your solution so have changed it to that and it’s now working perfectly.
Is it possible this could go into the next Wappler update?
Massive thanks for this. I can now crack on with the rest of the project.
sure, will make the changes here also in the code.
hey guys
yesterday I did an api test
in routes I created a server connect route pointing to an api
I received the values, I recorded them in postgresql, all ok
but how to authenticate? a Bearer or a username+password?
did you manage to do that?
or get values in the header of the call?
thanks
Hi Patrick …
i faced the same situation with aws sns confirmation message, for validate end point um SNS system
to solve this i decide to invert this logic for clarify my mind
it could be used for face other peculiarities of systems
look this …
private function getPost() {
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
$isAWSSubscriptionConfirmation = isset($_SERVER["X-AMZ-SNS-MESSAGE-TYPE"]) ? trim($_SERVER["X-AMZ-SNS-MESSAGE-TYPE"]) : '';
$post = $_POST;
if ( (stripos($contentType, 'application/json') > 0) OR
(stripos($isAWSSubscriptionConfirmation, 'subscriptionconfirmation' ) > 0) ) {
// Extend post data with files data
foreach ($_FILES as $field => $file) {
if (is_string($file['name'])) {
$post[$field] = $file;
$post[$field]['isFile'] = TRUE;
} else {
if (!isset($post[$field])) $files[$field] = array();
$this->parseField('error', $file['error'], $post[$field]);
$this->parseField('name', $file['name'], $post[$field]);
$this->parseField('size', $file['size'], $post[$field]);
$this->parseField('tmp_name', $file['tmp_name'], $post[$field]);
$this->parseField('type', $file['type'], $post[$field]);
}
}
} else {
$raw = $this->remove_utf8_bom(file_get_contents('php://input'));
$post = json_decode($raw, TRUE);
}
return $post;
}
regards
Your code seem to have several problems and would not work correctly.
I checked the SNS service documentation and noticed that it default uses content type text/plain; charset=UTF-8
. Easiest way to get it working without needing to change any code it to let the service know that it has to use the content type application/json
. You can do that by creating a delivery policy.
Amazon SNS message delivery retries - Amazon Simple Notification Service
Alternative you just add the text/plain
content type check to the code, at line 65:
if (stripos($contentType, 'application/json') === 0) {
change it to:
if (stripos($contentType, 'application/json') === 0 OR stripos($contentType, 'text/plain') === 0) {
hi Patrick
yes i thought about it
but wouldn’t that leave the range of options wide open?
another service that sends a ‘text/plain’ in the header would have its data treated as a json, even though it is not
what do you think of doing this check by ‘text/plain’ and also looking for the existence of an X-AMZ-SNS-MESSAGE-TYPE header?
so it will be sure that the call comes from Amazon …
just so you know, I’ve tried contacting Amazon a few times, I feel like a mosquito biting an elephant
continuing my saga
how to get a value that comes inside a second level object in a post?
I declared Message as an object
and inside notificationType as a string variable
but if I command to show the contents of Message, my entire object comes
what am I doing wrong ?
Hi,
I am trying to insert WhatsApp chat data into my database using webhook. Below is the json I receive.
{
"messages": [
{
"id": "yqI5O4D7dwa7wXE-wDgzoriOhw",
"from_me": true,
"type": "text",
"chat_id": "xxxxxxxxxx@s.whatsapp.net",
"timestamp": 1719823043,
"source": "api",
"device_id": 4,
"status": "pending",
"text": {
"body": "Hello world!"
},
"from": "xxxxxxxxxxxx"
}
],
"event": {
"type": "posts",
"event": "post"
},
"channel_id": "CAPTAM-DPLNX"
}
Please, may I know the solution that was found for @mebeingken