USPS : API Authorization failure - php

Why won't the rate work with USPS? I'm using ratev4 and I get an error:
Error:
API Authorization failure. RateV4 is not a valid API name for this protocol.
UspsCom::DoAuth
Here is my code:
<?php
$devurl = "testing.shippingapis.com/ShippingAPITest.dll";
$puburl = "https://secure.shippingapis.com/ShippingAPITest.dll";
$service = "RateV4";
$userid = "690DEVBL1739";
$xml = rawurlencode('<RateV4Request USERID="xxxxx">
<Revision/>
<Package ID="1ST">
<Service>FIRST CLASS</Service>
<FirstClassMailType>LETTER</FirstClassMailType>
<ZipOrigination>44106</ZipOrigination>
<ZipDestination>20770</ZipDestination>
<Pounds>1</Pounds>
<Ounces>0.0</Ounces>
<Container/>
<Size>REGULAR</Size>
<Machinable>true</Machinable>
</Package>
</RateV4Request>');
$request = $devurl . "?API=" . $service . "&xml=" . $xml;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "<pre>";
print_r($response);
echo "</pre>";

I assume that you have already registered for USPS Web Tools here:
https://secure.shippingapis.com/registration/
And have received confirmation from USPS that your account is active:
If you need to set up USPS or your customers are receiving this error on check out (See below) you should confirm the following
Confirm that our USPS API access is approved
Confirm that it is not in test mode and is in production mode
If USPS says your account is active, this does not mean it is in production mode, - you need to call USPS and specifically request that it be moved to production mode after your account has been approved. A good idea is to perform this quick test:
Insert the following into your browser with your own USERID in place of the XXXX in the URL of any browser:
https://secure.shippingapis.com/ShippingAPITest.dll?API=CarrierPick... USERID="XXXX">ABC Corp.Suite 7771390 Market StreetHoustonTX770581234
If your USPS account is active, it should accept the username.
Confirm that your username and password is for this site only. USPS only allows 1 domain per account.
http://production.shippingapis.com/ShippingAPI.dll
The problem is that by default, you don’t have access to USPS’s production API. They have to approve you first. Keep in mind that they only allow you to use it on one web site per account, so if you’re setting Magento up for a client, customer, or other business entity other than your own you should set up a separate USPS account for them.
That's why you're receiving this text - "Sample Do Not Mail" over the generated shipping label.
You can set up your USPS WebTools account here:
http://www.usps.com/webtools/
Once you have set up your account, they will give you access to the testing environment. The URL for the USPS test API is: http://testing.shippingapis.com/ShippingAPITest.dll
I recommend asking USPS to turn on production mode. When you are approved by USPS for the production API, you should use the following URLs:
http://production.shippingapis.com/ShippingAPI.dll
https://secure.shippingapis.com/ShippingAPI.dll
When you have completed your testing, email the USPS Internet Customer Care Center (ICCC). They will switch your profile to allow you access to the production server and will provide you with the production URLs.
The ICCC is staffed as follows: Monday through Friday from 8:00AM to 8:30PM Eastern Time Saturday from 8:00AM to 6:00PM Eastern Time Sunday and Postal Holidays - Closed except for the following Holidays: Martin Luther King; President's Day; Columbus Day; & Veteran's Day with hours from 9:00AM to 6:00PM Eastern Time
E-mail: uspstechsupport#esecurecare.net Telephone: 1-800-344-7779
But remember, it’s very important that you set up a separate USPS account for each web site (or at least one per domain). USPS will disable your access to their production server if you are caught using your account on multiple web sites.
To request access to the USPS production API, fill out the form here: http://www.usps.com/webtools/webtoolsapirequestform.htm
USPS doesn’t allow you to use their API for batch processing or data cleansing, so be sure to NOT check these boxes on the request form.
Once USPS gives you access to their production API server, everything should work corresponding to all USPS shipping options. If you are still having trouble, again check that you have access to USPS’s production API server.

I had the same problem. RateV4 is not valid for the USPS's test server, only production. I contacted their support people and tried to get a valid API for test but all they ever sent was a link to their documentation (which only contains production APIs, not test). In the end I just asked them to move my account to production and they did.

I've had the same issues with testing Ratev4 (and v2 for intl shipments) stuff. Just asking them to move you to production fixed that easily , but make sure you use the right urls of course.
Other than that, from what I understand your setup wouldn't work anyway, because you're asking for a rate for first class and the weight is 1 pound. First class only goes up to 13 ounce...

Related

Problem with Instagram api since July 2022 [duplicate]

I used instagram public api (adding __a=1 to parameters of an url) to get a post detail (caption ,imageUrl, postType, likes, comments , viewsCount). But it seems that Instagram banned that recently and returned a 403. It also asks for login when I try to directly open a post by its usrl.
I tried to use the instagram private api (https://mgp25.github.io/) for getting post details, but after some requests instargam banned that too:
"throttled by instagram because of too many api requests"
Do you have any offer for an alternative?
Actually it is not really banned but now redirects with 302 to auth page. It seems like auth is required when Instagram account and query geoIPs are different. Alternative is to use official API. No scraping can be done, because the profile link now also requires authentication. You can do authenticated scraping but you are limited to 200 queries ( that Instagram sends to get data) per hour.
Instagram blocked all public endpoints with some limitations and hit rate. Now you need to send the user's session to get the response.
Did you notice the same endpoint returning the JSON response when you are logged in on Instagram in the same browser? Yes, that because whenever you are hitting the URL like "https://www.instagram.com/anything/?__a=1", your browser sending the live and valid sessionid to Instagram. Since you are logged in hence Instagram served you well.
Ever you wonder why the same endpoint started to work again after changing the Internet connection from Wifi to Mobile hotspot or try with another internet service provider.
It's because your IP got blocked and no more free hot babes for you until you are logged in.
Below is the PHP code to give a try with sessionid.
<?php
// keyword or user name
$hashtag = $username = "msevylynch";
// $endpoint = "explore/tags/$hashtag"; // hashtag search
$endpoint = $username; // user search
// login in insta account and copy session from browser's cookie tab
$sessionid = '<YOU-SESSION-ID-PICK-FROM-BROWSER-AFTER-LOGIN>';
$ch = curl_init();
https://www.instagram.com/explore/tags/msevylynch/?__a=1
curl_setopt($ch, CURLOPT_URL, "https://www.instagram.com/{$endpoint}/?__a=1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Cookie: ds_user='.$username.'; igfl='.$username .'; sessionid=' . $sessionid,
'User-Agent: Instagram 7.16.0 Android'
));
$response = curl_exec($ch);
header('Content-Type: application/json');
echo $response;
?>
Still no luck then it means Instagram blocked you or your IP for some time due to
hitting endpoint too early or very fast programmatically
denied the presented challenge
seems it's an automated hit
password is changed
you are logged out
or your internet bill is over due .. ha ha ha
Thank you for the reading this long, much apriceated.
Instagram is getting very strict with __a=1 endpoint. Your best bet in 2021 to get Instagram profile info is to use clean residential proxies
They require residential IPs to access ?__a=1 pages without login. https://webscraping.ai works for it if you use proxy=residential parameter. An example of such a request:
curl "https://api.webscraping.ai/html?api_key=test-api-key&proxy=residential&url=https%3A%2F%2Fwww.instagram.com%2Finstagram%2F%3F__a%3D1"

Whatsapp API - send a notification message to another phone number

I was looking for a way to send notifications directly to the customer phone number using the Whatsapp API
I found an article on a site that explains in detail how to activate and use the Whatsapp API.
Add the phone number +34 644 76 66 43 into your Phone Contacts. (Name it it as you wish)
Send this message "I allow callmebot to send me messages" to the new Contact created (using WhatsApp of course)
Wait until you receive the message "API Activated for your phone number. Your APIKEY is 123123" from the bot.
Note: If you don't receive the ApiKey in 2 minutes, please try again after 24hs.
The WhatsApp message from the bot will contain the apikey needed to send messages using the API.
You can send text messages using the API after receiving the confirmation.
Perfect receipt apikey
How to send WhatsApp Messages from PHP using CURL Library
It is very simple to send WhatsApp messages from PHP using the cURL Library. I would recommend to create a function and then call to the function every time that you want to send a message.
First, create the function "send_whatsapp" in your php code as follow:
function send_whatsapp($message="Test"){
$phone="NUMBER"; // Enter your phone number here
$apikey="YOUR_API_KEY"; // Enter your personal apikey received in step 3 above
$url='https://api.callmebot.com/whatsapp.php?source=php&phone='.$phone.'&text='.urlencode($message).'&apikey='.$apikey;
if($ch = curl_init($url))
{
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$html = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// echo "Output:".$html; // you can print the output for troubleshooting
curl_close($ch);
return (int) $status;
}
else
{
return false;
}
}
Just update the $phone and $apikey variable with the ones that you obtained during the step 3 above.
And then call to the function from any place in your code.
send_whatsapp("this is a test from PHP"); //Text message that your would like to send
You can call to the send_whatsapp function from different places in your code.
QUESTION
Perfect this will send me a message every time to the number I specified to activate the notification system.
But what if I want to send it not to my number but to the customer number?
I believe you're missing two concepts here. If you want to send messages from your personal phone number, you need to host & run your own solution (I don't think you'd like to allow anybody else out there to get all your stuff).
If you are asking for a service provider to set up a number for you and offer you a gateway service for that purpose, there are several alternatives out there. Google them. You'll find two options; Facebook/Whatsapp API connected providers and 'free riders' that will set that up for you at a cost.
The solution you mention is called call me bot and it is just to send self notifications and not for sending out messages to third parties. I am hosting a similar solution (https://github.com/inUtil-info/whin-use-cases) but is the same situation. To prevent span, you are not allowed to send messages to anyone but you.

Pay 3rd Party With PayPal API

I'm developing an application which pays out payments to a 3rd party. The source code for what I'm using is found here:
http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/CreateThirdPartyPayment.html
I've added the following as well for my ClientID and Client Secret:
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'xxxxxxxxxxxxxxxxxxxxxxxxx', // ClientID
'xxxxxxxxxxxxxxxxxxxxxxxxx' // ClientSecret
)
);
When using my sandbox credentials, the code succeeds as it should. When swapping to the live credentials, however, I get an invalid client, authentication failed error. I've ensure the live ClientID and Client Secret are exactly what I have on my developer portal.
I've been looking all over the developer portal looking for a possible setting I'm missing, or something not configured correctly but have come to a loss. Any advice?
Update: I also don't see any issues/errors on the developer portal when logged into developer.paypal.com
Update 2:
I found this just now:
public function setConfig(array $config)
{
PayPalConfigManager::getInstance()->addConfigs($config);
}
Do I need to set the config by $apiContext->setConfig('LIVE') (or something to this effect?)
With the assistance from #JashParakh I was able to solve the issue. I added the following:
$config['mode'] = 'Live';
$apiContext->setConfig($config);
The payment went through in live and is should have.

