I'm struggling with an integration with a web service. A bit new to this, so I'm sure it's obvious, but I'm missing the how-to part.
I know how to handle data posted via AJAX to my PHP using something like this: $obj = $_POST['myData'];
I can handle this data just fine after that whether it be adding to a database or whatever.
Now I have a third party website that allows me to send an HTTP request. I need to supply the URL to the endpoint (which I'm assuming is the PHP file on my server I want to use to process the data).It's a POST request and I can create a body (in JSON format to send). I can construct this JSON with the right format and fields I need. Like this:
{
"val1":"12.121",
"val2":"232.4"
}
Here's the first question...what do I use in place of myData
in this line: $obj = $_POST['myData'];
? Do I need to somehow include the myData
part in my JSON body that I'm sending?
Once I have the data, I can parse it using json_decode
and go from there.
Final question...what's the best way to test this? When I'm using AJAX, I can just do a var_dump
for different variables and see what's working. How do I do something similar if data is being sent from a third party to my server?
Thanks!
EDIT: seeing the supposed duplicate post, but this situation is different in that I don't control the web service, so I can't really control how the code works on that end. All I can do is type in the body of the request that I can send in a sort of WYSIWYG editor.