API Integration: How to get complete order information from Shopware

I am developing an API integration with Shopware. Unfortunately, I don’t have access to full control over the Shopware website. The whole project is being developed by GetPrintBox (PBX). Some information: they made a controller for printing photos and photo albums based on Shopware. Of course, I don’t have access to most of the functions of the admin panel, including the code. The task: I need to send orders to CRM.

I have already developed the basic code, it looks something like this:

    $date = new \DateTimeImmutable();
    $now = $date->format($this->gpbFormatDateTime);
    $datetime_start_get_new = date($this->gpbFormatDateTime, (int)$datetime_start_get_new);
    if ($datetime_start_get_new == FALSE) {
        //get all orders (first request)
        $orderDateTime = [
            'type' => 'range',
            'field' => 'orderDateTime',
            'parameters' => [
                'gte' => '2022-01-01', // => (from)
            ]
        ];
    } else {
        $orderDateTime = [
            //if data has been created (in configs file) - get last orders
            "type" => "range",
            "field" => "orderDateTime",
            "parameters" => [
                "gte" => $datetime_start_get_new, // => (from)
                "lte" => $now // <= (to)
            ]
        ];
    }


    try {
        $response = $this->httpClient->request('GET', $this->baseUri . '/api/order', [ //ok
            'headers' => [
                'Authorization' => 'Bearer ' . $token,
                'Accept' => 'application/json'
            ],

            'query' => [
                'sort' => [
                    [
                        'field' => 'orderNumber',
                        'order' => 'asc'
                    ],
                ],
                "filter" => [
                    $orderDateTime,
                ],
                'associations' => [
                    'lineItems' => [
                        'associations' => [
                            'product' => [
                                'limit' => 1000, //all
                                'filter' => [
                                    "type" => "equals",
                                    "field" => "active",
                                    "value" => true
                                ]
                            ],
                        ],
                    ],
                    "deliveries" => [],
                    'billingAddress' => [
                        'limit' => 1,
                        'associations' => [
                            'country' => [
                                'limit' => 1
                            ],
                        ],
                    ],
                ]


            ]


        ]);
    } catch (ClientException $e) {
        $response = $e->getResponse();
    }

    $status_code = $response->getStatusCode();

    $body = $response->getBody();
    $contents = $body->getContents();

    $response = json_decode($contents);
    if ($status_code == 200) {
        $message = 'Action "getOrders NO Update". NO ERROR, Order received';
        Logger::log($message);
        return $response;
    } else {
        $message = 'Action "getOrders". Error: ' . $status_code . '. Info: ' . $response->errors[0]->title;
        Logger::log($message);
        return FALSE;
    }

I get this:

Example order:

