Get error code 14 when sending SMS using smsapi - php

I am trying to send SMS using the API from smsapi.pl. Currently I am getting error code 14 which means "Invalid sender field".
Code:
$access_token = 'XXXXXX'; //sms api access token
$numbers = '+7XXXXXXXX';
$params = array(
'to' => $numbers,
'from' => 'Info',
'message' => 'message text',
);
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'https://api.smsapi.pl/sms.do');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $params);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer $access_token"
));
$content = curl_exec($c);
$http_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
print_r($content);

The translated documentation says:
Only verified names are accepted. (& from = aktywna_nazwa). The sender field should be added after logging in to the SMSAPI website, Sender Field .
Did you add the sender name Info on the website?

Related

Issue sending post request to API | PHP

Essentially I need to send the appropriate POST request to the following Parcel Tracking API that return the shipping data from the courier provided:
API Doc: https://www.kd100.com/docs/real-time-shipment-tracking
The problem I am having, is the response:
[code] => 104
[message] => Invalid signature
Can someone please have a look at my request below and tell me if I've made a mistake based on the doc? Assuming the Key, Secret Key and Tracking data is correct, my request should be completely valid.
My POST Request so far:
$key = 'KEY';
$secret = 'SECRET KEY';
$param = array (
'carrier_id' => 'usps',
'tracking_number' => 'TRACKING #'
);
$post_data = array();
$post_data['param'] = json_encode($param, JSON_UNESCAPED_UNICODE);
$header_data = array();
$header_data['API-Key'] = $key;
$sign = md5($post_data['param'].$key.$secret);
$header_data['signature'] = strtoupper($sign);
$url = 'https://www.kd100.com/api/v1/tracking/realtime';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"signature: $sign",
"API-Key: $key"
));
$result = curl_exec($ch);
$data = json_decode($result, true);
echo '<br/><br/>Start:<br/><pre>';
echo print_r($data);
echo '</pre>';
Your signature is not in uppercase. You set $sign variable but never actually set uppercase to it. You actually set uppercase to $header_data['signature'] and then never use it.
$sign = md5($post_data['param'].$key.$secret);
$header_data['signature'] = strtoupper($sign);
Your problem should be solved if you write it like this:
$sign = strtoupper(md5(post_data['param'].$key.$secret));
Remember to clean your code. You don't actually use $header_data anywhere

MailChimp API Responds 404 in V3.0 PHP Curl

I am using the following code to initiate a member add request to a list in MailChimp.
<?php
error_reporting(-1);
ini_set('display_errors', 1);
$email = 'test#domain.com';
$first_name = 'name';
$last_name = 'last name';
$api_key = 'xx-us18'; // YOUR API KEY
// server name followed by a dot.
// We use us13 because us13 is present in API KEY
$server = 'us18.';
$list_id = 'xx'; // YOUR LIST ID
$auth = base64_encode( 'user:'.$api_key );
$data = array(
'apikey' => $api_key,
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => $first_name,
'LNAME' => $last_name
)
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'api.mailchimp.com/3.0/lists/'.$list_id.'/members');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
echo $result;
?>
But what happened is the response is 404.
{
type: "http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
title: "Resource Not Found",
status: 404,
detail: "The requested resource could not be found.",
instance: "78a35efa-ef43-471d-9e70-aecdc992d2e6"
}
Does anyone know what I am doing wrong? What might be the reason for this error?
Extra Infos: API Key is valid, If I provide that wrong, I am getting another error.
List-id is also true.
I am running this code on localhost with MAMP.
The issue was I used web_id instead of list_id.
When I changed that, the issue was resolved.

Send invoice by email through Zoho Books API

