T
T
Timur Yakhin2016-10-10 08:22:43
XML
Timur Yakhin, 2016-10-10 08:22:43

How to form a query according to grammars from WADL?

There is a service with an API. The scheme of working with the API is described by WADL

<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:tns="http://client.pub.api.cloudpbx.beeline.ru" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wadl.dev.java.net/2009/02 wadl.xsd">
    <grammars>
        <xs:schema xmlns:tns="http://client.pub.api.cloudpbx.beeline.ru" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://client.pub.api.cloudpbx.beeline.ru">           
            <xs:element name="AbonentList">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="list" ref="tns:Abonent"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

            <xs:element name="ListCallRecordRequest">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="1" minOccurs="1" name="pageNumber" type="xs:long"/>
                        <xs:element maxOccurs="1" minOccurs="1" name="pageSize" type="xs:long"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="userId" type="xs:string"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="phone" type="xs:string"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="direction" type="tns:Direction"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="dateFrom" type="xs:dateTime"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="dateTo" type="xs:dateTime"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="durationFrom" type="xs:long"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="durationTo" type="xs:long"/>
                        <xs:element maxOccurs="1" minOccurs="1" name="sort">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element maxOccurs="1" minOccurs="1" name="direction" type="tns:SortDirection"/>
                                    <xs:element maxOccurs="1" minOccurs="1" name="field" type="tns:ListCallRecordRequestSortField"/>
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

            <xs:element name="ListCallRecordResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="totalRecordQuantity" type="xs:long"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="list" ref="tns:CallRecord"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            
            <xs:element name="CallRecord">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="1" minOccurs="0" name="recordId" type="xs:long"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="abonent" ref="tns:Abonent"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="phone" type="xs:string"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="callDirection" type="tns:Direction"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="date" type="xs:dateTime"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="duration" type="xs:long"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="fileSize" type="xs:long"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="comment" type="xs:string"/>
                        <xs:element maxOccurs="1" minOccurs="0" name="externalId" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            
            <xs:element name="AgentStatusResponce">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="1" minOccurs="1" name="status" type="tns:AgentStatus"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

            <xs:simpleType name="ListCallRecordRequestSortField">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="Date"/>
                    <xs:enumeration value="Phone"/>
                    <xs:enumeration value="AbonentFio"/>
                    <xs:enumeration value="Comment"/>
                    <xs:enumeration value="Duration"/>
                    <xs:enumeration value="Direction"/>
                </xs:restriction>
            </xs:simpleType>

            <xs:simpleType name="Direction">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="INB"/>
                    <xs:enumeration value="OUT"/>
                </xs:restriction>
            </xs:simpleType>

            <xs:simpleType name="SortDirection">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="ASC"/>
                    <xs:enumeration value="DESC"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:schema>
    </grammars>

    <resources base="http://cloudpbx.beeline.ru/api/pub">
        <resource id="ClientPublicApiResource" path="/client">
            <resource path="/abonent">
                <method id="listAbonent" name="GET">
                    <response>
                        <representation element="tns:AbonentList" mediaType="application/xml"/>
                    </response>
                </method>
            </resource>
            <resource path="/abonent/{numberOrExtensionOrUserId}">
                <param name="numberOrExtensionOrUserId" style="template" type="xs:string"/>
                <method id="getAbonent" name="GET">
                    <response>
                        <representation element="tns:Abonent" mediaType="application/xml"/>
                    </response>
                </method>
            </resource>
            <resource path="/call/record">
                <resource path="/file/{recordIdOrExternalId}">
                    <param name="recordIdOrExternalId" style="template" type="xs:string"/>
                    <method id="getCallRecord" name="GET">
                        <response>
                            <representation mediaType="application/octeat-stream"/>
                        </response>
                    </method>
                </resource>
                <resource path="/list">
                    <method id="listCallRecord" name="PUT">
                        <request>
                            <representation element="tns:ListCallRecordRequest" mediaType="application/xml"/>
                        </request>
                        <response>
                            <representation element="tns:ListCallRecordResponse" mediaType="application/xml"/>
                        </response>
                    </method>
                </resource>
            </resource>
        </resource>
    </resources>
</application>

According to this document, it was possible to form a request /client/subscriber/ that does not require input data. The /client/call/record/list request requires input data, in XML format, the format is described in the section
<xs:element name="ListCallRecordRequest">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="1" minOccurs="1" name="pageNumber" type="xs:long"/>
            <xs:element maxOccurs="1" minOccurs="1" name="pageSize" type="xs:long"/>
            <xs:element maxOccurs="1" minOccurs="0" name="userId" type="xs:string"/>
            <xs:element maxOccurs="1" minOccurs="0" name="phone" type="xs:string"/>
            <xs:element maxOccurs="1" minOccurs="0" name="direction" type="tns:Direction"/>
            <xs:element maxOccurs="1" minOccurs="0" name="dateFrom" type="xs:dateTime"/>
            <xs:element maxOccurs="1" minOccurs="0" name="dateTo" type="xs:dateTime"/>
            <xs:element maxOccurs="1" minOccurs="0" name="durationFrom" type="xs:long"/>
            <xs:element maxOccurs="1" minOccurs="0" name="durationTo" type="xs:long"/>
            <xs:element maxOccurs="1" minOccurs="1" name="sort">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="1" minOccurs="1" name="direction" type="tns:SortDirection"/>
                        <xs:element maxOccurs="1" minOccurs="1" name="field" type="tns:ListCallRecordRequestSortField"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

How to generate such a request?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Timur Yakhin, 2016-10-10
@temoffey

It turned out that in the grammars section there is either a body or a link to the XSD Schema File. To generate XML from XSD (contents of the grammars section), I used the xmlgrid.net/genXml.html service
I generated an xml document:

<?xml version="1.0" encoding="utf-8"?>
<tns:ListCallRecordRequest xmlns:tns="http://client.pub.api.cloudpbx.beeline.ru">
<pageNumber>0</pageNumber> 
<pageSize>200</pageSize>
<direction>INB</direction>
<dateFrom>2004-02-12T15:19:21+00:00</dateFrom>
<dateTo>2004-02-12T15:19:21+00:00</dateTo>
<sort>
<direction>ASC</direction>
<field>Date</field>
</sort>
</tns:ListCallRecordRequest>

where:
pageNumber - sequence number of the selection
pageSize - number of elements of the selection
direction - direction (INB - incoming)
dateFrom, dateTo - selection range, dates in ISO 8601 format
sort - sorting
sort - field - which field to sort by
sort - direction - sorting direction ( ASC - ascending)
and sent the request using the "PUT" method, with the header "Content-type: application/xml" to the address "/api/pub/client/call/record/list"

C
classinfo, 2017-01-25
@classinfo

And then how to proceed? How specifically to connect to the API?

C
coolerpro08, 2017-01-31
@coolerpro08

Hello, I'm trying to do the same thing. But it responds with an error 415(Unsupported Media Type). If you don't mind, can you help me figure it out? Screenshot from fiddler attached. c18b6176b72e43cab5162a791eafa8a1.png
The issue was resolved by substitution in Content-type: not "/api/pub/client/call/record/list" but "xml"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question