Zendesk API: Receiving 422 response with "Email: cannot be blank" - php

when using postman, everything works fine as per screenshot below:
Once guzzle client is used, for the same payload (visible in screenshot below), there is this error message "email cannot be blank":
In the documentation, I don't see anything regarding email needed and if it is, then why am I able to create from postman in the first place?
What has been done so far:
Including "email" into the payload as a part of "request" key,
Including inside "comment"
Add it outside of "request" key in the payload
None of them worked.
The full error message is:
"{
"error":"RecordInvalid",
"description":"Record validation errors",
"details":{
"email":[
{
"description":"Email: cannot be blank",
"error":"BlankValue"
}
]
}
}"
Does anyone has an idea what could be the solution?
EDIT:
When I try directly using postman it works and I don't have email in the request at all.
EDIT #2:

Related

Woocommerce webhook response 200 message The Rest API is unavailable

When woocommerce (webhook) send a success message (200) but the body contain the below
{
"errors": {
"rest_api_unavailable": [
"The Rest API is unavailable."
]
},
"error_data": []
}
Has anyone happened this error?
Thanks in advance
I did some additional testing on the site I was experiencing this on and narrowed it down to define('ALTERNATE_WP_CRON', true) being set in wp-config.php. If you have this set, try commenting it out. In my tests, the correct payload was sent every time after commenting this constant out. Also, on a completely different site that I configured the same exact webhook/endpoint on that had no issues, as soon as I set ALTERNATE_WP_CRON to true, it started sending rest_api_unavailable for the payload. Please refer to these links for additional information and bug report:
https://github.com/woocommerce/woocommerce/pull/26878
https://github.com/woocommerce/woocommerce/issues/28363

Problem getting response content using Delphi, Indy10 and LARAVEL PHP

I am building a LARAVEL PHP API in order to be consumed by Delphi 2007.
Basically, in Delphi I am performing a POST and in PHP I am validating the fields. If it fails validation, I need to return code 422 along with the validation errors (array).
In Delphi, I'm using Indy10. In it I have a Client of type TIdHTTP.
To do the POST, I do:
Client.Post(sFullEndPoint, Request, Response);
To get code 422:
Client.ResponseCode;
To get the content of the response:
Response.DataString;
In PHP, if I return only one array of errors, as return $ errors I can handle it in Delphi with Response.DataString, the problem is that I won't know the response code, because it will come 200.
If I return response ($ errors, 422) in PHP, Delphi does not find the value of $errors in response.
I need to get the HTTP code and the response body. Can someone help me?
you can set http response code in php like (refrence : https://www.php.net/manual/en/function.http-response-code.php) :
http_response_code(422);
also in laravel you can do it like :
return response('Your output string', 200)->header('Content-Type', 'text/plain');
but i suggest you to pass response as json and add some information about what is wrong or ... :
$errors = [
[
'error_code'=>1312,
'error_message'=>'name is empty'
]
];
return Response::json($errors, 201); // Status code here

Error trying to create webhook

I tried to create a webhook for a task in Asana but the only response I'm getting is this:
{
"errors": [
{
"message": "Could not complete activation handshake with target URL. Please ensure that the receiving server is accepting connections and supports SSL",
"help": "For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors"
}
]
}
(Status: 400 Bad Request)
I am sending a POST Request via Postman to https://app.asana.com/api/1.0/webhooks with following content:
{
"data":
{
"resource": 123456789012345,
"target": "https://example.com/asana.php"
}
}
The asana.php looks something like this:
$headers = getallheaders();
$secret_token = $headers['X-Hook-Secret'];
header('X-Hook-Secret: ' . $secret_token);
What am I doing wrong? Am I missing something?
According to the Asana API Reference (https://asana.com/developers/api-reference/webhooks),
The target must respond with a 200 OK and a matching X-Hook-Secret header to confirm that this webhook subscription is indeed expected.
When you send the header, do you know what response code is being sent? Perhaps you might want to have a look at the $http_response_code argument in http://php.net/manual/en/function.header.php

Command sent on Bot stop/locking

I'd like to know if a command is sent from telegram when a bot is stopped/locked and what is. I've read the telegram bot documentation and googled for this problem but I haven't find a solution.
Where could I find?
Every time you send a request to Telegram servers you receive a response.
The response contains a JSON object, which always has a Boolean field ok and may have an optional String field description with a human-readable description of the result. If ok equals true, the request was successful and the result of the query can be found in the result field. In case of an unsuccessful request, ok equals false and the error is explained in the description. An Integer ‘error_code’ field is also returned, but its contents are subject to change in the future.
From the official documentation.
As example when you make a request to a blocked bot you may receive a response like that.
{
"ok":false,
"error_code":403,
"description":"[Error]: Forbidden: can't write to private chat with deleted user"
}
So when the field ok is false you know something went wrong.
You can check for my_chat_member update. When user is blocking your bot from his chat (it may be a converation or just a private chat), you will receive it with those fields.
{
chat: {
id: 1,
username: "...",
type: "private",
},
from: {...},
old_chat_member: {status: "member"}, // is your bot status
new_chat_member: {status: "kicked"}, // is you new bot status
}

How to use ForceReply in a telegram bot

I'm developing a telegram bot using php and a web hook. All it's fine but sometimes I would like to "wait for a reply" from the user. For example:
If the client write /info without any parameters I would like to show a "usage" message and ask&wait for a ID parameter.
I know there is a property "ForceReply" to force for a reply, but when I set it up nothing happens, and I don't know how to know if the client message its a reply for my question.
Do I have to put my php server on hold? (I think it would be a bad practice) Do I have to whait for a type of message?
Thanks
When you use getUpdates or receive updates via a webhook, the update message will contain a field like reply_to_message field. You can use this to compare it to the message you sent.
If you are running your script via webhooks I would assume that it only executes when it receives a message. If so, I would suggest you use something like memcache/redis to store the message you are expecting a reply for and then when the reply comes, you can compare it to the value stored:
<?php
// This script triggers as a webhook
$message = file_get_contents('php://input');
$message = json_decode($message, true);
$cache = new RedisClient('localhost');
if ($message->reply_to_message == $cache->get('original.message.id'))
{
var_dump('message reply received');
}
The example above is some "pseudo" code that you can use in a webhook to check for a reply to a specific message.

Categories