[apiAlias] => 
                            )

                    )

                [_uniqueIdentifier] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                [versionId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                [translated] => Array
                    (
                    )

                [createdAt] => 2024-05-26T11:21:55.334+00:00
                [updatedAt] => 2024-05-26T12:17:50.335+00:00
                [orderNumber] => 10669
                [currencyId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                [currencyFactor] => 1
                [salesChannelId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                [billingAddressId] => fda035734dc64f16a4ae3ca827ed6ec8
                [orderDateTime] => 2024-05-26T11:21:54.624+00:00
                [orderDate] => 2024-05-26T00:00:00.000+00:00
                [price] => stdClass Object
                    (
                        [extensions] => Array
                            (
                            )

                        [netPrice] => 730
                        [totalPrice] => 730
                        [calculatedTaxes] => Array
                            (
                            )

                        [taxRules] => Array
                            (
                            )

                        [positionPrice] => 730
                        [taxStatus] => tax-free
                        [rawTotal] => 730
                        [apiAlias] => cart_price
                    )

                [amountTotal] => 730
                [amountNet] => 730
                [positionPrice] => 730
                [taxStatus] => tax-free
                [shippingCosts] => stdClass Object
                    (
                        [extensions] => Array
                            (
                            )

                        [unitPrice] => 0
                        [quantity] => 1
                        [totalPrice] => 0
                        [calculatedTaxes] => Array
                            (
                            )

                        [taxRules] => Array
                            (
                            )

                        [referencePrice] => 
                        [listPrice] => 
                        [regulationPrice] => 
                        [apiAlias] => calculated_price
                    )

                [shippingTotal] => 0
                [orderCustomer] => stdClass Object
                    (
                        [extensions] => stdClass Object
                            (
                                [foreignKeys] => stdClass Object
                                    (
                                        [extensions] => Array
                                            (
                                            )

                                        [apiAlias] => 
                                    )

                                [internal_mapping_storage] => stdClass Object
                                    (
                                        [extensions] => Array
                                            (
                                            )

                                        [apiAlias] => 
                                    )

                            )

                        [_uniqueIdentifier] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [versionId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [translated] => Array
                            (
                            )

                        [createdAt] => 2024-05-26T11:21:55.330+00:00
                        [updatedAt] => 
                        [email] => Denis@denis.com
                        [orderId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [salutationId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [firstName] => Denis
                        [lastName] => Denis
                        [title] => 
                        [vatIds] => 
                        [company] => 
                        [customerNumber] => 10736
                        [customerId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [customer] => 
                        [salutation] => 
                        [order] => 
                        [remoteAddress] => 91.196.55.0
                        [id] => 4008bc562a9047fd98c5707c8b8c1566
                        [customFields] => stdClass Object
                            (
                                [pbx_pbx2_model_name] => Customer
                                [pbx_pbx2_customer_id] => 76249
                            )

                        [orderVersionId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [apiAlias] => order_customer
                    )

                [currency] => 
                [languageId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                [language] => 
                [salesChannel] => 
                [addresses] => 
                [billingAddress] => 
                [deliveries] => 
                [lineItems] => 
                [transactions] => 
                [deepLinkCode] => qqqqqqqqqqqqqqqqqqqqqqqqqq-q
                [autoIncrement] => 806
                [stateMachineState] => stdClass Object
                    (
                        [extensions] => stdClass Object
                            (
                                [foreignKeys] => stdClass Object
                                    (
                                        [extensions] => Array
                                            (
                                            )

                                        [apiAlias] => 
                                    )

                                [internal_mapping_storage] => stdClass Object
                                    (
                                        [extensions] => Array
                                            (
                                            )

                                        [apiAlias] => 
                                    )

                            )

                        [_uniqueIdentifier] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [versionId] => 
                        [translated] => stdClass Object
                            (
                                [name] => In Progress
                                [customFields] => Array
                                    (
                                    )

                            )

                        [createdAt] => 2021-01-29T18:24:22.731+00:00
                        [updatedAt] => 
                        [name] => In Progress
                        [technicalName] => in_progress
                        [stateMachineId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [stateMachine] => 
                        [fromStateMachineTransitions] => 
                        [toStateMachineTransitions] => 
                        [translations] => 
                        [orders] => 
                        [orderTransactionCaptures] => 
                        [orderTransactionCaptureRefunds] => 
                        [orderTransactions] => 
                        [orderDeliveries] => 
                        [fromStateMachineHistoryEntries] => 
                        [toStateMachineHistoryEntries] => 
                        [id] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [customFields] => 
                        [apiAlias] => state_machine_state
                    )

                [stateId] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                [documents] => 
                [tags] => 
                [affiliateCode] => 
                [campaignCode] => 
                [customerComment] => 
                [ruleIds] => Array
                    (
                        [0] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [1] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [2] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [3] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [4] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                        [5] => qqqqqqqqqqqqqqqqqqqqqqqqqq
                    )

                [createdById] => 
                [createdBy] => 
                [updatedById] => 
                [updatedBy] => 
                [itemRounding] => stdClass Object
                    (
                        [extensions] => Array
                            (
                            )

                        [decimals] => 2
                        [interval] => 0.01
                        [roundForNet] => 1
                        [apiAlias] => shopware_core_framework_data_abstraction_layer_pricing_cash_rounding_config
                    )

                [totalRounding] => stdClass Object
                    (
                        [extensions] => Array
                            (
                            )

                        [decimals] => 2
                        [interval] => 0.01
                        [roundForNet] => 1
                        [apiAlias] => shopware_core_framework_data_abstraction_layer_pricing_cash_rounding_config
                    )

                [id] => 007e0f8c20244319a65c524d6a2173ee
                [customFields] => stdClass Object
                    (
                        [pbx_pbx2_order_id] => 185
                        [pbx_pbx2_model_name] => Order
                        [pbx_pbx2_order_is_testing] => 
                    )

                [billingAddressVersionId] => qqqqqqqqqqqqqqqqqqqq
                [apiAlias] => order
            )

(I replaced some data with the “q” symbol)
_
Problem: I do not receive complete information about the order. For example, I do not receive information about deliveries and payments. In the settings, I saw that I don’t have the “Administrator” access right.
I need help. Thank you!

You can try to request the data from the API with an API user, that is an admin (you can set this directly on the user in the Shopware admin area)

To get the Bearer token, use the /api/oauth/token endpoint to recieve the corresponding Bearer token with the user’s credentials

Yes. Yeah. Thank you. I have already received an API token with a key and a secret code. Everything’s good here.
The main problem is to get information about deliveries and payments.

Hi. I’ve figured out my problem.
If anyone is interested:
Administrator rights have nothing to do with it.
You just need to write the request correctly.)
For example, for transactions:

"transactions" => [
                            'limit' => 1,
                            "associations" => [
                                "paymentMethod" => [
                                    'limit' => 1,
                                ]
                            ]
                        ],

For example, for deliveries:

"deliveries" => [
                            'limit' => 1,
                            "associations" => [
                                "shippingMethod" => [
                                    'limit' => 1,
                                ]
                            ]
                        ],

All this must be specified in the request.
The logic of the system is that each object needs to be asked, let’s say, to make a request, for receive it.


If you have any additional questions, please contact me and I will try to help.