J
J
jenny_sunny2017-10-03 12:56:42
1C-Bitrix
jenny_sunny, 2017-10-03 12:56:42

Get json data in Bitrix from a mobile application?

Hello!
You need to receive orders from the mobile application and add them to the Bitrix website.
New orders come from the POST mobile application as json:

{
    "version": "1.4.1",
    "method": "neworder",
    "platform": "android",
    "appId": 112065,
    "user": "user",
    "data": {
    "deliveryType": "Уточните у оператора",
    "deliveryData": [],
    "items": [
       {
          "count": 1,
          "id": "577094"
       }
    ],
    "fake": 0,
    "order_info": {
          "name": "тест",
          "phone": "999 999-99-99",
          "email": "[email protected]",
          "comments": null,
          "pointId": null,
          "regionId": "rest_267874043",
           "payment_type": {
              "id": "158ad92727wdew",
             "title": "Наличные",
             "type": "cash"
           }
        },
        "payment": {
           "type": "offline",
           "transactionId": null
        }
    },
    "region_data": {
        "full_title": "Москва, город Москва, Россия",
        "google_place_id": "ChIJybDUc_xKtUYRTM9XV8zWRD0",
        "id": "rest_267874043",
        "is_selected": true,
       "title": "Москва"
    },
    "access_token": null
};

How to get this data on Bitrix?
Added the getOrder.php script to the root of the Bitrix website:
$postData = file_get_contents('php://input');  // ловим данные
$data = json_decode($postData, true);

$file = 'order.txt';
$current = file_get_contents($file);
$current = $postData;
file_put_contents($file, $current); // записываем в файл

I want to check if the script works at all, so I send json data via ajax from another site (example above) and an error occurs:
POST http://--------------/getOrder.php 405 ( Not Allowed)
Failed to load http://---------/getOrder.php: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://--------- ' is therefore not allowed access. The response had HTTP status code 405.
So I understand that there is no access? Adding
header('Access-Control-Allow-Origin: *') to the receiving script doesn't change anything.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Emelyanov, 2017-10-03
@babarun

Does this url open in the browser?
*for debugging such things there is a wonderful Restlet Client tool

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question