我想在api网址中发送订单ID,并在json中获得正确的响应?

时间:2020-06-09 10:00:06

标签: php wordpress api woocommerce woocommerce-rest-api

响应:{“ Message”:“未找到与请求URI'http://example.com/Api/WooCommerceApi/SaveSubscriptionAndZoomData'匹配的HTTP资源。”,“ MessageDetail”:“在与请求匹配的控制器'WooCommerceApi'上未找到任何操作。“}

这是我的代码,用于在api网址中发送订单

function my_api_call( $order_id ){

// Order Setup Via WooCommerce

$order = new WC_Order( $order_id );

// Iterate Through Items

$items = $order->get_items();

$url = "http://example.com/Api/WooCommerceApi/SaveSubscriptionAndZoomData";

$orderid = "OrderId=".$order_id;

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $orderid);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );

 write_log ("Order Id for new user: " .$orderid ." and Response is : ".$response);

 }
 add_action( 'woocommerce_payment_complete', 'my_api_call');

1 个答案:

答案 0 :(得分:0)

您的答案就在错误消息中:

Response : {"Message":"No HTTP resource was found that matches the request URI 'http://example.com/Api/WooCommerceApi/SaveSubscriptionAndZoomData'.","MessageDetail":"No action was found on the controller 'WooCommerceApi' that matches the request."}

快速浏览WC文档不会显示任何具有该名称的端点,这就是错误消息告诉您的内容。确保您正在呼叫WC中实际存在的端点。

相关问题