How to send in Deals using a web form?

I'm trying to add a new Deal with the Pipedrive API.
To do so I've followed this tutorial: http://support.pipedrive.com/customer/portal/articles/1271064-how-to-send-in-deals-using-a-web-form
But there's something I didn't understand:
"Email API gives your company a special email address you can use to
automate lead generation and adding of new contacts and
organizations."
Where can I get this email address, there's no other mention of it at the tutorial?
Since I'm unable to follow the tutorial I'm trying to add a new deal with cURL, this is the code:
<?php
$deal = array("item_type" => "deal","stage_id" => 1,"title" => "Atendimento Web Site","organization" => "Company","owner" => "johndoe#company.com.br","visible_to" => 2,"person" => array("name" => $nome,"email" => $email,"organization" => $empresa,"phone" => $tel));
$deal_string = json_encode($deal);
$ch = curl_init('https://api.pipedrive.com/v1/deals?api_token=TOKEN');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $deal_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json, charset=UTF-8',
'Content-Length: ' .strlen($deal_string))
);
echo $deal_string;
echo curl_exec($ch);
?>
And this is what I get:
iten sent -> {"item_type":"deal","stage_id":1,"title":"Atendimento","organization":"Company","owner":"owner#mail.com.br","visible_to":2,"person":{"name":"Jo\u00e3o Neto","email":"mail#mail.com.br","organization":"Company 2","phone":"7112345678"}}
return from api -> {"success":false,"error":"Deal title must be given.","data":null,"additional_data":null}
Where's the error?
About the email support it's true that you are mixing two thing, although it was also happened to me the first time. I admit it would seem strange, an API in which you can use emails.
Anyway, I was working on a simple integration between Pipedrive and another platform and I used the full REST API.
I noticed every time you have an error creating a Deal or you make a mistake in the Json (even if title is ok), you always get the same answer "error":"Deal title must be given.". Of courses it won't help you too much.
So, I recommend you to use some tools like RESTClient for Firefox to simplify the problem at the beginning or even Firebug to sniff it from https://developers.pipedrive.com/v1 making use of their tools to understand the request a little bit better. After that, you can do it more complex.
I am putting you a screenshot in which you can see the simplest example. I hope it will be useful for anyone
I'd receive an email from Pipedrive Support with a full anwser.
*Hi,
Thanks for reaching out!
I'm sorry to hear about the trouble!
So you're mixing up two completely separate things. You're sending in the JSON object needed for the Email API into the REST API.
You have 2 options.
You could go full on with the email API. To do this you need to log into your Pipedrive account, navigate to the Settings, Features page and enable the Email API feature. Then click through to the email API page and get the email address you need to send the object to. And then alter your PHP code to send in that object to that email address as a plain text email. No curl or API token needed for that.
You could clean up the data object you're sending in with the REST API. But you need to understand that the REST API works a little different from the Email API. So you can't just send in the person object along with the deal. You would first need to POST in the person with all the details to the persons endpoint and get back the ID. You can then use the person ID in the deals POST.
I hope this helps
Martin Henk | Co-Founder, Head of Customer Support
Pipedrive*

