Working out why a call failed.
WHAT TO ESTABLISH FIRST
What exactly was sent and received.
HOW
Log both, or reproduce from the command line.
WHY THE COMMAND LINE
It removes your code from the question entirely.
WHAT TO CHECK IN ORDER
Does the address resolve Does the connection succeed Does authentication succeed Is the request accepted Is the response what you expected
WHY THAT ORDER
Each depends on the one before.
WHAT COMMON CAUSES ARE
A wrong address or path Credentials for the wrong environment Missing or wrong content type header A malformed body An expired token Rate limiting
WHAT TO CHECK ABOUT CONTENT TYPE
That it matches what you are actually sending.
WHY
Mismatches produce confusing parse errors on the far side.
WHAT A FOUR HUNDRED AND ONE USUALLY MEANS
The credential, or how it is being sent.
WHAT A FOUR HUNDRED AND THREE USUALLY MEANS
The credential is fine but lacks permission.
WHAT A FOUR HUNDRED AND FOUR SOMETIMES MEANS
Not permitted, deliberately disguised.
WHAT TO DO ABOUT INTERMITTENT FAILURES
Log everything, and look for a pattern in time or content.
WHAT TO COMPARE
A working call against a failing one, field by field.
WHAT TO ASK THE PROVIDER FOR
Their view of the request, with your identifier.