Kustom api Jalur api tidak valid

8

Jadi saya mengikuti contoh ini untuk membuat api kustom. Tetapi saya tidak yakin apakah saya menyebutnya salah atau kode saya salah. Inilah yang saya miliki.

Struktur folder:

Mycompany
    Syncreports
      etc
        api.xml
        wsi.xml
        wsdl.xml
      Model
        Sync
          Api
            V2.php
          Api.php

/app/etc/modules/Mycompany_Syncreports.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Syncreports>
            <active>true</active>
            <codePool>local</codePool>
    <depends>
                <Mage_Api />
            </depends>
        </Mycompany_Syncreports>
    </modules>
</config>

/app/code/local/Mycompany/Syncreports/etc/api.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Mycompany_Syncreports>
          <version>1.0.0</version>
        </Mycompany_Syncreports>
    </modules>
  <api>
      <resources>
        <syncreports_sync translate="title" module="mycompany_syncreports">
            <title>Synchronization API</title>
            <model>syncreports/sync_api</model>
            <acl>syncreports/sync</acl>
            <methods>
                <info translate="title" module="mycompany_syncreports">
                    <title>Retrieve synchronization info</title>
                    <acl>syncreports/sync/info</acl>
                    <method>info</method>
                </info>
            </methods>
            <faults module="mycompany_syncreports">
                <project_not_exists>
                    <code>101</code>
                    <message>Requested project does not exist.</message>
                </project_not_exists>
                <invalid_data>
                    <code>102</code>
                    <message>Provided data is invalid.</message>
                </invalid_data>
                <save_error>
                    <code>103</code>
                    <message>Error while saving project. Details in error message.</message>
                </save_error>
                <remove_error>
                    <code>104</code>
                    <message>Error while removing project. Details in error message.</message>
                </remove_error>
            </faults>
        </syncreports_sync>
    </resources>
    <resources_alias>
        <sync>syncreports_sync</sync>
    </resources_alias>
    <v2>
        <resources_function_prefix>
            <sync>syncreportsSync</sync>
        </resources_function_prefix>
    </v2>
    <acl>
        <resources>
            <syncreports translate="title" module="mycompany_syncreports">
                <title>SyncReports</title>
                <sync translate="title" module="mycompany_syncreports">
                    <title>Synchronization</title>
                    <sort_order>110</sort_order>
                    <info translate="title" module="mycompany_syncreports">
                        <title>Info</title>
                    </info>
                </sync>
            </syncreports>
        </resources>
    </acl>
  </api>
</config>

/app/code/local/Mycompany/Syncreports/etc/wsi.xml

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:typens="urn:{{var wsdl.name}}"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 name="{{var wsdl.name}}"
 targetNamespace="urn:{{var wsdl.name}}">
<wsdl:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:{{var wsdl.name}}">
        <xsd:complexType name="syncreportsSyncInfoEntity">
            <xsd:sequence>
                <xsd:element name="entity_id" type="xsd:string" />
                <xsd:element name="name" type="xsd:string" />
                <xsd:element name="description" type="xsd:string" />
                <xsd:element name="status" type="xsd:string" />
                <xsd:element name="created_at" type="xsd:string" />
                <xsd:element name="updated_at" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>
        <xsd:element name="syncreportsSyncInfoRequestParam">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="projectId" type="xsd:string" />
                </xsd:sequence>
             </xsd:complexType>
        </xsd:element>
        <xsd:element name="syncreportsSyncInfoResponseParam">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element minOccurs="1" maxOccurs="1" name="result" type="typens:portfolioProjectInfoEntity" />
                </xsd:sequence>
             </xsd:complexType>
        </xsd:element>
    </xsd:schema>
</wsdl:types>
<wsdl:message name="syncreportsSyncInfoRequest">
    <wsdl:part name="parameters" element="typens:syncreportsSyncInfoRequestParam" />
</wsdl:message>
<wsdl:message name="syncreportsSyncInfoResponse">
    <wsdl:part name="parameters" element="typens:syncreportsSyncInfoResponseParam" />
</wsdl:message>
<wsdl:portType name="{{var wsdl.handler}}PortType">
    <wsdl:operation name="syncreportsSyncInfo">
        <wsdl:documentation>Retrieve project info</wsdl:documentation>
        <wsdl:input message="typens:syncreportsSyncInfoRequest" />
        <wsdl:output message="typens:syncreportsSyncInfoResponse" />
    </wsdl:operation>

</wsdl:portType>
<wsdl:binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="syncreportsSyncInfo">
        <soap:operation soapAction="" />
        <wsdl:input>
            <soap:body use="literal" />
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal" />
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="{{var wsdl.name}}Service">
    <wsdl:port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
        <soap:address location="{{var wsdl.url}}" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

