Happy Business Starts Here

Re: Working with a query in .Net with REST API

Tutor

Working with a query in .Net with REST API

Does anyone have an example of issuing a query using the REST API in .Net?  I'm using the Swagger-generated library from here: https://github.com/zuora/codelibrary-dotnet

 

I can successfully call ProxyActionPOSTquery, which returns the records I request, but it can't seem to deserialize the results properly.  It tries to deserialize the results into a ProxyActionqueryResponse type, and it just ends up being null.

Tags (2)
6 REPLIES
Zuora Support Moderator

Re: Working with a query in .Net with REST API

Hello,

 

Please check out the following article for calling web API from .NET, which also includes information on deserializing. https://www.asp.net/web-api/overview/advanced/calling-a-web-api-from-a-net-client

 

Make sure you're utilizing Zuora's endpoints: https://knowledgecenter.zuora.com/CA_Commerce/C_Zuora_Quotes/G_Zuora_Quotes_Configuration_Settings/A...

 



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Tutor

Re: Working with a query in .Net with REST API

The API itself is not the problem.  It's returning the records I request. The problem is with the code library I mentioned.  If I use it to request a specific type of record ("AccountsApi.GETAccount", or "PaymentMethodsApi.GETPaymentMethods", for example), those work fine because they return a distinct, specifc type that the json can be mapped to ("GETAccountType", and "GETPaymentMethodType", for example).  It's the ad-hoc queries that are a problem, because they don't know what the return type is.  "ActionsApi.ProxyActionPOSTquery" returns a "ProxyActionqueryResponse" type, which is basically just a wrapper around a "ZObject", which doesn't have any properties, and so the records that come back aren't able to be deserialized into anything useful.  That's why I was looking for an example specifically relating to the action query function of the API.  I'm about to tear the code apart and try to get it to work, but wanted to see if I was doing something wrong before I reinvent the wheel.

 

By the way, the SOAP API action query works fine.  The SOAP result includes the type of object that was requested, and the SOAP "zObject" inherits from "object", so it's able to actually store a useful result.  The REST "ZObject" appears to be useless...?

Zuora Alumni

Re: Working with a query in .Net with REST API

Hi Jerrade,

 

Can you send us a isolated test class where you can reproduce this issue using the swagger generated lib?

 

We'll take a look and follow up with you.

 

Thanks,



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Tutor

Re: Working with a query in .Net with REST API

Here is a simple project that shows the problem: https://github.com/jerrade/ZuoraSwaggerTest

Zuora Alumni

Re: Working with a query in .Net with REST API

Thanks for that,

 

I'm going to create a ticket for you so we can track this internally as we will probably want to engage some internal resources

 

thanks!



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Highlighted
Zuora Support Moderator

Re: Working with a query in .Net with REST API

We’ve recently been looking into this issue again. I’m replying in this topic because it still gets viewed often.

 

The ZObject class should extend Dictionary<String, Object>, but swagger-codegen isn’t picking this up from our Swagger spec.

 

As a workaround, you can modify a local copy of the Swagger spec before using swagger-codegen to generate the C# library:

 

  1. Download the Swagger spec. To do this, visit https://www.zuora.com/developer/api-reference/, then click the Download button at the top of the page.

  2. Open the downloaded file in a text editor. The file is quite large, so this may take a few seconds.

  3. Locate this part of the file:

      zObject:
        additionalProperties:
          description: 'Field of the object.
    
            '
        type: object
    


    In the latest Swagger spec, this part is very close to the end of the file.

  4. Add type: object within additionalProperties, like this:

      zObject:
        additionalProperties:
          type: object
          description: 'Field of the object.
    
            '
        type: object
  5. In addition to zObject, there are some other models in the Swagger spec that contain additionalProperties without type specified. I’d recommend that you modify these models in the same way.

    All the other affected models are called <name>ObjectCustomFields. E.g., AccountObjectCustomFields, which you should modify to look like this:

      AccountObjectCustomFields:
        additionalProperties:
          type: object
          description: 'Custom fields of the Account object. The name of each custom field
            has the form <code>*customField*__c</code>. Custom field names are case sensitive.
            See [Manage Custom Fields](https://knowledgecenter.zuora.com/BB_Introducing_Z_Business/Manage_Custom_Fields)
            for more information.
    
            '
        description: 'Container for custom fields of an Account object.
    
          '
        title: accountFieldsCustom
        type: object
    
  6. After ensuring that every occurrence of additionalProperties has type specified, save the file.

    Note: If you are using version 2.3.0 or later of swagger-codegen, you will need to remove the additionalProperties blocks entirely. See this post for more information.

  7. Use swagger-codegen to generate a C# library.

 

Manually modifying the Swagger spec can be time-consuming, so I’d recommend that you automate the process via a script. Don’t hesitate to reply to this post if you’d like any advice about doing that.