Jump to content

[Solved] Cannot get PW to process POST with JSON


artaylor
 Share

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...

 

Link to comment
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
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...