cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
oguruma
Helper II
Helper II

Custom Connector: Array for query parameter?

I'm building a Custom Connector for ERPNext. It uses the Filter Parameter to filter for criteria.

 

The Parameter accepts an array of arrays. For example 

 

https://erp.com/api/resource/Lead/?fields=["name"]&filters=[["company_name","=","Microsoft"],["rating",">","1"]]

 

would filter for Leads with the company name "Microsoft," and a Rating greater than 1, and retrieve the "Name" field.

 

The problem is that when I try to describe this in the Custom Connector Wizard, I get the error message 

 

Your custom connector has been successfully updated, but there was an issue converting it to WADL for Power Apps: An error occured while converting OpenAPI file to WADL file. Error: 'Parameter with type='array' is not currently supported at JSON path paths['/api/resource/Lead/'].get.parameters[0]'

 

 

My Swagger is 

 

swagger: '2.0'
info: {title: ERPNext, description: '', version: '1.0'}
host: erp.com
basePath: /
schemes: [https]
consumes: []
produces: []
paths:
  /api/resource/Lead/:
    get:
      responses:
        default:
          description: default
          schema: {}
      summary: Filter Leads By Company Name
      operationId: LeadsByCompanyName
      parameters:
      - {name: fields, in: query, required: false, type: array}
      - {name: filters, in: query, required: false, type: array}
definitions: {}
parameters: {}
responses: {}
securityDefinitions:
  basic_auth: {type: basic}
security:
- basic_auth: []
tags: []

 

In Swagger, for the Parameters, I get the message "Schemas with type Array require sibling "Item" fields. 

6 REPLIES 6
HS_Nico
Helper II
Helper II

Hi @oguruma ,

 

try to use the official OpenAPI definition of ERPNext (ERPNext | 13 | alyf.de | SwaggerHub) in your connector. This has always worked well for me so far. Unfortunately I can't test it for your API because I don't have access to ERPNext.

 

