Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

PriceList and assign marketID GRAPHSQL

PriceList and assign marketID GRAPHSQL

pstanek
Shopify Partner
8 0 1

Hello

 

I need to create a PriceList and assign a MarketID but I have an error. It stopped working SUDDENLY.

Can anyone tell me what might be wrong?? Thank you

 

 

$ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json','X-Shopify-Access-Token:'.$data['api_password']));
        curl_setopt($ch, CURLOPT_URL, 'https://'.$data['api_host'].'/admin/api/2023-01/graphql.json');
        curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS ,'{"query": "mutation PriceListCreate($input: PriceListCreateInput!) { priceListCreate(input: $input) { userErrors { field message } priceList { id name currency contextRule { market { id } } parent { adjustment { type value } } } } }","variables": {"input": {"name": "'.$data['currency'].'_'.$data['name'].'","currency": "'.$data['currency'].'","contextRule": {"marketId": "'.$data['marketId'].'"},"parent": {"adjustment": {"type": "PERCENTAGE_DECREASE","value": 0}}}}}');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_VERBOSE, true);

        $result=curl_exec ($ch);

        curl_close ($ch);
        $array = json_decode($result, true);

 

Error:

[errors] => Array
        (
            [0] => Array
                (
                    [message] => Field 'contextRule' doesn't exist on type 'PriceList'
                    [locations] => Array
                        (
                            [0] => Array
                                (
                                    [line] => 1
                                    [column] => 150
                                )

                        )

                    [path] => Array
                        (
                            [0] => mutation PriceListCreate
                            [1] => priceListCreate
                            [2] => priceList
                            [3] => contextRule
                        )

                    [extensions] => Array
                        (
                            [code] => undefinedField
                            [typeName] => PriceList
                            [fieldName] => contextRule
                        )

                )

        )

 

Reply 1 (1)

SBD_
Shopify Staff
1831 273 421

Hey @pstanek 

 

Are you able to remove `contextRule { market { id } }` from the query? This field isn't available.

Scott | Developer Advocate @ Shopify