cancel
Showing results for 
Search instead for 
Did you mean: 

v2 - update/patch Order - INVALID_JSON_POINTER_FORMAT

Options
fra105
Contributor
Posted on

I feel stupid. No one else seems to have this problem.

I want to replace "purchase_units". According to the docs it can be replaced. But it is not working. Patching a single property of purchase_units is also not working.

 

Request:

 

curl -v -X PATCH <a href="https://api.sandbox.paypal.com/v2/checkout/orders/ORDER_ID/" target="_blank">https://api.sandbox.paypal.com/v2/checkout/orders/ORDER_ID/</a> -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" -d '[{"op":"replace","path":"/purchase_units/@reference_id=='default'","value":[{"amount":{"currency_code":"EUR","value":"11.22"}}]}]'

 

 

Response:

 

{"name":"UNPROCESSABLE_ENTITY","details":[{"field":"path","value":"/purchase_units/@reference_id==default","location":"body","issue":"INVALID_JSON_POINTER_FORMAT","description":"Path should be a valid JSON Pointer <a href="https://tools.ietf.org/html/rfc6901" target="_blank">https://tools.ietf.org/html/rfc6901</a> that references a location within the request where the operation is performed."}],"message":"The requested action could not be performed, semantically incorrect, or failed business validation.","debug_id":"b25a467e2950a","links":[{"href":"<a href="https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_JSON_POINTER_FORMAT","rel":"informati..." target="_blank">https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_JSON_POINTER_FORMAT","rel":"informati...>"}]}

 

 

The example in the docs is also not working. invoice_id is being patched but the value passed is an object with the property integration_artifact?? This makes no sense. invoice_id should be a string.

 

Please help ;(

10 REPLIES 10

v2 - update/patch Order - INVALID_JSON_POINTER_FORMAT

Options
misteart
Contributor

fra105,

did you ever found a solution to your problem?

v2 - update/patch Order - INVALID_JSON_POINTER_FORMAT

Options
fra105
Contributor

I had to replace every value of purchase_units separately. And i also needed to escape the path properly. This is working for me now:

 

 

 

curl -v -X PATCH https://api.sandbox.paypal.com/v2/checkout/orders/ORDER_ID/ -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" -d '[{"op":"replace","path":"\/purchase_units\/@reference_id=='\''default'\''\/shipping\/name","value":{"full_name":"first_name last_name"}},{"op":"replace","path":"\/purchase_units\/@reference_id=='\''default'\''\/shipping\/address","value":{"address_line_1":"address_line_1","address_line_2":"address_line_2","admin_area_2":"admin_area_2","admin_area_1":"admin_area_1","postal_code":"01234","country_code":"DE"}},{"op":"replace","path":"\/purchase_units\/@reference_id=='\''default'\''\/amount","value":{"currency_code":"EUR","value":"123.45"}}]'

v2 - update/patch Order - INVALID_JSON_POINTER_FORMAT

Options
misteart
Contributor

Great job. I found that update works fine on the client side passing the data as shown in the Docs but not so much if you are making API or CURL calls.  In my case I am making API calls the adding all those escapes in your solution would be a nightmare.

If you take a look at the request body of the updateOrder, you would notice its in the form of a json object, specifically,

[

 {

   "op":"replace",

   "path":"/purchase_units/@reference_id=='E2217CCD3988082'/amount",

   "value":{"currency_code":"USD","value","1.00" }

 }

]

Now, we could attempt to create these by hand for each update. But, it is more useful to let the array and object building feature of your programming language do the work for you. Its less prone to errors you cant see and no need to be adding escapes.

Here is a sample from Coldfusion of what worked for me:

<cfset refNo= reference_id From OrderDetails/>

<cfset orderID= id From OrderDetails/>

<cfset updStruct = structNew()/>
<cfset updStruct["op"] ="add"/>
<cfset updStruct["path"] = "/purchase_units/@reference_id=='#refNo#'/invoice_id" />
<cfset updStruct["value"] = Order.ordernumber/>
<cfset arrayAppend(updateArr,updStruct)/>
<cfset toJson = serializeJson(updateArr)>
<cfset application.PaypalManager.updateOrder(aToken,orderID,toJson)/>

 

As you can see struct is already a json type object and so I was able to just pass the values into the keys. And the path was passed without escapes. then, serializeJson() just converts it to a string correcting for any errors in could create trying to create that json string manually

v2 - update/patch Order - INVALID_JSON_POINTER_FORMAT

Options
mista_y
New Community Member

thank you very much for posting your solution. worked for me as well. don't know why paypal provides wrong example code in api documentation. seems that nobody even tried it. again, great work, thanks!

v2 - update/patch Order - INVALID_JSON_POINTER_FORMAT

Options
GreenJesterAt
Member

I am having the same problem: My Use-Case: If the buyer cancels the approval, I send him beck to payment options. From there he can go back and change the cart (as well as the address). I would want to re-use the created PP order object and change the items, etc.

 

According to https://developer.paypal.com/docs/api/orders/v2/#orders_patch, it should be possible to patch the whole purchase_units array. The workaround posted here - to patch the values underneath - does not fulfil my requirements, because I use the items object to list the cart content. And the items attribute cannot be patched.

 

If you look more closely into the created order object (by retreiving it after creation), you will see that PP adds the payee property as well, which again is not part of the list of patchable properties.

 

So, I guess that the doc wants to tell us that the purchase_units array is "partly pathcable", listing which properties and sub-properties are patchable. Then it makes sense that you can't patch the whole purchase_units array, because that would violate the "non-patchable" rule for properties like items and payee.

 

A pitty, though, because I can't imagine any reason why I cannot change the items but I can change the amount. Maybe it makes sense for an order in "APPROVED" status, but not in "CREATED".

 

So finally, I end up throwing the old order object away and creating a new one.

v2 - update/patch Order - INVALID_JSON_POINTER_FORMAT

Options
nkavian
Contributor

Don't feel stupid. PayPal APIs are poorly designed and poorly documented.

 

I can 'add' a description and invoice_id, but the API won't let me 'replace' the full_name or shipping information. I've spent so much more time integrating PayPal than I did Checkout.com or Stripe.

v2 - update/patch Order - INVALID_JSON_POINTER_FORMAT

Options
bhavikagrawal
Contributor

If you want to patch the entire purchase unit, use the below syntax

[
  {
    "op": "replace",
    "path": "/purchase_units/@reference_id=='default'",
    "value": {
      "amount": {
        "currency_code": "USD",
        "value": "53.42",
        "breakdown": {
          "item_total": {
            "currency_code": "USD",
            "value": "39.98"
          },
          "shipping": {
            "currency_code": "USD",
            "value": "9.99"
          },
          "tax_total": {
            "currency_code": "USD",
            "value": "3.45"
          },
          "shipping_discount": {
            "currency_code": "USD",
            "value": "0.00"
          }
        }
      },
      "items": [
        {
          "name": "test",
          "unit_amount": {
            "currency_code": "USD",
            "value": "39.98"
          },
          "quantity":"1"
        }
      ]
    }
  }
]

 Note: the value contains is an object and not array. so it will automatically patch purchase_unit[0].
You can update items, amount, shipping address and other this way.

v2 - update/patch Order - INVALID_JSON_POINTER_FORMAT

Options
gcpman
Contributor

are you sure you can do a generic patch to all purchase_items? I'm getting this error currently

{"name":"UNPROCESSABLE_ENTITY","details":[{"field":"path","value":"/purchase_units/@reference_id=='default/","location":"body","issue":"INVALID_JSON_POINTER_FORMAT","description":"Path should be a valid JSON Pointer https://tools.ietf.org/html/rfc6901 that references a location within the request where the operation is performed.

This is my patch

[
{
"op": "replace",
"path": "\/purchase_units\/@reference_id=='default\/",
"value": {
"amount": {
"currency_code": "CAD",
"value": "27.90",
"breakdown": {
"shipping": {
"currency_code": "CAD",
"value": "7.90"
},
"tax_total": {
"currency_code": "CAD",
"value": "0.00"
},
"discount": {
"currency_code": "CAD",
"value": "0.00"
},
"item_total": {
"currency_code": "CAD",
"value": "20.00"
}
}
},
"items": [
{
"name": "gum x 1",
"unit_amount": {
"currency_code": "CAD",
"value": "10.00"
},
"tax": {
"currency_code": "CAD",
"value": "0.00"
},
"quantity": "1",
"description": "",
"category": "PHYSICAL_GOODS"
},
{
"name": "Gift wrapping x 1",
"unit_amount": {
"currency_code": "CAD",
"value": "10"
},
"tax": {
"currency_code": "CAD",
"value": "0.00"
},
"quantity": "1",
"description": "",
"category": "DIGITAL_GOODS"
}
]
}
}
]

 

v2 - update/patch Order - INVALID_JSON_POINTER_FORMAT

Options
vovkin
Contributor

@gcpman , it looks like path is incorrect in your request, it must be

"/purchase_units/@reference_id=='default'"

so you are missing single quote at the end. 

Haven't Found your Answer?

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