Web_API Get() call what does the status value mean?

Hi
When I use these blocks:


There is the status output. I get the status as 200, 404 and all kinds of numbers. I could not find any table explaining what those number mean. I would assume error also might return various values to indicate the type of error. There is no table explaining them too. Could someone point me to the info please? Thanks

The API blocks call external services unrelated to Thunkable. So when you call the Open Weather API, the response, status, and error values are provided by the Open Weather servers.

If you Google API status values, you’ll find examples of each status code.

The error is most important here. In the “then do” section of that block, add an if block and attach the green error block to it. Inside the if block, set a label’s text to the green error block. In the else section, put your other blocks (with “get property of object”, etc.).

I never worry about status values when using APIs. I just check if there is an error and if so, I display it. If there isn’t an error, then you should have a response and you can display the green response block in a label or text input to make sure you’re getting a valid response. Then you can parse that response as you’ve done in your screenshot by getting specific properties of the JSON object.

1 Like

Hi Tatiang,

I am from C/C++ world and there we have this syntax:
ErrCode = Function();
if (ErrCode != 0) {
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
ErrCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL
);
}
So when there is a failure FormatMessage() a system call provided by Microsoft is called and lpMsgBuf buffer will have a detailed message.

My question is in do we have a function which would do a similar work for us in Thunkable. In other words assume the we get a status value of 405. Using that number can I get the words “Method not Allowed” or better yet, can I get the full description “The request HTTP …” that would be awesome. If such function does not exists then we will have to create it ourselves right?
thanks a lot for all the help
regards
ananda

I get what you’re saying and I think you might be overthinking or over-complicating things.

As far as I know, Thunkable only provides the full API response when it succeeds. When it fails, you are limited to whatever the “status” and “error” blocks are programmed to return.

But the reason I say I think you’re over complicating is because most APIs provide a detailed error value. That should be enough to figure out what’s not working.

Are you trying to get a specific API property value? Is it working? If not, what is the value of the green “error” block?

1 Like

Let me give an example: In the URL the last element is the name of the city. Assume there is a typo.
Error: undefined
Status: 200
I need to tell the user there is typo in the city name. Or put out a message: “no such city exists”. Currently I have no clue when all I get is “undefined”. The word undefined might mean many things.

The status returns 200 (OK) which is technically correct because the function executed successfully but data wise it had failed. It is like the operation was successful but the patient died :slight_smile: . Anyway I guess there is no easy way out but other than that I go out to the Web API code site and get the error messages. Hopefully in the future they will provide it. Thanks again for your help.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.