cancel
Showing results for 
Search instead for 
Did you mean: 

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
ayrancd
Contributor
Posted on

Following this API article https://developer.paypal.com/docs/api/invoicing/v2/#invoices_create

 

I'm getting this error using PHP language:

 

Array ( [name] => INVALID_REQUEST [message] => Request is not well-formed, syntactically incorrect, or violates schema. [debug_id] => c0c75e12510f5 [details] => Array ( ) [links] => Array ( [0] => Array ( [href] => https://developer.paypal.com/docs/api/invoicing/#errors [method] => GET ) ) )

 

Can't figure out what I am missing. Below are all fields I'm sending to Paypal api:

 

$invoice->fields['detail']["invoice_number"] = "12345";
$invoice->fields['detail']["currency_code"] = "USD";
$invoice->fields['detail']["invoice_date"] = "2020-09-04";
$invoice->fields['detail']["note"] = "Thank you for your business.";
$invoice->fields['detail']["memo"] = "This is invoice is due in 24hrs after being generated.";
$invoice->fields['detail']["payment_term"]["term_type"] = "DUE_ON_DATE_SPECIFIED";
$invoice->fields['detail']["payment_term"]["due_date"] = "2020-09-05";

//seller
$invoice->fields['invoicer']["business_name"] = "Business name here";
$invoice->fields['invoicer']["name"]["given_name"] = "Cezar";
$invoice->fields['invoicer']["name"]["surname"] = "Ayran";

$invoice->fields['invoicer']["address"]["address_line_1"] = "533 Cece Lake";
$invoice->fields['invoicer']["address"]["address_line_2"] = "Apt 0101";
$invoice->fields['invoicer']["address"]["admin_area_2"] = "West Palm Beach";
$invoice->fields['invoicer']["address"]["admin_area_1"] = "FL";
$invoice->fields['invoicer']["address"]["postal_code"] = "33437";
$invoice->fields['invoicer']["address"]["country_code"] = "US";
$invoice->fields['invoicer']["email_address"] = "seller email";

 

//buyer - billing
$invoice->fields["primary_recipients"][0]["billing_info"]["business_name"] = "Evanice Company";
$invoice->fields["primary_recipients"][0]["billing_info"]["name"]["given_name"] = "Evanice";
$invoice->fields["primary_recipients"][0]["billing_info"]["name"]["surname"] = "D";

$invoice->fields["primary_recipients"][0]["billing_info"]["address"]["address_line_1"] = "Av Benjamin Constant";
$invoice->fields["primary_recipients"][0]["billing_info"]["address"]["admin_area_2"] = "Boca Raton";
$invoice->fields["primary_recipients"][0]["billing_info"]["address"]["admin_area_1"] = "FL";
$invoice->fields["primary_recipients"][0]["billing_info"]["address"]["postal_code"] = "12345";
$invoice->fields["primary_recipients"][0]["billing_info"]["address"]["country_code"] = "US";
$invoice->fields["primary_recipients"][0]["billing_info"]["email_address"] = "buyer email";

//shipping
$invoice->fields["primary_recipients"][0]["shipping_info"]["business_name"] = "Evanice Company";
$invoice->fields["primary_recipients"][0]["shipping_info"]["name"]["given_name"] = "Evanice";
$invoice->fields["primary_recipients"][0]["shipping_info"]["name"]["surname"] = "D";
$invoice->fields["primary_recipients"][0]["shipping_info"]["address"]["address_line_1"] = "Av Benjamin Constant";
$invoice->fields["primary_recipients"][0]["shipping_info"]["address"]["admin_area_2"] = "Boca Raton";
$invoice->fields["primary_recipients"][0]["shipping_info"]["address"]["admin_area_1"] = "FL";
$invoice->fields["primary_recipients"][0]["shipping_info"]["address"]["postal_code"] = "12345";
$invoice->fields["primary_recipients"][0]["shipping_info"]["address"]["country_code"] = "BR";
$invoice->fields["primary_recipients"][0]["shipping_info"]["email_address"] = "buyer email";

//items
$invoice->fields["items"][0]["name"] = "Product title here";
$invoice->fields["items"][0]["description"] = "Description here";
$invoice->fields["items"][0]["quantity"] = 1;
$invoice->fields["items"][0]["unit_amount"]["currency_code"] = "USD";
$invoice->fields["items"][0]["unit_amount"]["value"] = "80.00";

 

Any idea of what I am missing? Tks

1 ACCEPTED SOLUTION

Accepted Solutions
Solved

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
ayrancd
Contributor

Hi Stefan,

 

noone.jpg

paypal.jpg

 

1 - How can I get the public URL of that invoice?
2 - Why can't I see any invoice on both accounts (invoicer or bill-to)?
3 - Is there anything else I should do with Array ( [rel] => self [href] => https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-EMGM-XAC7-S4LZ-ERHR [method] => GET )

 

Tks for helping me!!

View solution in original post

11 REPLIES 11

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
ayrancd
Contributor

Adding the JSON of all fields I'm sending to Paypal API to help visualizing:

 

Array
(
    [detail] => Array
        (
            [invoice_number] => 0001
            [currency_code] => USD
            [invoice_date] => 2020-09-04
            [note] => Thank you for your business.
            [memo] => This is invoice is due in 24hrs after being generated.
            [payment_term] => Array
                (
                    [term_type] => DUE_ON_DATE_SPECIFIED
                    [due_date] => 2020-09-05
                )

        )

    [invoicer] => Array
        (
            [name] => Array
                (
                    [given_name] => Cezar
                    [surname] => A
                )

            [address] => Array
                (
                    [address_line_1] => 456 Cede Rd
                    [address_line_2] => Apt 0101
                    [admin_area_2] => Boca
                    [admin_area_1] => FL
                    [postal_code] => 12345
                    [country_code] => US
                )

            [email_address] => seller email
        )

    [primary_recipients] => Array
        (
            [0] => Array
                (
                    [billing_info] => Array
                        (
                            [business_name] => Evanice Company
                            [name] => Array
                                (
                                    [given_name] => Evanice
                                    [surname] => D
                                )

                            [address] => Array
                                (
                                    [address_line_1] => Av Benjamin Constant
                                    [admin_area_2] => Boca
                                    [admin_area_1] => FL
                                    [postal_code] => 12345
                                    [country_code] => US
                                )

                            [email_address] => buyer email
                        )

                    [shipping_info] => Array
                        (
                            [business_name] => Evanice Company
                            [name] => Array
                                (
                                    [given_name] => Evanice
                                    [surname] => D
                                )

                            [address] => Array
                                (
                                    [address_line_1] => Av Benjamin Constant
                                    [admin_area_2] => Boca
                                    [admin_area_1] => FL
                                    [postal_code] => 12345
                                    [country_code] => US
                                )

                            [email_address] => buyer email
                        )

                )

        )

    [items] => Array
        (
            [0] => Array
                (
                    [name] => Product title here
                    [description] => Description here
                    [quantity] => 1
                    [unit_amount] => Array
                        (
                            [currency_code] => USD
                            [value] => 80.00
                        )

                )

        )

)

 

 

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
MTS_Stefan
Moderator

Hello Ayrancd,

 

Based on the debug ID and the JASON, the ground structure is flawed, it throws errors at any stage from the detail field, over to invoice and addresses.

It might be easiest, to test this via sandbox and build the invoice up again from ground up.

I took the liberty to take some of your parameters and do that for you, here is the cURL request.

 

{
  "detail": {
    "invoice_number": "0002ASDFasdfasdf",
    "invoice_date": "2020-09-04",
    "currency_code": "USD",
    "note": "Thank you for your business.",
    "memo": "This is invoice is due in 24hrs after being generated.",
    "payment_term": {
      "term_type": "DUE_ON_DATE_SPECIFIED",
      "due_date": "2020-09-05"
    }
  },
  "invoicer": {
    "name": {
      "given_name": "first name",
      "surname": "last name"
    },
    "address": {
      "address_line_1": "1234 First Street",
      "address_line_2": "337673 Hillside Court",
      "admin_area_2": "Anytown",
      "admin_area_1": "CA",
      "postal_code": "98765",
      "country_code": "US"
    },
    "email_address": "email of api caller account matching first and last name in account",
    "phones": [
      {
        "country_code": "001",
        "national_number": "4085551234",
        "phone_type": "MOBILE"
      }
    ],
    "website": "www.test.com",
    "tax_id": "ABcNkWSfb5ICTt73nD3QON1fnnpgNKBy- Jb5SeuGj185MNNw6g",
    "logo_url": "https://example.com/logo.PNG",
    "additional_notes": "2-4"
  },
  "primary_recipients": [
    {
      "billing_info": {
        "name": {
          "given_name": "Stephanie",
          "surname": "Meyers"
        },
        "address": {
          "address_line_1": "1234 Main Street",
          "admin_area_2": "Anytown",
          "admin_area_1": "CA",
          "postal_code": "98765",
          "country_code": "US"
        },
        "email_address": "bill-me@example.com",
        "phones": [
          {
            "country_code": "001",
            "national_number": "4884551234",
            "phone_type": "HOME"
          }
        ],
        "additional_info_value": "add-info"
      },
      "shipping_info": {
        "name": {
          "given_name": "Stephanie",
          "surname": "Meyers"
        },
        "address": {
          "address_line_1": "1234 Main Street",
          "admin_area_2": "Anytown",
          "admin_area_1": "CA",
          "postal_code": "98765",
          "country_code": "US"
        }
      }
    }
  ],
  "items": [
    {
      "name": "Yoga Mat",
      "description": "Elastic mat to practice yoga.",
      "quantity": "1",
      "unit_amount": {
        "currency_code": "USD",
        "value": "80.00"
      }
    }
  ],
  "configuration": {
    "partial_payment": {
      "allow_partial_payment": true,
      "minimum_amount_due": {
        "currency_code": "USD",
        "value": "20.00"
      }
    },
    "allow_tip": true,
    "tax_calculated_after_discount": true,
    "tax_inclusive": false
  },
  "amount": {
    "breakdown": {
      "custom": {
        "label": "Packing Charges",
        "amount": {
          "currency_code": "USD",
          "value": "10.00"
        }
      },
      "shipping": {
        "amount": {
          "currency_code": "USD",
          "value": "10.00"
        },
        "tax": {
          "name": "Sales Tax",
          "percent": "7.25"
        }
      }
    }
  }
}

 

I hope this helps.

Stefan

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
ayrancd
Contributor

Hi Stefan, thank you for replying to me.

 

When you say

    "email_address": "email of api caller account matching first and last name in account",

Can that be any email? I've seen some sites like myslabs.com that uses the api to create an invoice using different emails (not the one from the api credential).

I also noticed that you added some fields that are not required... do I need them anyway?

 

  "amount": {
    "breakdown": {
      "custom": {
        "label": "Packing Charges",
        "amount": {
          "currency_code": "USD",
          "value": "10.00"
        }
      },
      "shipping": {
        "amount": {
          "currency_code": "USD",
          "value": "10.00"
        },
        "tax": {
          "name": "Sales Tax",
          "percent": "7.25"
        }
      }

 

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
ayrancd
Contributor

Just to clarify.

 

I'm using sandbox and I have this email there sb-rmnbb3131472@

 

So my test should be coming from it? What about when I use the live credential? Will I be able to use any email as the invoicer? Tks!

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
MTS_Stefan
Moderator
Hi Ayran,

No need to add all the fields I used, just habit I guess 🙂

The API caller is defined as the sandbox account which is linked to the REST App which's client ID/secret is used for the oAuthentication call.
The name (first,last) must match those in the API caller account. If SB-rmnbb3131472@ is the API caller, use the name from that account in the field outlined.
You can see the details of the account by using the login on sandbox.paypal.com which is the SB mirror of the live system.

The email is the receiver, so I would not use "any" but the one of the PayPal account, which is receiving the money of the invoice aka the API caller.

I hope this helps,
Stefan

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
ayrancd
Contributor

Hi Stefan,

 

After changing the email to the one in Sandbox, it worked
Per what I found... I have to send the invoice in order to make it public... and I did the "get" to the URL "/send" and got no response as it is in the documentation...

 

I'm a bit confused... The JSON returned when I create the invoice looks like:

 

Array ( [rel] => self [href] => https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-EMGM-XAC7-S4LZ-ERHR [method] => GET )

 

- Can you please guide me... how do I get the public URL to see the invoice like https://www.paypal.com/invoice/payerView/details/INV2-AQB4-WP2A-8YS4-K3KN (but using sandbox) ?

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
ayrancd
Contributor

I finally got access to sandbox... so I have two emails: 47bhgp3167914@ as the invoicer and sb-7qfhf3165049@ as the bill to.

 

I'm logged in https://www.sandbox.paypal.com/ on both accounts and I'm creating the invoice (https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-2GPN-DPLX-C857-FHFV ) and sending it POST https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-2GPN-DPLX-C857-FHFV/send

 

I don't see anything on both accounts... what step am I missing? lol tks

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
MTS_Stefan
Moderator

Hi Eleven41,

 

I would look for the invoices in the accounts of the receiver and sender:

- Dev Portal email notifications

MTS_Stefan_0-1599642278884.png

 

And logining into the account on sandbox.paypal.com which is the sandbox version of the live side, works the same way.

Regards,

Stefan

Solved

Invoice API - Request is not well-formed, syntactically incorrect, or violates schema

Options
Go to solution
ayrancd
Contributor

Hi Stefan,

 

noone.jpg

paypal.jpg

 

1 - How can I get the public URL of that invoice?
2 - Why can't I see any invoice on both accounts (invoicer or bill-to)?
3 - Is there anything else I should do with Array ( [rel] => self [href] => https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-EMGM-XAC7-S4LZ-ERHR [method] => GET )

 

Tks for helping me!!

View solution in original post

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.