/app/code/local/Mycompany/Syncreports/etc/wsdl.xml

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
        <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
        <complexType name="syncreportsSyncInfoEntity"><!-- define type for retrieve info -->
            <all>
                <element name="entity_id" type="xsd:string" minOccurs="1" />
                <element name="name" type="xsd:string" minOccurs="1" />
                <element name="description" type="xsd:string" minOccurs="0" />
                <element name="status" type="xsd:string" minOccurs="0" />

                <element name="created_at" type="xsd:string" minOccurs="1" />
                <element name="updated_at" type="xsd:string" minOccurs="1" />
            </all>
        </complexType>
    </schema>
</types>
<message name="syncreportsSyncInfoRequest">
    <part name="sessionId" type="xsd:string" />
    <part name="projectId" type="xsd:string" />
</message>
<message name="syncreportsSyncInfoResponse">
    <part name="result" type="typens:syncreportsSyncInfoEntity" />
</message>
<portType name="{{var wsdl.handler}}PortType">
    <operation name="syncreportsSyncInfo">
        <documentation>Retrieve project info</documentation>
        <input message="typens:syncreportsSyncInfoRequest" />
        <output message="typens:syncreportsSyncInfoResponse" />
    </operation>
</portType>
<binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="syncreportsSyncInfo">
        <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
        <input>
            <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
        </input>
        <output>
            <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
        </output>
    </operation>
</binding>
<service name="{{var wsdl.name}}Service">
    <port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
        <soap:address location="{{var wsdl.url}}" />
    </port>
  </service>
</definitions>

/app/code/local/Mycompany/Syncreports/Model/Sync/Api.php

<?php
  class Mycompany_Syncreports_Model_Sync_Api extends Mage_Api_Model_Resource_Abstract
  {
      public function info($projectId){
    return "This is the message: ".$projectId;
      }
}

/app/code/local/Mycompany/Syncreports/Model/Sync/Api/V2.php

<?php
class Mycompany_Syncreports_Model_Sync_Api_V2 extends Mycompany_Syncreports_Model_Sync_Api{

  public function info($projectId){
    return "This is the message: ".$projectId;
  }
}

Dan ini adalah bagaimana saya memanggil api saya:

<?php
$host = "127.0.0.1/magento/index.php";
$client = new SoapClient("http://".$host. "/api/soap/?wsdl");
$apiuser= "user";
$apikey = "123456";
$action = "syncreports.info";

try { 
    $session_id= $client->login($apiuser, $apikey);
$result = array();

$result= $client->call($session_id, $action, array("test"));
    var_dump($result);
}
catch (Exception $e){
    echo var_dump($e);
    throw $e;
}
?>

Menggunakan coad ini saya mendapatkan error: Fatal error: Uncaught SoapFault exception: [3] Path api tidak valid

Ada ide bagaimana saya harus menyelesaikan ini?


/app/code/local/Mycompany/Syncreports/etc/config.xml

<?xml version="1.0" ?>
<config>
  <modules>
    <Mycompany_Syncreports>
        <version>1.0.0</version>
    </Mycompany_Syncreports>
</modules>
<global>
    <helpers>
        <mycompany_syncreports>
            <class>Mycompany_Syncreports_Helper</class>
        </mycompany_syncreports>
    </helpers>
</global>   
<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <foo_bar before="Mage_Adminhtml">Mycompany_Syncreports_Adminhtml</foo_bar>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

<frontend>
    <routers>
        <syncreports>
            <use>standard</use>
            <args>
                <module>Mycompany_Syncreports</module>
                <frontName>syncreports</frontName>
            </args>
        </syncreports>
    </routers>
</frontend>

<adminhtml>
    <layout>
        <updates>
            <syncreports>
                <file>mycompany/syncreports.xml</file>
            </syncreports>
        </updates>
    </layout>
</adminhtml>    
</config>
intentarr
sumber

Jawaban:

6

Nama tindakan Anda seharusnya

$action = 'syncreports_sync.info';

Secara umum di sini adalah bagaimana tampilan nama metode API v1.

entity_alias.method
   |           |
   |           |------------the name of the method to call.Child of the `<methods>` tag in the `api.xml` file
   |  
   |--- the tag name you specified in `api.xml` inside the `<resources>` tag

[EDIT]
Masalah Anda yang lain disebabkan oleh fakta bahwa Anda kehilangan deklarasi model config.xml.
Tambahkan ini di dalam <global>tag

