Jump to content
artaylor

[Solved] Cannot get PW to process POST with JSON

Recommended Posts

Hi,

I have a site the interfaces with a payment processor. As transactions happen on the processor, it automatically calls endpoints on my application and passes a JSON body with the details. Working for a few hours with the payment processor support team we have figured out that the problem is the the endpoint is returning a 301 which they cannot handle. It is also converting the POST to a GET.

I thought it was due to the PagePathHistory module as at one point I did move the page to a new location in the tree. However, I have since then tried the following:

  1. Moved it back to the original place.
  2. Deleted and recreated
  3. Deleted and changed the name
  4. Truncated the page_path_history table in the database

However, I am still getting a 301 and my log file still shows a GET request.

Here is the code for the New Subscription endpoint

wire()->log()->save('ccbill', 'Add New Subscription Started');
wire()->log()->save('ccbill', 'Request Method: ' . $_SERVER['REQUEST_METHOD']);

$ccBillData = json_decode(file_get_contents('php://input'), true); // get the JSON encoded data and convert to PHP array
if ($ccBillData !== NULL) wire()->log()->save('ccbill', "Data: " . var_dump($ccBillData));

$ccBillIntegration = modules()->get('CcbillIntegration');
$ccBillIntegration->addNewSubscription($ccBillData);

And the results in the log file when I use an API Tester to POST to the endpoint with some JSON

2019-04-30 22:41:51	guest	http://site/subscription-new/	Add New Subscription Started
2019-04-30 22:41:51	guest	http://site/subscription-new/	Request Method: GET

Any and all help is appreciated. I have no hair left to pull out...

 

Share this post


Link to post
Share on other sites
16 minutes ago, artaylor said:

the problem is the the endpoint is returning a 301

A couple of things to check:

  • That you are calling the endpoint URL with/without a trailing slash according to the template "Should page URLs end with a slash?" setting.
  • If the site is multi-language that you are calling the endpoint URL with the language string in it, e.g. http://site/en/subscription-new/
  • Like 2

Share this post


Link to post
Share on other sites

@Robin S Adding the slash at the end worked.

You rock and my remaining strand of hair thanks you immensely for your prompt, working reply!

 

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...