mobile phone's carrier information

We need to test the sms text notifications thru our project which is implemented in PHP. We have used the phone number combine with the carrier gateway. For example 7-11 Speakout (USA GSM) has a gateway #cingularme.com, so while send sms we are combining the number with the gateway as 9860112354##cingularme.com and sending this thru PHP's mail function.
Now wee need to test this on our mobile phones. However we are unabel to find the carrier gateway list for the same (Nokia 6300). Please advise.
Are you looking for a list of carrier email to SMS addresses? Such as ##tmomail.net?
If so, here's an exhaustive list:
http://www.mutube.com/projects/open-email-to-sms/gateway-list/
I had this problem also. The carrier gateway list, as posted out by another answer - is irrelevant to the device, but instead has to due with it's service provider. What you will need to do, is find the carrier - and then fetch it's email to SMS address, to build the e-mail address to send your message to. Such a list can be found on wikipedia.
To get the carrier and service provider of the cellular device, here is a simple function that will provide the cellphone's carrier name when provided with a celluar number:
<?php
// leave this blank - we may never implement an authentication key
$smsarc_API_key = '';
// enter the user's 10 digit cell phone number.
// example format: $smsarc_to = '5556667777';
$smsarc_number = '5192097991';
// lookup carrier
$ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, 'http://www.smsarc.com/api-carrier-lookup.php?sa_number='.$smsarc_number); $AskApache_result = curl_exec ($ch); $smsarc_message_status = $AskApache_result; curl_close($ch);
// print the carrier lookup results
echo $smsarc_carrier;
?>
Developer API from their site:
http://www.smsarc.com/free-php-cell-phone-carrier-lookup/

Categories