<models>
    <syncreports>
        <class>Mycompany_Syncreports_Model</class>
    </syncreports>
</models>

Jika Anda ingin menggunakan mycompany_syncreportssebagai model alias seperti yang Anda lakukan untuk helper, letakkan xml ini di atas

<models>
    <mycompany_syncreports>
        <class>Mycompany_Syncreports_Model</class>
    </mycompany_syncreports>
</models>

Tetapi dalam hal ini Anda perlu memodifikasi api.xml.
Ubah baris ini:

<model>syncreports/sync_api</model>

Untuk yang ini

<model>mycompany_syncreports/sync_api</model>
Marius
sumber
Marius terima kasih banyak atas jawaban Anda. Saya mengubah tindakan saya seperti yang Anda katakan. Tapi sekarang saya mendapatkan kesalahan lain: Kesalahan fatal: Pengecualian Uncaught SoapFault: [4] Jalur sumber daya tidak dapat dipanggil. Apakah Anda punya ide apa yang dapat menyebabkan kesalahan ini?
intentarr
@intentarr. Pengecualian dimasukkan Mage_Api_Model_Server_Handler_Abstract. cari kodenya throw new Mage_Api_Exception('resource_path_not_callable');. Anda dapat men-debug dari sana. Ada 4 kejadian seperti itu. Kemungkinan besar model Anda tidak dikonfigurasikan dengan benar. Tambahkan config.xmlmodul Anda ke pertanyaan. Itu bisa menjelaskan semuanya
Marius
Saya menambahkan file config.xml dan saya juga akan mencari pengecualian resource_path_not_callable.
intentarr
@intentarr. Lihat pembaruan untuk jawaban saya. Terlalu besar untuk menambahkan komentar.
Marius
@Marius Terima kasih, $ action = 'syncreports_sync.info'; Penjelasan ini juga membantu saya.
Mukesh
0

Saya juga mengalami masalah yang sama (Jalur API tidak valid). Tolong ada yang tahu, tolong jawab saya .. Ini kode saya. Apa yang saya lakukan ??

api.xml

<resources>

  <arb translate="title" module="mymodule">

    <title>Chiragdodia module</title>

    <model>mymodule/api</model>

    <methods>

      <storesList translate="title" module="mymodule">
        <title>Retrieve list of installed stores</title>
        <acl>arb/storesList</acl>
      </storesList>

    </methods>


  </arb>
</resources>
<acl>
  <resources>
    <arb translate="title" module="mymodule">
      <title>arb</title>
      <create translate="title" module="mymodule">
        <title>Create product</title>
      </create>

    </arb>
  </resources>
</acl>
  <v2>
  <resources_function_prefix>
    <arb>arb</arb>
  </resources_function_prefix>
</v2>

config.xml

1.1.65

<global>
    <helpers>
        <mymodule>
            <class>Chiragdodia_Mymodule_Helper</class>
        </mymodule>
    </helpers>
    <models>
        <catalog>
            <rewrite>
                <category_api>Chiragdodia_Mymodule_Model_Category_Api</category_api>
                <product_api>Chiragdodia_Mymodule_Model_Product_Api</product_api>
                <product_attribute_api>Chiragdodia_Mymodule_Model_Product_Attribute_Api</product_attribute_api>
                <product_attribute_media_api>Chiragdodia_Mymodule_Model_Product_Attribute_Media_Api</product_attribute_media_api>
                <product_link_api>Chiragdodia_Mymodule_Model_Product_Link_Api</product_link_api>
            </rewrite>
        </catalog>
        <core>
            <rewrite>
                <url>Chiragdodia_Mymodule_Model_Core_Url</url>
                <store>Chiragdodia_Mymodule_Model_Core_Store</store>
            </rewrite>
        </core>
        <mymodule>
            <class>Chiragdodia_Mymodule_Model</class>
        </mymodule> 
    </models>
</global>

vicky
sumber
0

nama sumber tidak boleh sama dengan mengikuti api.xml

<rescustomapi>adalah nama sumber saya sementara customapi adalah nama modul saya. Mungkin Anda memiliki kedua nama yang sama.

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <rescustomapi translate="title" module="customapi">
                <model>customapi/helloworld_api</model>
                <title>Custom HelloWorld API</title>
                <methods>
                   <setddapi translate="title" module="customapi">
                        <title>Mydons HelloWorld API</title>
                   </setddapi>
                </methods>
                <faults module="customapi">
                    <data_invalid>
                        <code>100</code>
                        <message>Invalid data</message>
                    </data_invalid>
                </faults>
            </rescustomapi>
          </resources>
      </api>
</config>
Pengembang PHP Magento
sumber