提问人:Singleton 提问时间:3/20/2021 最后编辑:mvorisekSingleton 更新时间:3/30/2021 访问量:181
关于 API 和 Postman 的问题,或者无论如何检索数据和填充参数
Question about API's and Postman and or anyway to retrieve data and populate parameters
问:
不确定这是否可行,但这是我试图通过邮递员完成的工作,但我愿意使用终端或任何推荐的东西,如果它更容易的话。
我有这个xmlSoap文件,假设它驻留在这里:http://test.myapi.local:7947/my/path/here/myWSAPI
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:microsoft-dynamics-schemas/codeunit/myWSAPI"
targetNamespace="urn:microsoft-dynamics-schemas/codeunit/myWSAPI">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:microsoft-dynamics-nav/xmlports/x00000"
elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-nav/xmlports/x00000">
<complexType name="APIDataCapture">
<sequence>
<element minOccurs="1" maxOccurs="1" name="Type" type="string"/>
<element minOccurs="1" maxOccurs="1" name="Code" type="string"/>
<element minOccurs="1" maxOccurs="1" name="Qty1" type="string"/>
<element minOccurs="1" maxOccurs="1" name="Qty2" type="string"/>
<element minOccurs="1" maxOccurs="1" name="Qty3" type="string"/>
<element minOccurs="1" maxOccurs="1" name="Qty4" type="string"/>
</sequence>
</complexType>
<complexType name="Root" mixed="true">
<sequence>
<element minOccurs="1" maxOccurs="unbounded" name="APIDataCapture" type="tns:APIDataCapture"/>
</sequence>
</complexType>
<element name="Root" type="tns:Root"/>
</schema>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:microsoft-dynamics-nav/xmlports/x50014"
elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-nav/xmlports/x50014">
<complexType name="APIDataCapture">
<sequence>
<element minOccurs="1" maxOccurs="1" name="Type" type="string"/>
<element minOccurs="1" maxOccurs="1" default="0" name="EntryNo" type="int"/>
<element minOccurs="1" maxOccurs="1" name="SalesOrderFound" type="string"/>
<element minOccurs="1" maxOccurs="1" name="SalesOrderNo" type="string"/>
<element minOccurs="1" maxOccurs="1" default="0" name="SalesOrderLineNo" type="int"/>
<element minOccurs="1" maxOccurs="1" name="SalesOrderETADate" type="string"/>
<element minOccurs="1" maxOccurs="1" name="SalesOrderItemNo" type="string"/>
</sequence>
</complexType>
<complexType name="Root" mixed="true">
<sequence>
<element minOccurs="1" maxOccurs="unbounded" name="APIDataCapture" type="tns:APIDataCapture"/>
</sequence>
</complexType>
<element name="Root" type="tns:Root"/>
</schema>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="urn:microsoft-dynamics-schemas/codeunit/MyWSAPI">
<element name="Get_Item_ETA_Date">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="itemNo" type="string"/>
</sequence>
</complexType>
</element>
<element name="Get_Item_ETA_Date_Result">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="return_value" type="date"/>
</sequence>
</complexType>
</element>
<element name="Find_Duplicate_Ext_Doc_No">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="custNo" type="string"/>
<element minOccurs="1" maxOccurs="1" name="extDocNo" type="string"/>
</sequence>
</complexType>
</element>
<element name="Find_Duplicate_Ext_Doc_No_Result">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="return_value" type="boolean"/>
</sequence>
</complexType>
</element>
<element name="Get_Item_Quantity">
<complexType>
<sequence>
<element xmlns:q1="urn:microsoft-dynamics-nav/xmlports/x00000" minOccurs="1" maxOccurs="1"
name="aPIDataCapture" type="q1:Root"/>
</sequence>
</complexType>
</element>
<element name="Get_Item_Quantity_Result">
<complexType>
<sequence>
<element xmlns:q2="urn:microsoft-dynamics-nav/xmlports/x00000" minOccurs="1" maxOccurs="1"
name="aPIDataCapture" type="q2:Root"/>
</sequence>
</complexType>
</element>
<element name="GetSalesOrderETA">
<complexType>
<sequence>
<element xmlns:q3="urn:microsoft-dynamics-nav/xmlports/x50014" minOccurs="1" maxOccurs="1"
name="aPIDataCapture" type="q3:Root"/>
</sequence>
</complexType>
</element>
<element name="GetSalesOrderETA_Result">
<complexType>
<sequence>
<element xmlns:q4="urn:microsoft-dynamics-nav/xmlports/x50014" minOccurs="1" maxOccurs="1"
name="aPIDataCapture" type="q4:Root"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="Get_Item_ETA_Date">
<part name="parameters" element="tns:Get_Item_ETA_Date"/>
</message>
<message name="Get_Item_ETA_Date_Result">
<part name="parameters" element="tns:Get_Item_ETA_Date_Result"/>
</message>
<message name="Find_Duplicate_Ext_Doc_No">
<part name="parameters" element="tns:Find_Duplicate_Ext_Doc_No"/>
</message>
<message name="Find_Duplicate_Ext_Doc_No_Result">
<part name="parameters" element="tns:Find_Duplicate_Ext_Doc_No_Result"/>
</message>
<message name="Get_Item_Quantity">
<part name="parameters" element="tns:Get_Item_Quantity"/>
</message>
<message name="Get_Item_Quantity_Result">
<part name="parameters" element="tns:Get_Item_Quantity_Result"/>
</message>
<message name="GetSalesOrderETA">
<part name="parameters" element="tns:GetSalesOrderETA"/>
</message>
<message name="GetSalesOrderETA_Result">
<part name="parameters" element="tns:GetSalesOrderETA_Result"/>
</message>
<portType name="MyWSAPI_Port">
<operation name="Get_Item_ETA_Date">
<input name="Get_Item_ETA_Date" message="tns:Get_Item_ETA_Date"/>
<output name="Get_Item_ETA_Date_Result" message="tns:Get_Item_ETA_Date_Result"/>
</operation>
<operation name="Find_Duplicate_Ext_Doc_No">
<input name="Find_Duplicate_Ext_Doc_No" message="tns:Find_Duplicate_Ext_Doc_No"/>
<output name="Find_Duplicate_Ext_Doc_No_Result" message="tns:Find_Duplicate_Ext_Doc_No_Result"/>
</operation>
<operation name="Get_Item_Quantity">
<input name="Get_Item_Quantity" message="tns:Get_Item_Quantity"/>
<output name="Get_Item_Quantity_Result" message="tns:Get_Item_Quantity_Result"/>
</operation>
<operation name="GetSalesOrderETA">
<input name="GetSalesOrderETA" message="tns:GetSalesOrderETA"/>
<output name="GetSalesOrderETA_Result" message="tns:GetSalesOrderETA_Result"/>
</operation>
</portType>
<binding name="MyWSAPI_Binding" type="tns:MyWSAPI_Port">
<binding xmlns="http://schemas.xmlsoap.org/wsdl/soap/" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="Get_Item_ETA_Date">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/"
soapAction="urn:microsoft-dynamics-schemas/codeunit/MyWSAPI:Get_Item_ETA_Date" style="document"/>
<input name="Get_Item_ETA_Date">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</input>
<output name="Get_Item_ETA_Date_Result">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</output>
</operation>
<operation name="Find_Duplicate_Ext_Doc_No">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/"
soapAction="urn:microsoft-dynamics-schemas/codeunit/myWSAPI:Find_Duplicate_Ext_Doc_No"
style="document"/>
<input name="Find_Duplicate_Ext_Doc_No">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</input>
<output name="Find_Duplicate_Ext_Doc_No_Result">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</output>
</operation>
<operation name="Get_Item_Quantity">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/"
soapAction="urn:microsoft-dynamics-schemas/codeunit/myWSAPI:Get_Item_Quantity" style="document"/>
<input name="Get_Item_Quantity">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</input>
<output name="Get_Item_Quantity_Result">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</output>
</operation>
<operation name="GetSalesOrderETA">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/"
soapAction="urn:microsoft-dynamics-schemas/codeunit/myWSAPI:GetSalesOrderETA" style="document"/>
<input name="GetSalesOrderETA">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</input>
<output name="GetSalesOrderETA_Result">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</output>
</operation>
</binding>
<service name="myWSAPI">
<port name="myWSAPI_Port" binding="tns:MyWSAPI_Binding">
<address xmlns="http://schemas.xmlsoap.org/wsdl/soap/"
location="http://test.myapi.local:7947/my/path/here/myWSAPI"/>
</port>
</service>
</definitions>
我正在尝试调用 Web 服务中的“Get_Item_Quantity”函数。
函数名称:Get_Item_Quantity
此函数接受 ,并返回 、 、 和 参数:Type
Code fields
Qty1
Qty2
Qty3
Qty4
Type = 0 – input value
Code = ‘product100317’ – input value
Qty 1 – return value
Qty 2 – return value
Qty 3 – return value
Qty 4 – return value
我创建了一个文件CustomInterface.php
<?php
namespace Test\CustomApi\Api;
interface CustomInterface
{
/**
* GET for Qty api
* @param int $type
* @param string $code
* @return string
*/
public function getQty($type,$code);
}
以及一个名为 Custom.php 的文件
<?php
namespace Test\CustomApi\Model\Api;
use Psr\Log\LoggerInterface;
class Custom
{
protected $logger;
public function __construct(
LoggerInterface $logger
)
{
$this->logger = $logger;
}
/**
* @inheritdoc
*/
public function getQty($type,$code) {
$response = ['success' => false];
try {
// Logic to call soap service here
$qty = $this->getItemQty($type,$code);
$response = ['success' => true, 'qty' => $qty];
} catch (\Exception $e) {
$response = ['success' => false, 'message' => $e->getMessage()];
$this->logger->info($e->getMessage());
}
$returnArray = json_encode($response);
return $returnArray;
}
/**
* Soap API call
*
* @param int $type
* @param string $code
* @return void
*/
public function getItemQty($type,$code)
{
$soapRequest = '<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<Get_Item_Quantity xmlns="http://test.com/">
<Type>' . $type . '</Type>
<Code>' . $code . '</Code>
</Get_Item_Quantity>
</soap12:Body>
</soap12:Envelope>';
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
);
$soapHandler = curl_init();
curl_setopt($soapHandler, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
curl_setopt($soapHandler, CURLOPT_URL, "http://test.com/");
curl_setopt($soapHandler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($soapHandler, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($soapHandler, CURLOPT_POST, true);
curl_setopt($soapHandler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soapHandler, CURLOPT_POSTFIELDS, $soapRequest);
curl_setopt($soapHandler, CURLOPT_HTTPHEADER, $header);
curl_setopt($soapHandler, CURLOPT_FOLLOWLOCATION, false);
//header('Content-type: text/xml');
$result = curl_exec($soapHandler);
$qtyData = array();
if ($result === false) {
$err = 'Curl error: ' . curl_error($soapHandler);
curl_close($soapHandler);
$this->logger->info($err);
} else {
curl_close($soapHandler);
$xml = simplexml_load_string($result);
$xml->registerXPathNamespace('soap', 'http://www.w3.org/2003/05/soap-envelope');
$result = $xml->xpath('/soap:Envelope/soap:Body');
$res = $result[0]->Get_Item_Quantity_Result;
$qtyData = simplexml_load_string($res);
}
return $qtyData;
}
}
有没有办法将这些文件添加到邮递员和端点链接中,以测试我是否可以填充参数?有没有更简单的方法可以通过命令行和 curl 来做到这一点?我对任何途径都持开放态度。有点像邮递员和 API 调用的新手。
答: 暂无答案
评论
get
post