How do I get the conversationId from a RingCentral SMS response? - php

I am building a simple SMS sending module with the RingCentral WebRTC client in PHP. I can successcully send messages and I get a valid JSON response object, and when I echo it out I can see the conversationId, but I cannot seem to echo it into a variable.
This is my API call:
$resp = $this->platform->post('/account/~/extension/~/sms',
array(
'from' => array ('phoneNumber' => $this->ringcentral_username),
'to' => array(array('phoneNumber' => $phone)),
'text' => $message
));
I can see:
"conversationId" : 1234567890,
in the response object, but $resp->conversationId is not found. How do I pull that out?

I found it:
$resp->json()->conversationId

Related

How to Update an Xero Invoice Using wp_remote_post()

I am trying to update the invoice template of an Xero invoice. My issue is that I get a 400 error and a response saying:
NoDataProcessedException No data has been processed for this endpoint. This endpoint is expecting Invoice data to be specifed in the request body
So my authentication works perfectly but its claiming that I have no data in the body of my post request. As you can see in my code below I have specified data in the body of the request. So have I just formatted it wrong or am I doing something else wrong?
$xeroInvoiceId = '7b601c90-642b-4b6c-9a21-3969ff339cb0';
$updateInvoiceArgs = array(
'headers' => array(
'xero-tenant-id' => $tenantId,
'Authorization' => 'Bearer ' . $refreshTokenBody->access_token,
),
'body' => array(
'InvoiceID' => $xeroInvoiceId,
'BrandingThemeID' => '5d4dd402-c851-497e-aae1-9ff265c0d15a'
)
);
$res = wp_remote_post('https://api.xero.com/api.xro/2.0/Invoices/' . $xeroInvoiceId, $updateInvoiceArgs);
var_dump($res);
You are trying to post template or invoice data?

Trying to send a HTTP request but have no idea how to do it

I'm trying a new service to do a specific task, they have a pretty basic API which lets the users build simple apps.
An example of the HTTP request is:
https://domainname.com/dashboard/api
?to={PHONE NUMBER}&from={SENDER ID}&message={TEXT}
&email={YOUR EMAIL}&api_secret={API SECRET}
&unicode={TRUE/FALSE}&id={IDENTIFIER}
I have tried everything, using postman,php and googling for the past 3 hours and i can't get it to work.
(even tried to send it through the browser lol)
Whats a proper way to send a http request?
Thank you.
You can send an HTTP request without CURL using PHP5. This answer is based off of How do I send a POST request with PHP?. You'll have to enter your variables into the $data array.
$url = 'https://domainname.com/dashboard/api';
$data = array('to' => PHONE_NUMBER, 'from' => SENDER_ID, 'message' => TEXT, 'email' => EMAIL, 'api_secret' => SECRET, 'unicode' => BOOLEAN, 'id' => IDENTIFIER);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
You can test if your requests are working from your script by using http://www.postb.in or some other similar service. This allows you to see your requests to debug them (rather than relying on feedback/errors from the service you are using). Then you'll know if your requests are formatted correctly and working. Sometimes a service is down... and you spend hours troubleshooting something that's not on your end.

Unable to get data from aws sns email bounce notification message

