Hi there,
Im new to using the Infinite Flight API and im trying to recieve flights picturing on my map however every time I try an new code to simplify the information I still get the error:
Failed to decode flights: The data couldn’t be read because it isn’t in the correct format.
Anyone else knows what to do? (I use Xcode)
Hi …
I think more information would be needed for someone in the IFC to be able to help. Some questions I immediately have would be:
- are you using the Live API or Connect API?
- what endpoint are you calling? Can you provide sample code for how you are calling the API?
- can you provide the code which XCode says is causing the error and the exact error details?
2 Likes
Sure, It is an great question tho on which I use the connect or the Live API because I do not rlly know that (im quite knew to coding).
But I can share an screenshot to show the error message I got
Just a quick note – that image has your API key which you really shouldn’t be sharing publicly as others could then use it. I suggest you remove the key from the image and edit this post.
Separately, the first thing I notice is that I think your URL for the /flights
endpoint is incorrect. The documentation refers to using the Session ID of the server – not the name of the server – in the URL.
But your code appears to use selectedServer
to build the URL which is a hard-coded value of expert
. If you read the Live API documentation it says you need to use the Session ID for the server and you get that by calling the following endpoint to get a list of all server sessions: Get Sessions | Infinite Flight
This will return a list of entries that look like this:
{
"errorCode": 0,
"result": [
{
"maxUsers": 1000,
"id": "89573c7f-d398-4281-bcc0-3e9b7f6b8492",
"name": "Sample Server",
"userCount": 187,
"type": 0,
"worldType": 0,
"minimumGradeLevel": 2
}
]
}
You want to find the entry in the results for the server you want and use the value of id
for that server in constructing your URL.
I suspect that because your URL doesn’t use the Session ID the response you get back is an error response and not a proper API response which is why you are triggering this error.
ahhh, I see. Thanks I’m gonna try that