Hello,
I am programming new feature for erp system i'm working with. It is c# based. Can somebody show me examples of getting token or post calls classes?
I have few problem with json handling...
This thread has been locked.
Hello,
I am programming new feature for erp system i'm working with. It is c# based. Can somebody show me examples of getting token or post calls classes?
I have few problem with json handling...
Hello! We actually have a library of C# wrapper classes and example code in development, which will be made widely available in early January. :)
In that system, we developed a utility class which handles HTTP requests by deserializing the JSON response into a given class (using the open source Json.NET library). This means that for each possible JSON output, we have defined a class or hierarchy of classes in order to represent the structure. The function itself is written using a generic class 'T' so it can be used for any such class. Below is the generic function for POST requests, where the _client field refers to a private object of type HttpClient. There is also logic to pass a token if desired, since the class has logic to automatically retrieve it.
To acquire a token to begin with, the same utility class calls that POST function with the values necessary to retrieve the token from TI's server. Notice that authorization is set to false because not only do we not currently have a token, but our goal here is precisely to acquire that token. The function assumes public string fields ClientID and ClientSecret, corresponding tto the user's API credentials, and Server corresponding to the base URL of the TI server (for you, it will be "">https://transact.ti.com").
In the example above, rather than defining and referring to a class definition for the server response, we request the function to deserialize the output as a dictionary of string values to string values. This will be okay for simple JSON structures, but is not viable for nested structures or structures with more complex contents. Something you can do to quickly develop such classes is to first make the API call on an API client like Insomnia or Postman, copy the JSON server response as a string, and use a JSON-to-C# converter which analyzes the JSON structure and generates a C# class structure based on it.
I hope this is a helpful starting point! Again, the complete tool will be made available in January so that you can make use of not only this utility class but also specific wrapper classes for each of the TI store APIs. :)
**Attention** This is a public forum