I have subscribed my endpoint and now I need to pull the emailAddress from the object/array I cannot get the value 'fakeemail#
gmail.com' for the life of me
Aws\Sns\Message Object
(
data:Aws\Sns\Message:private => Array
(
Type => Notification
MessageId => hghkvvhhv32hg32vh23v32hjk32bjk
TopicArn => arn:aws:sns:us-west-232jh32bhj322j3hv23jhv23jhv2
Message => {"notificationType":"Bounce","bounce":{"bounceType":"Permanent","bounceSubType":"Suppressed","bouncedRecipients":,"timestamp":"2016-06-21T04:43:05.786Z","feedbackId":"wef-a5166c3e-fe-11e6-923e4-1115qbdde1aq2907d-000000","reportingMTA":"dns; amazonses.com"},"mail":{"timestamp":"2016-06-21T04:43:04.000Z","source":"www-data#myserver.com","sourceArn":"arn:aws:ses:us-west-2:0f2243234320627162:identity/myserver.com","sendingAccountId":"0243122452162","messageId":"0103714433d74e-e3bfd2dd3b3b7-49238-45a3f-953fa-c9a3eb3fd312c-03300000","destination":["fakeemail#
gmail.com"]}}
Timestamp => 2016-06-21T04:43:05.882Z
SignatureVersion => 1
Signature => vfvdfvsdffsvfadvfdvdfvdfdfsdvsdfdf
SigningCertURL => https://sns.us-west-2.amazonaws.com/SimpleNotificationService-vafvadfvadsvdsfdsvsvdsdfsdvsdsvd.pem
UnsubscribeURL => https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:02vsddfvddv43230vfvsvf67162:email_bounce:5fc6vsdfvd6af9-cfssdvdv197-4vfsdf0f-afb7-67fvdfs1b
)
)
I have changed my details above but this is what is given. I need to get the
fakeemail#gmail.com from array in the object but cant for the life of me
//from aws sdk
$message = Message::fromRawPostData();
I used
print_r($message['Message'], true);
to get the data above would be appreciated :)
Ok I figured it out. You want to take the
$message['Message']
and encode it to json to use as an object
$test = json_decode($message['Message']);
$returnsMyAnswer = print_r($test-> mail-> destination[0], true);
and then
echo $returnsMyAnswer;
and you get
fakeemail# gmail.com

Wordpress HTTP API with twilio

I am trying to send sms messages using Twilio API in Wordpress, but I don't understand what is curl -u. Now I want to send sms using twilio and wordpress via wp_remote_post.
See twilio send sms docs API (via JSON)
My code:
function sending_sms_via_twilio_api(){
$oauth_args = array(
"body" => array(
"Body" => "Hello World",
"To" => "0000000",
"From" => "5555555",
),
"my_Sid:my_token"
);
$response = wp_remote_post('https://api.twilio.com/2010-04-01/Accounts/AC28fcd041ffe3edb8029779894b7912d3/Messages.json', $oauth_args);
$result = json_decode( wp_remote_retrieve_body($response), true );
print_r($result);
}
Result is:
Array ( [code] => 20003 [detail] => Your AccountSid or AuthToken was
incorrect. [message] => Authentication Error - No credentials provided
[more_info] => [status] => 401 )
Any solutions?
That is a simple authentication problem. You should check your credentials again.
A GET call on https://{AccountSid}:{AuthToken}#api.twilio.com/2010-04-01/Accounts with wrong credentials give that problem.
Also the api response give this error page as advice for you:
https://www.twilio.com/docs/errors/20003
Hope it helps

AWS SDK Guzzle error when sending email with SES

I am attempting to send mail using AWS SES sendEmail method, and I'm having trouble with an error. I have read this question: AWS SDK Guzzle error when trying to send a email with SES
I am dealing with a very similar issue. The original poster indicates that they have a solution, but did not post the solution.
My code:
$response = $this->sesClient->sendEmail('example#example.com',
array('ToAddresses' => array($to)),
array('Subject.Data' => array($subject), 'Body.Text.Data' => array($message)));
Guzzle code producing the error (from aws/Guzzle/Service/Client.php):
return $this->getCommand($method, isset($args[0]) ? $args[0] : array())->getResult();
Error produced:
Catchable fatal error: Argument 2 passed to Guzzle\Service\Client::getCommand() must be of the type array, string given
Looking at the Guzzle code, I can see that the call to getCommand will send a string if args[0] is set and is a string. If args[0] is NOT set then an empty array is sent.
What am I missing here please?
SOLUTION:
It turns out I was trying to use SDK1 data structures on the SDK2 code base. Thanks to Charlie Smith for helping me to understand what I was doing wrong.
For others (using AWS SDK for PHP 2) :
Create the client -
$this->sesClient = \Aws\Ses\SesClient::factory(array(
'key' =>AWS_ACCESS_KEY_ID,
'secret' => AWS_SECRET_KEY,
'region' => Region::US_EAST_1
));
Now, structure the email (don't forget that if you're using the sandbox you will need to verify any addresses you send to. This restriction doesn't apply if you have been granted production status) -
$from = "Example name <example#example.com>";
$to ="example#verified.domain.com";
$subject = "Testing AWS SES SendEmail()";
$response = $this->sesClient->getCommand('SendEmail', array(
'Source' => $from,
'Destination' => array(
'ToAddresses' => array($to)
),
'Message' => array(
'Subject' => array(
'Data' => $subject
),
'Body' => array(
'Text' => array(
'Data' => "Hello World!\n Testing AWS email sending."
),
'Html' => array(
'Data' => "<h1>Hello World!</h1><p>Testing AWS email sending</p>"
)
),
),
))->execute();
That should work now.
Here is the relevant section in the AWS SDK for PHP 2 documentation:
http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.Ses.SesClient.html#_sendEmail

Categories