Authorization failed 410
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
so for a customer project I need to be working with the paypal api. To be exact, Invoices and Payments.
But I'm already failing at the basic connection. It's always an authorization issue. For example I get the error "Got Http response code 401 when accessing https://api.sandbox.paypal.com/v1/invoicing/invoices.".
It's always something like this. Whether I try to curl over the terminal or in my php script.
I'm still only working with a sandbox test account!!!
On https://developer.paypal.com/developer/applications/ I have a Sandbox Account, where I'm getting my access token from.
Under Rest API apps I created an app, where I'm getting the client id and secret from.
Then I try to use the API. For example this is an official code example that I used to test invoice creating. I still think the error is about my credentials and not the code. But in case you want to take a look, the error message is thrown in line
$invoice->create($this->apiContext);
public function createInvoice() { $invoice = new Invoice(); // ### Invoice Info // Fill in all the information that is // required for invoice APIs $invoice ->setMerchantInfo(new MerchantInfo()) ->setBillingInfo(array(new BillingInfo())) ->setNote("Medical Invoice 16 Jul, 2013 PST") ->setPaymentTerm(new PaymentTerm()) ->setShippingInfo(new ShippingInfo()); // ### Merchant Info // A resource representing merchant information that can be // used to identify merchant $invoice->getMerchantInfo() ->setEmail("ANY EMAIL ADDRESS") ->setFirstName("Dennis") ->setLastName("Doctor") ->setbusinessName("Medical Professionals, LLC") ->setPhone(new Phone()) ->setAddress(new Address()); $invoice->getMerchantInfo()->getPhone() ->setCountryCode("001") ->setNationalNumber("5032141716"); // ### Address Information // The address used for creating the invoice $invoice->getMerchantInfo()->getAddress() ->setLine1("1234 Main St.") ->setCity("Portland") ->setState("OR") ->setPostalCode("97217") ->setCountryCode("US"); // ### Billing Information // Set the email address for each billing $billing = $invoice->getBillingInfo(); $billing[0] ->setEmail("ANY EMAIL ADDRESS"); $billing[0]->setBusinessName("Jay Inc") ->setAdditionalInfo("This is the billing Info") ->setAddress(new InvoiceAddress()); $billing[0]->getAddress() ->setLine1("1234 Main St.") ->setCity("Portland") ->setState("OR") ->setPostalCode("97217") ->setCountryCode("US"); // ### Items List // You could provide the list of all items for // detailed breakdown of invoice $items = array(); $items[0] = new InvoiceItem(); $items[0] ->setName("Sutures") ->setQuantity(100) ->setUnitPrice(new Currency()); $items[0]->getUnitPrice() ->setCurrency("USD") ->setValue(5); // #### Tax Item // You could provide Tax information to each item. $tax = new \PayPal\Api\Tax(); $tax->setPercent(1)->setName("Local Tax on Sutures"); $items[0]->setTax($tax); // Second Item $items[1] = new InvoiceItem(); // Lets add some discount to this item. $item1discount = new Cost(); $item1discount->setPercent("3"); $items[1] ->setName("Injection") ->setQuantity(5) ->setDiscount($item1discount) ->setUnitPrice(new Currency()); $items[1]->getUnitPrice() ->setCurrency("USD") ->setValue(5); // #### Tax Item // You could provide Tax information to each item. $tax2 = new \PayPal\Api\Tax(); $tax2->setPercent(3)->setName("Local Tax on Injection"); $items[1]->setTax($tax2); $invoice->setItems($items); // #### Final Discount // You can add final discount to the invoice as shown below. You could either use "percent" or "value" when providing the discount $cost = new Cost(); $cost->setPercent("2"); $invoice->setDiscount($cost); $invoice->getPaymentTerm() ->setTermType("NET_45"); // ### Shipping Information $invoice->getShippingInfo() ->setFirstName("Sally") ->setLastName("Patient") ->setBusinessName("Not applicable") ->setPhone(new Phone()) ->setAddress(new InvoiceAddress()); $invoice->getShippingInfo()->getPhone() ->setCountryCode("001") ->setNationalNumber("5039871234"); $invoice->getShippingInfo()->getAddress() ->setLine1("1234 Main St.") ->setCity("Portland") ->setState("OR") ->setPostalCode("97217") ->setCountryCode("US"); // ### Logo // You can set the logo in the invoice by providing the external URL pointing to a logo $invoice->setLogoUrl('https://www.paypalobjects.com/webstatic/i/logo/rebrand/ppcom.svg'); // For Sample Purposes Only. $request = clone $invoice; try { // ### Create Invoice // Create an invoice by calling the invoice->create() method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) $invoice->create($this->apiContext); } catch (Exception $ex) { var_dump("Create Invoice", "Invoice", null, $request, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY var_dump("Create Invoice", "Invoice", $invoice->getId(), $request, $invoice); var_dump("SUCCESS"); return $invoice; }
Any quick help would be appreciated. I'm really struggling for a long time now with the paypal api.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In the merchant_info be sure to set the correct email. It is the email related to the app
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I reopen this old subject because i don't find an information on the live environment.
In the sandbox, we must set the merchantinfo.email field only with "facilitator" email or others merchants email created in the sendbox accounts.
In live environment, i don't find the list of merchant email, the setting of merchantinfo.email field is it limited again?
Regards.
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- link my PayPal business account with my WordPress website , but it's not work ?! in PayPal Payments Standard
- Change the button from Sandbox to Production in PayPal Payments Standard
- I met the 422 response, and tries a lot solutions in the community but still not work in REST APIs
- Handling payouts that are being on hold/blocked in REST APIs
- When I do PayPal capture Order, I keep on getting Invalid Request Connection in REST APIs