How do I find the data type information from an API

William Thompson 120 Reputation points
2024-09-13T22:00:59.19+00:00

I am getting data from an API query. I will be duplicating the API call in C# code eventually, but for now, let's just discuss the JSON output my API GET call receives.

When I look at the data in the form of JSON in Postman, I see this (in part):

group-of-stuff

The issue is that I want to know how to define the obvious floating point numeric value.

I mean, I can see that TripId must be an integer and OffBlocksUTc must be a DateTime class. FlyingTimePinned is a boolean type and ExternalReference is probably a string type. But what would FlyingTime and BlockTime be classified as? When I look at the XML file that "@odata.context" mentions, I can see the classification of "Decimal".

So how do I make use of that data type? When moving the data into a SharePoint List through C# code, I have to tell the created SharePoint List exactly what the data type is.

From what I can gather, these are the only data types that SharePoint List columns will accept:

Text: Single line of text.

Note: Multiple lines of text.

Number: Numeric values.

DateTime: Date and time values.

Choice: A set of predefined options.

Lookup: Values from another list.

Boolean: Yes/No values.

User: User or group values.

URL: Hyperlink or picture.

Currency: Currency values.

Calculated: Calculated values based on other columns.

Guid: Globally unique identifier.

MultiChoice: Multiple choice options.

TaxonomyFieldType: Managed metadata.

Please advise.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,006 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,684 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 54,316 Reputation points
    2024-09-16T02:32:56.3466667+00:00

    Here's the thing about JSON. There are really only a few types: boolean, numbers and strings. Everything else falls into these categories. For example an integer and a floating point value are both numbers. Strings cover everything else including fixed size numbers (like SSN), date and times, etc. So you really need to look at the OpenAPI spec for the API you're calling. In general for things that are flexible like numbers and strings they will provide additional context such as the precision, min/max length and required format (for strings). Without this information just looking at the data is going to be the wrong approach. For example you may see "value": 10 when the value happens to be a whole number but "value": 10.1 when it is fractional. The OpenAPI spec will generally clarify this otherwise you need to look at the documentation for the API.

    Since you're using OData here then look at the documentation for the API you're calling and they should provide the information about the available fields and their expected types. That is what you need to code against.

    For general guidelines, integrals are ints, floating points are doubles, booleans are booleans and everything else is a string. Given your very specific example I would expect the times to be timespan strings but it looks like they are either really fast or actually fractional parts of a time, such as minutes of a day or something. The docs should clarify this.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.