Usually you can also create a connector directly from the definition (https://api.swaggerhub.com/apis/alyf.de/ERPNext/13), but unfortunately OpenAPI version 3 is still not supported.

 

I saw that version 14 of ERPNext already exists, unfortunately I could only find the OpenAPI definition in version 13.

Thanks for the input. I used an online tool to convert the V3 to V2 Swagger. I do get the error message below when I try to save the connector based on that definition. 

Specified swagger has the following errors: 'Definition is not valid. Error: 'Error : paths/~1method~1logout/get/responses/200/schema/default : The 'default' value is of type 'String', but should match the given type 'Object'. ## Error : paths/~1resource~1{DocType}/get/parameters/1/default : The 'default' value is of type 'String', but should match the given type 'Array'. '

 

swagger: '2.0'
info:
  version: '0.0.1'
  title: Frappe / ERPNext API
  description: >
    Unofficial documentation of the [Frappe](https://frappe.io) / [ERPNext](https://erpnext.org) API.
  contact:
    email: raffael@alyf.de
    name: Raffael Meyer
    url: https://alyf.de
host: demo.erpnext.com
basePath: /api
securityDefinitions:
  tokenAuth:
    type: apiKey
    description: >-
      Get your API keys at User -> Api Access -> Generate Keys.

      "headers = {'Authorization': 'token <api_key>:<api_secret>'}"
    name: Authorization
    in: header
  basicAuth:
    type: basic
    description: >
      Get your API keys at User -> Api Access -> Generate Keys.

      username = api_key; password = api_secret

      [More info](https://frappe.io/docs/user/en/guides/integration/token_based_auth)
  oAuth2:
    type: oauth2
    description: "This API uses OAuth 2 with the authorization code flow. \n[More info]https://frappe.io/docs/user/en/guides/integration/using_oauth)\n"
    flow: accessCode
    authorizationUrl: https://demo.erpnext.com/api/method/frappe.integrations.oauth2.authorize
    tokenUrl: https://demo.erpnext.com/api/method/frappe.integrations.oauth2.get_token
    scopes:
      all: Same permissions as the user who created the oAuth client
schemes:
- https
consumes:
- application/json
produces:
- application/json
paths:
  /method/login:
    post:
      description: Authenticate yourself
      summary: login
      tags:
      - Naive Authentication
      operationId: login
      deprecated: false
      produces:
      - application/json
      - text/html
      consumes:
      - application/x-www-form-urlencoded
      parameters:
      - name: usr
        in: query
        required: false
        type: string
        description: Your username
      - name: pwd
        in: query
        required: false
        type: string
        description: Your password
      - name: Content-Type
        in: header
        required: false
        enum:
        - application/x-www-form-urlencoded
        type: string
        description: ''
      - name: data
        in: formData
        required: false
        type: string
        description: ''
      responses:
        '200':
          description: Login successful
          schema:
            $ref: '#/definitions/MethodLoginResponse'
          headers: {}
        '401':
          description: oneOf(Incomplete login details, Incorrect password, User disabled or missing)
          schema:
            $ref: '#/definitions/MethodLogin401Error1'
          headers: {}
  /method/logout:
    get:
      description: Logout from current session
      summary: Logout from current session
      tags:
      - Naive Authentication
      operationId: Logoutfromcurrentsession
      deprecated: false
      produces:
      - application/json
      parameters: []
      responses:
        '200':
          description: Logged out.
          schema:
            type: object
            default: ''
          headers: {}
  /method/frappe.auth.get_logged_user:
    get:
      description: Get the currently logged in user
      summary: authGetLoggedUser
      tags:
      - Naive Authentication
      operationId: authGetLoggedUser
      deprecated: false
      produces:
      - application/json
      - text/html
      parameters: []
      responses:
        '200':
          description: search results matching criteria
          schema:
            $ref: '#/definitions/MethodFrappeAuthGetLoggedUserResponse'
          headers: {}
        '401':
          description: Not permitted
          schema:
            $ref: '#/definitions/MethodFrappeAuthGetLoggedUser401Error1'
          headers: {}
  /method/version:
    get:
      description: Get the version of the app
      summary: Get the version of the app
      operationId: Gettheversionoftheapp
      deprecated: false
      produces:
      - application/json
      parameters: []
      responses:
        '200':
          description: Successful
          schema:
            $ref: '#/definitions/MethodVersionResponse'
          headers: {}
  /resource/{DocType}:
    post:
      description: Create a new document
      summary: Create a new document
      operationId: Createanewdocument
      deprecated: false
      produces:
      - application/json
      - text/html
      consumes:
      - application/x-www-form-urlencoded
      parameters:
      - name: DocType
        in: path
        required: true
        type: string
        description: The DocType you'd like to receive. For example, Customer.
      - name: Content-Type
        in: header
        required: false
        enum:
        - application/x-www-form-urlencoded
        type: string
        description: ''
      - name: data
        in: formData
        required: false
        type: string
        description: ''
      responses:
        '200':
          description: Document created
          schema:
            $ref: '#/definitions/ResourceResponse'
          headers: {}
        '403':
          description: Insufficient Permission
          schema:
            $ref: '#/definitions/Resource403Error1'
          headers: {}
    get:
      description: Returns a list of documents of the given type
      summary: Get a list of documents
      operationId: Getalistofdocuments
      deprecated: false
      produces:
      - application/json
      parameters:
      - name: DocType
        in: path
        required: true
        type: string
        description: "The DocType you'd like to receive. For example Customer, Supplier, \nEmployee, Account, Lead, Company, Sales Invoice, Purchase Invoice, Stock Entry, etc."
      - name: fields
        in: query
        required: false
        default: >-
          [

            "name"

          ]
        type: array
        items:
          type: string
        description: "By default, only the \"name\" field is included in the listing, to add more fields, \nyou can pass the fields param to GET request. For example, fields=[\"name\",\"country\"]"
      - name: filters
        in: query
        required: false
        type: array
        items:
          type: array
          items:
            type: string
        description: >-
          You can filter the listing using sql conditions by passing them as the filters GET param.

          Each condition is an array of the format, [{doctype}, {field}, {operator}, {value}].

          For example, filters=[["Customer", "country", "=", "India"]]
      - name: limit_page_length
        in: query
        required: false
        default: 20
        type: integer
        format: int32
        description: "By default, all listings are returned paginated. With this parameter you can change the \npage size (how many items are teturned at once)."
      - name: limit_start
        in: query
        required: false
        default: 0
        type: integer
        format: int32
        description: "To request successive pages, pass a multiple of your limit_page_length as limit_start. \nFor Example, to request the second page, pass limit_start as 20."
      responses:
        '200':
          description: "Found requested DocType. By default, only the \"name\" field is included in the listing, \nto add more fields, you can pass the fields param to GET request."
          schema:
            $ref: '#/definitions/DocList'
          headers: {}
  /resource/{DocType}/{DocumentName}:
    get:
      description: Get a document by it's name, for example EMP001 of DocType Employee.
      summary: Get a specific document
      operationId: Getaspecificdocument
      deprecated: false
      produces:
      - application/json
      parameters:
      - name: DocType
        in: path
        required: true
        type: string
        description: "The DocType you'd like to receive. For example Customer, Supplier, \nEmployee, Account, Lead, Company, Sales Invoice, Purchase Invoice, Stock Entry, etc."
      - name: DocumentName
        in: path
        required: true
        type: string
        description: The name (ID) of the document you'd like to receive. For example EMP001 (of type Employee).
      responses:
        '200':
          description: Found requested document
          schema:
            $ref: '#/definitions/ResourceResponse'
          headers: {}
    put:
      description: TBD
      summary: Update a specific document
      operationId: Updateaspecificdocument
      deprecated: false
      produces:
      - application/json
      parameters:
      - name: DocType
        in: path
        required: true
        type: string
        description: "The DocType you'd like to update. For example Customer, Supplier, \nEmployee, Account, Lead, Company, Sales Invoice, Purchase Invoice, Stock Entry, etc."
      - name: DocumentName
        in: path
        required: true
        type: string
        description: The name (ID) of the document you'd like to update. For example EMP001 (of type Employee).
      responses:
        '200':
          description: Updated specified document
          schema:
            $ref: '#/definitions/ResourceResponse'
          headers: {}
    delete:
      description: TBD
      summary: Delete a specific document
      operationId: Deleteaspecificdocument
      deprecated: false
      produces:
      - application/json
      parameters:
      - name: DocType
        in: path
        required: true
        type: string
        description: "The type of the document you'd like to delete. For example Customer, Supplier, \nEmployee, Account, Lead, Company, Sales Invoice, Purchase Invoice, Stock Entry, etc."
      - name: DocumentName
        in: path
        required: true
        type: string
        description: The name (ID) of the document you'd like to delete. For example EMP001 (of type Employee).
      responses:
        '202':
          description: Deleted specified document
          schema:
            $ref: '#/definitions/ResourceResponse3'
          headers: {}
definitions:
  DocType:
    title: DocType
    type: object
    properties:
      name:
        type: string
      modified_by:
        type: string
      creation:
        type: string
      modified:
        type: string
      doctype:
        type: string
      owner:
        type: string
      docstatus:
        type: integer
        format: int32
  DocList:
    title: DocList
    type: object
    properties:
      data:
        type: array
        items:
          $ref: '#/definitions/DocType'
  MethodFrappeAuthGetLoggedUser401Error1:
    title: MethodFrappeAuthGetLoggedUser401Error1
    type: object
    properties:
      exc:
        example: Traceback (most recent call last) ...
        type: string
      _server_messages:
        example:
        - message: Not permitted
        type: string
  MethodFrappeAuthGetLoggedUserResponse:
    title: MethodFrappeAuthGetLoggedUserResponse
    type: object
    properties:
      message:
        example: demo@erpnext.com
        type: string
  MethodLogin401Error1:
    title: MethodLogin401Error1
    type: object
    properties:
      exc:
        example: Traceback (most recent call last) ...
        type: string
      message:
        example: Incorrect password
        type: string
  MethodLoginResponse:
    title: MethodLoginResponse
    type: object
    properties:
      full_name:
        example: Administrator
        type: string
      message:
        example: Logged in
        type: string
      home_page:
        example: /desk
        type: string
  MethodVersionResponse:
    title: MethodVersionResponse
    type: object
    properties:
      message:
        example: 10.1.36
        type: string
  Resource403Error1:
    title: Resource403Error1
    type: object
    properties:
      exc:
        example: Traceback (most recent call last) ...
        type: string
      _error_message:
        example: Insufficient Permission for {DocType}
        type: string
  ResourceResponse:
    title: ResourceResponse
    type: object
    properties:
      data:
        $ref: '#/definitions/DocType'
  ResourceResponse3:
    title: ResourceResponse3
    type: object
    properties:
      message:
        type: string
security: []
tags:
- name: Naive Authentication
  description: If you are developing something serious, you may want to use oAuth2.
HS_Nico
Helper II
Helper II

To fix the error you need to append "items: {type: string}" to your parameter definition. You do that in Swagger Editor. Your code should then look like this:

parameters:
- {name: fields, in: query, required: false, type: array, items: {type: string}}
- {name: filters, in: query, required: false, type: array, items: {type: string}}

I believe I found the offending part in Swagger.

 

        default: "[\n\n  \"name\"\n\n]"

 

When I delete that line, the error message goes away. The default value is an array with "name" in it, but swagger is evaluating "[\n\n \"name\"\n\n]" as a string, instead of as an array. What's the proper way to denote a literal array for a default value?

 

Even after deleting the offending line, and getting rid of the error message, I can save the Connector, but I still receive the message 

Your custom connector has been successfully updated, but there was an issue converting it to WADL for Power Apps: An error occured while converting OpenAPI file to WADL file. Error: 'Parameter with type='array' is not currently supported at JSON path paths['/resource/{DocType}'].get.parameters[1]'

 

HS_Nico
Helper II
Helper II

Ignore my suggestion with the official OpenAPI documentation and build your connector manually. Then you will again face the problem of your introductory question ("Schemas with type Array require sibling "Item"), which you can fix with my second answer.

HS_Nico
Helper II
Helper II

Has your problem now been resolved? If my answer helped you, I would be happy if you would accept it as a solution.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Users online (6,079)