.Net Deserialize Fields

Posted in General by Gui Gimenez Wed Jul 12 2017 13:08:51 GMT+0000 (Coordinated Universal Time)·3·Viewed 1,218 times

Hi guys, I'm trying to migrate from API v1 to v2 and spending a fair bit of time trying to proper deserialize fields from the formz returned from the endpoint https://api.goformz.com/v2/formz/{0} That name property in front of each field is the issue, can you guys provide any help on this ? any example on how to rid of that name and properly convert the json fields into c# objects ? Another question what's the end point to download the PDF file from each form ? used to download from https://api.goformz.com/1.0/stream.svc/GetPDFStream?formInstanceId={0} Thank you and Regards
July 12, 2017

Hi Gui,

One option is to deserialize the fields as a Dictionary<string, Dictionary<string, object>> where the name of each field is the key, and then in the inner dictionary, each key is the name of a property. The Value in the inner dictionary needs to be an object rather than a string since some field properties are objects rather than string values. You'll then need to check the type of each Object using the "type" property on each field, and then convert to the relevant C# type.

An alternative would be to write a custom json converter, but in my experience, that's more work than its worth for the type of thing you're doing.

To download a PDF, use the https://api.goformz.com/v2/formz/:formId/exports endpoint as documented here:

July 13, 2017

Thanks Michael, that makes sense, dictionary will do the job !

July 17, 2017

Hi Michael,
I've been trying to generate the pdf through the endpoint but keep getting "Message": "Authorization has been denied for this request.", is there any special privilege that needs to be added for the user to be able to export ? I can do everything else with the same user, only to export the pdf that I get this message.

By the way to get the pdf file in APIv1 was a lot easier than now that needs to hit 4 different endpoints to be able to download the file.

Markdown is allowed