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.

API orders..refunds/calculate.json {"errors":{"refund":"Required parameter missing or invalid"}}

Solved

API orders..refunds/calculate.json {"errors":{"refund":"Required parameter missing or invalid"}}

akashtilva
Tourist
3 1 0

hello,

i'm calling /admin/api/2021-04/orders/{{XXX_ORDER_ID}}/refunds/calculate.json by php curl with below data

====================================================================

	$data = '{
  "refund": {
    "shipping": {
      "full_refund": true
    },
    "refund_line_items": [
      {
        "line_item_id": 9776518856882,
        "quantity": 1,
        "restock_type": "no_restock",
      }
    ]
  }
}';

i also tested with 

$data = '{
  "refund": {
    "shipping": {
      "full_refund": true
    }
  }
}';

 

====================================================================

  $curl = curl_init();
		   curl_setopt($curl, CURLOPT_POST, true);
		   if ($data)
		      curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

	curl_setopt_array($curl, array(
	  CURLOPT_URL => 'https://{{USER:PASS}}@{{MY_STORE}}.myshopify.com/admin/api/2021-04/orders/{{MY_ORDER_ID}}/refunds/calculate.json',
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_MAXREDIRS => 2,
	  CURLOPT_TIMEOUT => 0,
	  CURLOPT_FOLLOWLOCATION => false,
	));
  echo $result = curl_exec($curl);
  curl_close($curl);

 

but i'm getting response like this

{"errors":{"refund":"Required parameter missing or invalid"}}

 

however from same curl function by i can cancel order with 

kindly help me where i need to update.

 

Accepted Solution (1)
akashtilva
Tourist
3 1 0

This is an accepted solution.

Hello Kevin,

thank you for your response.

but i found the solution for the issue.

there was issue in curl arguments i passed.. due to which required data is not being transferred with POST request.

now below code is working perfect with any API call

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data))
);
$result = curl_exec($curl);
curl_close($curl);
?>

 

Thank you.

View solution in original post

Replies 2 (2)

Kevin_A
Shopify Staff
318 42 61

Hey @akashtilva 

Can you pass us an x-request-id response header for the call that isn't working?

Kevin_A | Solutions Engineer @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

akashtilva
Tourist
3 1 0

This is an accepted solution.

Hello Kevin,

thank you for your response.

but i found the solution for the issue.

there was issue in curl arguments i passed.. due to which required data is not being transferred with POST request.

now below code is working perfect with any API call

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data))
);
$result = curl_exec($curl);
curl_close($curl);
?>

 

Thank you.