cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
693
Views
0
Helpful
1
Replies

Can I always rely on REST status code 200 = "success"

Steve Krause
Level 1
Level 1

Hello,

As I am building out a library of REST calls for programming the APICs is it safe to test for a calls successful completion in the following way?


if (response.statusCode != 200) {
throw new Error(apic.name + ": " + jsonResponse.imdata[0].error.attributes.text);
}

Will status code 200 always be equivalent to a success and ANY other status code will be associated with an error?

I've tried to look through the API documentation about this, but haven't found anything definitive.

Thanks

1 Reply 1

Claudia de Luna
Spotlight
Spotlight

Hi Steve,

While I've never found anything definitive either I've automated most of an ACI build and so far its always an indicator of success.

Below is sample output from a script that configures connectivity.  You can see that the first two entries are configuring a static path binding with encapsulation using 2190 because the payload meets certain criteria (2190 is in an "allowed" list).  You can see that the last two failed because one of the constructs is missing.

I key off of it but also log all results (as you can see below).

Same for removing configuration as you can see in attached.

====================POST Action: POST Object: Adding Static Path Binding to EPG DMZ-Infra-EFWLIn-DMZSEC-NonPROD-EPG type acc on interface 1/23 in mode regular since 2190 is in allowed vlan list 2090 2190 2601 2097 2197.
Status Code: 200
Reason: OK
========================================
====================POST Action: POST Object: Adding Static Path Binding to EPG DMZ-Infra-EFWLIn-DMZSEC-NonPROD-EPG type acc on interface 1/24 in mode regular since 2190 is in allowed vlan list 2090 2190 2601 2097 2197.
Status Code: 200
Reason: OK
========================================
====================POST Action: POST Object: Adding Static Path Binding to EPG DMZ-Pub-LBSIn-L3-EPG type acc on interface 1/1 in mode regular since 2601 is in allowed vlan list 2090 2190 2601 2097 2197.
Status Code: 400
Reason: Bad Request
Error Text: configured object ((Dn0)) not found Dn0=uni/tn-LAX1-Production-TN/ap-Outside-AP/epg-DMZ-Pub-LBSIn-L3-EPG/rspathAtt-[topology/pod-1/paths-208/pathep-[eth1/1]],
========================================
====================POST Action: POST Object: Adding Static Path Binding to EPG DMZ-Pub-LBSIn-L3-EPG type acc on interface 1/2 in mode regular since 2601 is in allowed vlan list 2090 2190 2601 2097 2197.
Status Code: 400
Reason: Bad Request
Error Text: configured object ((Dn0)) not found Dn0=uni/tn-LAX1-Production-TN/ap-Outside-AP/epg-DMZ-Pub-LBSIn-L3-EPG/rspathAtt-[topology/pod-1/paths-208/pathep-[eth1/2]],
========================================

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Save 25% on Day-2 Operations Add-On License