My Code is as follows...
The email functions
public function zoho_email($array){
$data = json_decode($array,true);
$url = '/invoices/'.$data['invoice']['invoice_id'].'/email';
$recivers[] = array($data['invoice']['contact_persons_details'][0]['email']);
$data = array(
'to_mail_ids' => $recivers,
'subject' => 'Invoice from MSL (Invoice#: '.$data['invoice']['invoice_number'].')',
'body' => 'Dear Customer,<br><br><br><br>Thanks for your business,
'send_from_org_email_id' => true
);
$result = $this->zoho_create($url, $data);
}
The curl Function for create invoices, contacts, and send email
public function zoho_create($url,$array){
$json = json_encode($array);
$data = array('authtoken' => ZOHOAUTHTOKEN,'JSONString' => $json,'organization_id' => ZOHOORGNISATIONID);
$curl = curl_init($this->apiUrl.$url);
if($url=='contacts/'){
curl_setopt_array($curl, array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true
));
}
else{
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded") );
}
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
I want to send invoice by email through API to customer but This error occur in my code.
{"code":5,"message":"Invalid URL Passed"}
Please help me out there....
Thanks in advance...
Your code is working correctly. Try to print the url ($url) and confirm once if it is in the required format (/invoices/invoice_id/email). For example if your invoice_id is 1234, then the $url should be '/invoices/1234/email'. Also make sure that $this->apiUrl is https://books.zoho.com/api/v3
If there occurs a problem still u can use the help documents mentioned below:
https://www.zoho.com/books/api/v3/.
have you tried using full url : "https://books.zoho.com/api/v3/invoices/:invoiceno/email"

Mailgun API on Google App Engine

I'm trying to send emails via Mailgun API on Google App Engine PHP, however, I keep getting a 401 error on my requests.
define(DOMAIN,'sandbox-----------.mailgun.org');
define(MAILGUN_API,'key-xxxxxxxxxxxxx');
function mg_send($to, $subject, $message) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api: '.MAILGUN_API);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$plain = strip_tags(nl2br($message));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v3/'.DOMAIN.'/messages');
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'from' => 'support#'.DOMAIN,
'to' => $to,
'subject' => $subject,
'html' => $message,
'text' => $plain)
);
$j = json_decode(curl_exec($ch));
$info = curl_getinfo($ch);
if($info['http_code'] != 200) {
echo($info['http_code']);
}
curl_close($ch);
return $j;
}
$r = mg_send('authorized#email.com','Test Email','This is the test email.');
I've authorized the email I'm trying to send to, verified my account, triple checked my API Key and made sure curl is enabled in my php.ini. Any insight as to why this is happening?

Token invalid - Error 401 in YouTube API

I am Working send message using youtuba api. But i got a Error on my file. it shows Invalid Token 401 Error. My file is given below.I'm pretty sure I must be missing something vital but small enough to not notice it.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = array('accountType' => 'GOOGLE',
'Email' => 'User Email',
'Passwd' => 'pass',
'source'=>'PHI-cUrl-Example',
'service'=>'lh2');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$kk = curl_getinfo($ch);
$response = curl_exec($ch);
list($auth, $youtubeuser) = explode("\n", $response);
list($authlabel, $authvalue) = array_map("trim", explode("=", $auth));
list($youtubeuserlabel, $youtubeuservalue) = array_map("trim", explode("=", $youtubeuser));
$developer_key = 'AI39si7SavL5-RUoR0kvGjd0h4mx9kH3ii6f39hcAFs3O1Gf15E_3YbGh-vTnL6mLFKmSmNJXOWcNxauP-0Zw41obCDrcGoZVw';
$token = '7zWKm-LZWm4'; //The user's authentication token
$url = "http://gdata.youtube.com/feeds/api/users/worshipuk/inbox" ; //The URL I need to send the POST request to
$title = $_REQUEST['title']; //The title of the caption track
$lang = $_REQUEST['lang']; //The languageof the caption track
$transcript = $_REQUEST['transcript']; //The caption file data
$headers = array(
'Host: gdata.youtube.com',
'Content-Type: application/atom+xml',
'Content-Language: ' . $lang,
'Slug: ' . rawurlencode($title),
'Authorization: GoogleLogin auth='.$authvalue,
'GData-Version: 2',
'X-GData-Key: key=' . $developer_key
);
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<id>Qm6znjThL2Y</id>
<summary>sending a message from the api</summary>
</entry>';
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_HEADER, TRUE );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($xml) );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1 );
$tt = curl_getinfo($ch);
print_r($tt);
$result = curl_exec($ch);
print_r($result);
exit;
// close cURL resource, and free up system resources
curl_close($ch);
?>
any problem in my code? Please guide me. How can I get a result from this code?
Most likely your authentication is wrong, please debug that part first. Either you are not using right scope or that API is not enabled from your console.
On a separate note, I strongly suggest to use Youtube Data API v3 for this. We have updated PHP client library and great samples to get you started.

Categories