1

I am trying to sent request to api to update the billing plan for paypal Rest Api.

API Link: https://developer.paypal.com/docs/api/payments.billing-plans#plan_update

The request method is:

HTTPoison.patch(Paypal.Config.url <> "/payments/billing-plans/#{plan.id}",
  [Poison.encode!(%{path: "/", value: %{"state" => "ACTIVE"}, op: "replace"})],
  Paypal.Authentication.headers, 
  timeout: :infinity, 
  recv_timeout: :infinity)
|> Paypal.Config.parse_response

But the response give me the error with format problem.

%{"debug_id" => "a673179dcd91", 
  "information_link" => "https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST", 
  "message" => "Incoming JSON request does not map to API request", 
  "name" => "MALFORMED_REQUEST"}

What the problem of my request?

Stephen
  • 3,822
  • 2
  • 25
  • 45
  • From the docs it looks like you are missing `/v1` from the start of your request (unless that is part of Paypal.Config.url). – Harrison Lucas Jul 07 '16 at 06:06
  • @HarrisonLucas Thanks for your answer. It's the part of the `Paypal.Config.url`. – Stephen Jul 07 '16 at 06:20
  • Try by adding the following to the headers' list: `{"Accept", "application/json"}` – ibizaman Jul 07 '16 at 06:25
  • @ibizaman Thanks for your answer. The headers don't have problem. cos I use the same for other api call and success. The problem must in the format of the body. I think is about deal with array `[]` – Stephen Jul 07 '16 at 06:42
  • Try by putting the `[]` inside `Poison.encode!` – ibizaman Jul 07 '16 at 06:44
  • @ibizaman have tried this `Poison.encode!([%{path: "/", value: %{"state" => "ACTIVE"}, op: "replace"}])` this one gives me the error `Unexpected end of input` – Stephen Jul 07 '16 at 06:51
  • Are you able to do a `IO.inspect` on Poison.encode? and add it to your question – Harrison Lucas Jul 07 '16 at 06:51
  • @HarrisonLucas `["{\"value\":{\"state\":\"ACTIVE\"},\"path\":\"/\",\"op\":\"replace\"}"]` – Stephen Jul 07 '16 at 07:00
  • have you tried removing the `[]` around the Poison.encode!? – Harrison Lucas Jul 07 '16 at 10:27
  • @ibizaman after checking, your answer is correct, `Unexpected end of input` is happened on decode the patch response not the request step. The request is successful. Thanks – Stephen Jul 07 '16 at 23:34

0 Answers0