Cisco APIC REST API User Guide
Cisco APIC REST API User Guide
Cisco APIC REST API User Guide
Americas Headquarters
Cisco Systems, Inc.
170 West Tasman Drive
San Jose, CA 95134-1706
USA
http://www.cisco.com
Tel: 408 526-4000
800 553-NETS (6387)
Fax: 408 527-0883
THE SPECIFICATIONS AND INFORMATION REGARDING THE PRODUCTS IN THIS MANUAL ARE SUBJECT TO CHANGE WITHOUT NOTICE. ALL STATEMENTS,
INFORMATION, AND RECOMMENDATIONS IN THIS MANUAL ARE BELIEVED TO BE ACCURATE BUT ARE PRESENTED WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED. USERS MUST TAKE FULL RESPONSIBILITY FOR THEIR APPLICATION OF ANY PRODUCTS.
THE SOFTWARE LICENSE AND LIMITED WARRANTY FOR THE ACCOMPANYING PRODUCT ARE SET FORTH IN THE INFORMATION PACKET THAT SHIPPED WITH
THE PRODUCT AND ARE INCORPORATED HEREIN BY THIS REFERENCE. IF YOU ARE UNABLE TO LOCATE THE SOFTWARE LICENSE OR LIMITED WARRANTY,
CONTACT YOUR CISCO REPRESENTATIVE FOR A COPY.
The Cisco implementation of TCP header compression is an adaptation of a program developed by the University of California, Berkeley (UCB) as part of UCB's public domain version
of the UNIX operating system. All rights reserved. Copyright © 1981, Regents of the University of California.
NOTWITHSTANDING ANY OTHER WARRANTY HEREIN, ALL DOCUMENT FILES AND SOFTWARE OF THESE SUPPLIERS ARE PROVIDED “AS IS" WITH ALL FAULTS.
CISCO AND THE ABOVE-NAMED SUPPLIERS DISCLAIM ALL WARRANTIES, EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, THOSE OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OR ARISING FROM A COURSE OF DEALING, USAGE, OR TRADE PRACTICE.
IN NO EVENT SHALL CISCO OR ITS SUPPLIERS BE LIABLE FOR ANY INDIRECT, SPECIAL, CONSEQUENTIAL, OR INCIDENTAL DAMAGES, INCLUDING, WITHOUT
LIMITATION, LOST PROFITS OR LOSS OR DAMAGE TO DATA ARISING OUT OF THE USE OR INABILITY TO USE THIS MANUAL, EVEN IF CISCO OR ITS SUPPLIERS
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Any Internet Protocol (IP) addresses and phone numbers used in this document are not intended to be actual addresses and phone numbers. Any examples, command display output, network
topology diagrams, and other figures included in the document are shown for illustrative purposes only. Any use of actual IP addresses or phone numbers in illustrative content is unintentional
and coincidental.
Cisco and the Cisco logo are trademarks or registered trademarks of Cisco and/or its affiliates in the U.S. and other countries. To view a list of Cisco trademarks, go to this URL: http://
www.cisco.com/go/trademarks. Third-party trademarks mentioned are the property of their respective owners. The use of the word partner does not imply a partnership
relationship between Cisco and any other company. (1110R)
Audience
This guide is intended for software engineers with a background in programming and the use of APIs. Engineers
should have knowledge of XML and JSON, RESTful web service APIs, data systems, networking protocols,
and storage protocols.
Document Conventions
Command descriptions use the following conventions:
Convention Description
bold Bold text indicates the commands and keywords that you enter literally
as shown.
Convention Description
Italic Italic text indicates arguments for which the user supplies the values.
variable Indicates a variable for which you supply values, in context where italics
cannot be used.
string A nonquoted set of characters. Do not use quotation marks around the
string or the string will include the quotation marks.
Convention Description
screen font Terminal sessions and information the switch displays are in screen font.
boldface screen font Information you must enter is in boldface screen font.
italic screen font Arguments for which you supply values are in italic screen font.
Note Means reader take note. Notes contain helpful suggestions or references to material not covered in the
manual.
Caution Means reader be careful. In this situation, you might do something that could result in equipment damage
or loss of data.
Related Documentation
For detailed reference information about API classes, properties, and data types, see the Cisco APIC
Management Information Model Reference, which is a web-based application.
You can find detailed procedures of many common tasks using the API in the Cisco APIC Getting Started
Guide.
Web-Based Documentation
• Cisco APIC Management Information Model Reference
• Cisco APIC Online Help Reference
• Cisco ACI MIB Support List
Downloadable Documentation
• Cisco Application Centric Infrastructure Release Notes
• Cisco Application Centric Infrastructure Fundamentals Guide
• Cisco APIC Getting Started Guide
• Cisco APIC REST API User Guide
• Cisco APIC Command Line Interface User Guide
• Cisco APIC Faults, Events, and System Message Guide
• Cisco APIC Layer 4 to Layer 7 Device Package Development Guide
• Cisco APIC Layer 4 to Layer 7 Services Deployment Guide
• Cisco ACI Firmware Management Guide
• Cisco ACI Troubleshooting Guide
• Cisco ACI NX-OS Syslog Reference Guide
• Cisco ACI Switch Command Reference, NX-OS Release 11.0
Documentation Feedback
To provide technical feedback on this document, or to report an error or omission, please send your comments
to apic-docfeedback@cisco.com. We appreciate your feedback.
Configuration policies are the majority of the policies in the system and describe the configurations of different
ACI fabric components. Policies determine how the system behaves under specific circumstances. Certain
MOs are not created by users but are automatically created by the fabric (for example, power supply objects
and fan objects). By invoking the API, you are reading and writing objects to the MIM.
The information model is centrally stored as a logical model by the APIC, while each switch node contains
a complete copy as a concrete model. When a user creates a policy in the APIC that represents a configuration,
the APIC updates the logical model. The APIC then performs the intermediate step of creating a fully elaborated
policy from the user policy and pushes the policy into all the switch nodes where the concrete model is updated.
The models are managed by multiple data management engine (DME) processes that run in the fabric. When
a user or process initiates an administrative change to a fabric component (for example, when you apply a
profile to a switch), the DME first applies that change to the information model and then applies the change
to the actual managed endpoint. This approach is called a model-driven framework.
The following branch diagram of a leaf switch port starts at the topRoot of the ACI fabric MIT and shows a
hierarchy that comprises a chassis with two line module slots, with a line module in slot 2.
|——root———————————–– (root)
|——sys———————————––– (sys)
|——ch————————————————(sys/ch)
|——lcslot-1——————————(sys/ch/lcslot-1)
|——lcslot-2——————————(sys/ch/lcslot-2)
|——lc————————————————(sys/ch/lcslot-2/lc)
|——leafport-1————————(sys/ch/lcslot-2/lc/leafport-1)
Object Naming
You can identify a specific object by its distinguished name (DN) or by its relative name (RN).
Distinguished Name
The DN enables you to unambiguously identify a specific target object. The DN consists of a series of RNs:
dn = {rn}/{rn}/{rn}/{rn}...
In this example, the DN provides a fully qualified path for fabport-1 from the top of the object tree to the
object. The DN specifies the exact managed object on which the API call is operating.
Relative Name
The RN identifies an object from its siblings within the context of its parent object. The DN contains a sequence
of RNs.
For example, this DN:
<dn = "sys/ch/lcslot-1/lc/fabport-1"/>
A typical request comes into the DME and is placed in the transactor queue in first in, first out (FIFO) order.
The transactor gets the request from the queue, interprets the request, and performs an authorization check.
After the request is confirmed, the transactor updates the MIT. This complete operation is done in a single
transaction.
Note For detailed reference information about API classes, properties, and data types, see the Cisco APIC
Management Information Model Reference, which is a web-based application.
Note For security, only HTTPS is enabled as the default mode for API communications. HTTP and
HTTP-to-HTTPS redirection can be enabled if desired, but are less secure. For simplicity, this document
refers to HTTP in descriptions of protocol components and interactions.
Note The root element of the response structure is imdata. This element is merely a container for the response;
it is not a class in the management information model (MIM).
Note For security, only HTTPS is enabled as the default mode for API communications. HTTP and
HTTP-to-HTTPS redirection can be enabled if desired, but are less secure. For simplicity, this document
refers to HTTP in descriptions of protocol components and interactions.
Request Methods
The API supports HTTP POST, GET, and DELETE request methods as follows:
• An API command to create or update an MO, or to execute a method, is sent as an HTTP POST message.
• An API query to read the properties and status of an MO, or to discover objects, is sent as an HTTP
GET message.
• An API command to delete an MO is sent as either an HTTP POST or DELETE message. In most cases,
you can delete an MO by setting its status to deleted in a POST operation.
Note Although the DELETE method is supported, the HTTP header might show only these:
Access-Control-Allow-Methods:POST,GET,OPTIONS
Content Type
The API supports either JSON or XML data structures in the HTML body of an API request or response. You
must specify the content type by terminating the URI pathname with a suffix of either .json or .xml to indicate
the format to be used. The HTTP Content-Type and Accept headers are ignored by the API.
This example shows a URI for an API operation that involves an MO of class fv:Tenant:
https://192.0.20.123/api/mo/uni/tn-ExampleCorp.xml
URI Components
The components of the URI are as follows:
• http:// or https://—Specifies HTTP or HTTPS. By default, only HTTPS is enabled. HTTP or
HTTP-to-HTTPS redirection, if desired, must be explicitly enabled and configured, as described in
Configuring HTTP and HTTPS Using the GUI, on page 53. HTTP and HTTPS can coexist.
• host—Specifies the hostname or IP address of the APIC.
• :port—Specifies the port number for communicating with the APIC. If your system uses standard port
numbers for HTTP (80) or HTTPS (443), you can omit this component.
• /api/—Specifies that the message is directed to the API.
• mo | class—Specifies whether the target of the operation is an MO or an object class.
• dn—Specifies the distinguished name (DN) of the targeted MO.
• className—Specifies the name of the targeted class. This name is a concatenation of the package name
of the object queried and the name of the class queried in the context of the corresponding package.
For example, the class aaa:User results in a className of aaaUser in the URI.
• json | xml—Specifies whether the encoding format of the command or response HTML body is JSON
or XML.
• ?options—(Optional) Specifies one or more filters, selectors, or modifiers to a query. Multiple option
statements are joined by an ampersand (&).
https://192.0.20.123/api/mo/uni/tn-ExampleCorp.xml
Alternatively, in a POST operation, you can POST to /api/mo and provide the DN in the body of the message,
as in this example:
POST https://192.0.20.123/api/mo.xml
<fvTenant dn="uni/tn-ExampleCorp"/>
You can also provide only the name in the message body and POST to /api/mo and the remaining relative
name components, as in this example:
POST https://192.0.20.123/api/mo/uni.xml
<fvTenant name="ExampleCorp"/>
GET https://192.0.20.123/api/mo/topology/pod-1/node-1/sys/ch/bslot/board/sensor-3.json
GET https://192.0.20.123/api/class/aaaUser.json
{
"zzzObject" : {
"attributes" : {
"property1" : "value1",
"property2" : "value2",
"property3" : "value3"
},
"children" :
[{
"zzzChild1" : {
"attributes" : {
"childProperty1" : "childValue1",
"childProperty2" : "childValue1"
},
"children" : []
}
}
]
}
}
<zzzObject
property1 = "value1",
property2 = "value2",
property3 = "value3">
<zzzChild1
childProperty1 = "childValue1",
childProperty2 = "childValue1">
</zzzChild1>
</zzzObject>
• aaaRefresh—Sent as a GET message with no message body or as a POST message with the aaaLogin
message body, this method resets the session timer. The response contains a new session token and
cookie.
• aaaLogout—Sent as a POST message, this method logs out the user and closes the session. The message
body contains an aaa:User object with the name attribute. The response contains an empty data structure.
• aaaListDomains—Sent as a GET message, this method returns a list of valid AAA login domains. You
can send this message without logging in.
You can call the authentication methods using this syntax, specifying either JSON or XML data structures:
This example shows a user login message that uses a JSON data structure:
POST https://192.0.20.123/api/aaaLogin.json
{
"aaaUser" : {
"attributes" : {
"name" : "georgewa",
"pwd" : "paSSword1"
}
}
}
This example shows part of the response upon a successful login, including the token and the refresh timeout
period:
RESPONSE:
{
"imdata" : [{
"aaaLogin" : {
"attributes" : {
"token" :
"GkZl5NLRZJl5+jqChouaZ9CYjgE58W/pMccR+LeXmdO0obG9NB
Iwo1VBo7+YC1oiJL9mS6I9qh62BkX+Xddhe0JYrTmSG4JcKZ4t3
bcP2Mxy3VBmgoJjwZ76ZOuf9V9AD6Xl83lyoR4bLBzqbSSU1R2N
IgUotCGWjZt5JX6CJF0=",
"refreshTimeoutSeconds" : "300",
"lastName" : "Washington",
"firstName" : "George"
},
"children" : [{
...
[TRUNCATED]
...
}
In the preceding example, the refreshTimeoutSeconds attribute indicates that the session timeout period is
300 seconds.
This example shows how to request a list of valid login domains:
GET https://192.0.20.123/api/aaaListDomains.json
RESPONSE:
{
"imdata": [{
"name": "ExampleRadius"
},
{
"name": "local",
In the preceding example, the response data shows two possible login domains, 'ExampleRadius' and 'local.'
The following example shows a user login message for the ExampleRadius login domain:
POST https://192.0.20.123/api/aaaLogin.json
{
"aaaUser" : {
"attributes" : {
"name" : "apic:ExampleRadius\\georgewa",
"pwd" : "paSSword1"
}
}
}
Related Topics
Example: Using the JSON API to Authenticate a User, on page 23
Example: Using the XML API to Authenticate a User, on page 22
To initiate a session that requires a challenge token, include the URI parameter statement
?gui-token-request=yes in your login message, as shown in this example:
POST https://192.0.20.123/api/aaaLogin.json?gui-token-request=yes
The response message body contains an attribute of the form "urlToken":"token", where token is a long
string of characters representing the challenge token. All subsequent messages to the API during this session
must include the challenge token, as shown in this example where it is sent as a 'url-token' URI parameter:
GET https://192.0.20.123/api/class/aaaUser.json?url-token=fa47e44df54562c24fef6601dc...
This example shows how the challenge token is sent as an 'APIC-challenge' field in the HTTP header:
GET //api/class/aaaUser.json
HTTP/1.1
Host: 192.0.20.123
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml,application/json
APIC-challenge: fa47e44df54562c24fef6601dcff72259299a077336aecfc5b012b036797ab0f
.
.
.
https://URI?condition[&condition[&...]]
target-subtree-class=mo-class1[,mo-class2]...
This statement specifies which object classes are to be considered when the query-target option is used with
a scope other than self. You can specify multiple desired object types as a comma-separated list with no spaces.
To request subtree information, combine query-target=subtree with the target-subtree-class statement to
indicate the specific subtree as follows:
query-target=subtree&target-subtree-class=className
This example requests information about the running firmware. The information is contained in the
firmware:IfcRunning subtree (child) object of the APIC firmware status container firmware:IfcFwStatusCont:
GET https://192.0.20.123/api/class/firmwareIfcFwStatusCont.json?
query-target=subtree&target-subtree-class=firmwareIfcRunning
query-target-filter=filter-expression
This statement specifies a logical filter to be applied to the response. This statement can be used by itself or
applied after the query-target statement.
rsp-subtree-class=mo-class
When child objects are to be returned, this statement specifies that only child objects of the specified object
class are included in the response.
rsp-subtree-filter=filter-expression
When child objects are to be returned, this statement specifies a logical filter to be applied to the child objects.
rsp-subtree-include=category1[,category2...][option]
When child objects are to be returned, this statement specifies additional contained objects or options to be
included in the response. You can specify one or more of the following categories in a comma-separated list
with no spaces:
• audit-logs—Response includes subtrees with the history of user modifications to managed objects.
• event-logs—Response includes subtrees with event history information.
• faults—Response includes subtrees with currently active faults.
• fault-records—Response includes subtrees with fault history information.
• health—Response includes subtrees with current health information.
• health-records—Response includes subtrees with health history information.
• relations—Response includes relations-related subtree information.
• stats—Response includes statistics-related subtree information.
• tasks—Response includes task-related subtree information.
With any of the preceding categories, you can also specify one of the following options to further refine the
query results:
• count—Response includes a count of matching subtrees but not the subtrees themselves.
• no-scoped—Response includes only the requested subtree information. Other top-level information of
the target MO is not included in the response.
• required—Response includes only the managed objects that have subtrees matching the specified
category.
For example, to include fault-related subtrees, specify fault in the list. To return only fault-related subtrees
and no other top-level MO information, specify fault,no-scoped in the list as shown in this example:
query-target=subtree&rsp-subtree-include=fault,no-scoped
Related Topics
Composing Query Filter Expressions, on page 14
Example: Using the JSON API to Get Running Firmware, on page 49
query-target-filter=[eq|ne](attribute,value)
You can create a more complex test by combining operators and conditions using parentheses and commas:
query-target-filter=[and|or]([eq|ne](attribute,value),[eq|ne](attribute,value),...)
Operator Description
eq Equal to
ne Not equal to
lt Less than
gt Greater than
bw Between
or Logical OR
Operator Description
false Boolean FALSE
wcard Wildcard
Examples
This example returns all managed objects of class aaaUser whose last name is equal to "Washington":
GET https://192.0.20.123/api/class/aaaUser.json?
query-target-filter=eq(aaaUser.lastName,"Washington")
GET https://192.0.20.123/api/class/fvAEPg.xml?
query-target-filter=eq(fvAEPg.fabEncap,"vxlan-12780288")
This example shows all tenant objects with a current health score of less than 50:
GET https://192.0.20.123/api/class/fvTenant.json?
rsp-subtree-include=health,required
&
rsp-subtree-filter=lt(healthInst.cur,"50")
This example returns all endpoint groups and their faults under the tenant ExampleCorp:
GET https://192.0.20.123/api/mo/uni/tn-ExampleCorp.xml?
query-target=subtree
&
target-subtree-class=fvAEPg
&
rsp-subtree-include=faults
This example returns aaa:Domain objects whose names are not "infra" or "common":
GET https://192.0.20.123/api/class/aaaDomain.json?
query-target-filter=
and(ne(aaaDomain.name,"infra"),
ne(aaaDomain.name,"common"))
Use the optional pipe delimiter ('|') to specify either ascending order (asc) or descending order (desc). If no
order is specified, the default is ascending order.
You can perform a multi-level sort by more than one property (for example, last name and first name), but
all properties must be of the same MO or they must be inherited from the same abstract class.
This example shows you how to sort users by last name, then by first name:
GET
https://192.0.20.123/api/class/aaaUser.json?order-by=aaaUser.lastName|asc,aaaUser.firstName|asc
page-size=number-of-objects-per-page
By adding the page operator in the query URI, you can specify a single group to be returned using the following
syntax. The pages start from number 0.
page=page-number
This example shows you how to specify 15 fault instances per page in descending order, returning only the
first page:
GET
https://192.0.20.123/api/class/faultInfo.json?order-by=faultInst.severity|desc&page=0&page-size=15
Note Every query, whether paged or not, generates a new set of results. When you perform a query that returns
only a single page, the query response includes a count of the total results, but the unsent pages are not
stored and cannot be retrieved by a subsequent query. A subsequent query generates a new set of results
and returns the page requested in that query.
Opening a WebSocket
The API subscription feature uses the WebSocket protocol (RFC 6455) to implement a two-way connection
with the API client through which the API can send unsolicited notification messages to the client. To establish
this notification channel, you must first open a WebSocket connection with the API. Only a single WebSocket
connection is needed to support multiple query subscriptions with multiple APIC instances. The WebSocket
connection is dependent on your API session connection, and closes when your API session ends.
The WebSocket connection is typically opened by a JavaScript method in an HTML5-compliant browser, as
in the following example:
In the URI, the %TOKEN% is the current API session token (cookie). This example shows the URI with a
token:
https://192.0.20.123/socketGkZl5NLRZJl5+jqChouaZ9CYjgE58W/pMccR+LeXmdO0obG9NB
Iwo1VBo7+YC1oiJL9mS6I9qh62BkX+Xddhe0JYrTmSG4JcKZ4t3bcP2Mxy3VBmgoJjwZ76ZOuf9V9AD6X
l83lyoR4bLBzqbSSU1R2NIgUotCGWjZt5JX6CJF0=
After the WebSocket connection is established, it is not necessary to resend the API session token when the
API session is refreshed.
Creating a Subscription
To create a subscription to a query, perform the query with the option ?subscription=yes. This example
creates a subscription to a query of the fv:Tenant class in the JSON format:
GET https://192.0.20.123/api/class/fvTenant.json?subscription=yes
The query response contains a subscription identifier, subscriptionId, that you can use to refresh the
subscription and to identify future notifications from this subscription.
{
"subscriptionId" : "72057611234574337",
"imdata" : [{
"fvTenant" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "",
"dn" : "uni/tn-common",
"lcOwn" : "local",
"monPolDn" : "",
"name" : "common",
"replTs" : "never",
"status" : ""
}
}
}
]
}
Receiving Notifications
An event notification from the subscription delivers a data structure that contains the subscription ID and the
MO description. In this JSON example, a new user has been created with the name "sysadmin5":
{
"subscriptionId" : ["72057598349672454", "72057598349672456"],
"imdata" : [{
"aaaUser" : {
"attributes" : {
"accountStatus" : "active",
"childAction" : "",
"clearPwdHistory" : "no",
"descr" : "",
"dn" : "uni/userext/user-sysadmin5",
"email" : "",
"encPwd" : "TUxISkhH$VHyidGgBX0r7N/srt/YcMYTEn5248ommFhNFzZghvAU=",
"expiration" : "never",
"expires" : "no",
"firstName" : "",
"intId" : "none",
"lastName" : "",
"lcOwn" : "local",
"name" : "sysadmin5",
"phone" : "",
"pwd" : "",
"pwdLifeTime" : "no-password-expire",
"pwdSet" : "yes",
"replTs" : "2013-05-30T11:28:33.835",
"rn" : "",
"status" : "created"
}
}
}
]
}
Because multiple active subscriptions can exist for a query, a notification can contain multiple subscription
IDs as in the example shown.
GET https://192.0.20.123/api/subscriptionRefresh.json?id=72057611234574337
The API returns an empty response to the refresh message unless the subscription has expired.
Note The timeout period for a subscription is one minute. To prevent lost notifications, you must send a
subscription refresh message at least once every 60 seconds.
When you send an API command, the APIC checks the command for conformance with the MIM schema. If
an API command violates the MIM schema, the APIC rejects the command and returns an error message. For
example, you can create an MO only if it is allowed in the path you have specified in the command URI and
only if you have the required privilege level for that object class. You can configure an MO's properties only
with valid data, and you cannot create properties.
When composing an API command to create an MO, you need only include enough information in the
command's URI and data structure to uniquely define the new MO. If you omit the configuration of a property
when creating the MO, the property is populated with a default value if the MIM specifies one, or it is left
blank.
When modifying a property of an MO, you need only specify the property to be modified and its new value.
Other properties will be left unchanged.
Note When you modify an MO that affects APIC or switch management communication policy, you might
experience a brief disruption of any operations in progress on any APIC or switch web interface in the
fabric. Configuration changes that can result in disruption include the following:
• changing management port settings, such as port number
• enabling or disabling HTTPS
• changing the state of redirection to HTTPS
• PKI changes, such as key ring
Tip In addition to the API examples shown in this document, you can find detailed examples of many common
tasks using the API in the Cisco APIC Getting Started Guide.
Using Tags
To simplify API operations, you can assign tags to an object. A tag allows you to group multiple objects by
a descriptive name. You can assign the same tag name to multiple objects and you can assign one or more tag
names to an object. In an API operation, you can refer to the object or group of objects by the tag name instead
of by the distinguished name (DN).
Adding Tags
You can add one or more tags by using the following syntax in the URI of an API POST operation:
In this syntax, name is the name of a tag and dn is the distinguished name of the object to which the tag is
assigned.
This example shows how to assign the tags tenants and orgs to the tenant named ExampleCorp:
POST https://192.0.20.123/api/tag/mo/uni/tn-ExampleCorp.xml?add=tenants,orgs
Removing Tags
You can remove one or more tags by using the following syntax in the URI of an API POST operation:
This example shows how to remove the tag orgs from the tenant named ExampleCorp:
POST https://192.0.20.123/api/tag/mo/uni/tn-ExampleCorp.xml?remove=orgs
You can delete all instances of a tag by using the following syntax in the URI of an API DELETE operation:
/api//tag/name.{json| xml}
This example shows how to remove the tag orgs from all objects:
DELETE https://192.0.20.123/api/tag/orgs.xml
Note In the examples in this section, the responses have been edited to remove attributes unrelated to tags.
This example shows how to find all tags assigned to the tenant named ExampleCorp:
GET https://192.0.20.123/api/tag/mo/uni/tn-ExampleCorp.xml
RESPONSE:
<imdata>
<tagInst
dn="uni/tn-ExampleCorp/tag-tenants"
name="tenants"
/>
<tagInst
dn="uni/tn-ExampleCorp/tag-orgs"
name="orgs"
/>
</imdata>
This example shows how to find all objects with the tag 'tenants':
GET https://192.0.20.123/api/tag/tenants.xml
RESPONSE:
<imdata>
<fvTenant
dn="uni/tn-ExampleCorp"
name="ExampleCorp"
/>
</imdata>
Note You can find detailed procedures of many common tasks using the API in the Cisco APIC Getting Started
Guide.
This section provides simple examples of typical tasks that are required in order to create a tenant and deploy
an application. These are the general steps:
• Logging in—Open a session to perform configuration tasks.
• Creating a tenant—Create a private domain within the fabric for a tenant company who will host an
application.
• Creating a user—Create an account for the tenant's administrator, who will deploy and maintain the
tenant's application.
• Deploying an application—Configure the endpoint groups and contracts in a tenant network to connect
the servers needed to host an application.
Note In the examples, the JSON and XML structures have been expanded with line feeds, spaces, and indentations
for readability.
Logging In
You can log in to the APIC REST API by sending a valid username and password in a data structure to the
aaaLogin API method, as described in Authenticating and Maintaining an API Session, on page 9. Following
a successful login, you must periodically refresh the session.
The following examples show how to log in as an administrator, refresh the session during configuration, and
log out using XML and JSON.
POST https://192.0.20.123/api/aaaLogin.xml
<imdata>
<aaaLogin
token=
"mk/i+LHZMhFQ47YyMlfZOjmUQQV4PXwFAY/6Dyg5Bm7PC0SVdm
MVWeOlLw69AoNoRVziR8GQeNqPbX/Vu92PxWyPjGx7kOQpoTaUY
P4Y2NkBwRfl5fEDwUe5WnGl3VoBXF4nrc8QSG8N1UWCuIFIyt9O
OzgsLG58fTf4OPCUqQL="
refreshTimeoutSeconds="300" lastName="Washington" firstName="George">
<aaaUserDomain name="all" rolesR="0" rolesW="2">
<aaaReadRoles/>
<aaaWriteRoles>
<role name="admin"/>
</aaaWriteRoles>
</aaaUserDomain>
<aaaUserDomain name="common" rolesR="0" rolesW="1">
<aaaReadRoles/>
<aaaWriteRoles>
<role name="read-only"/>
</aaaWriteRoles>
</aaaUserDomain>
<DnDomainMapEntry dn="uni/tn-common" readPrivileges="0" writePrivileges="3"/>
</aaaLogin>
</imdata>
The response contains a session timeout period and a session token, along with domain and role information
about the user.
This example refreshes the session using the aaaRefresh API method:
GET https://192.0.20.123/api/aaaRefresh.xml
lastName=""
firstName=""/>
</imdata>
This example logs out a user using the aaaLogout API method:
POST https://192.0.20.123/api/aaaLogout.json
POST https://192.0.20.123/api/aaaLogin.json
{
"aaaUser":{
"attributes":{
"name":"georgewa",
"pwd":"paSSword1"
}
}
}
{
"imdata":[{
"aaaLogin":{
"attributes":{
"token":"token":
"GkZl5NLRZJl5+jqChouaZ9CYjgE58W/pMccR+LeXmdO0obG9NB
Iwo1VBo7+YC1oiJL9mS6I9qh62BkX+Xddhe0JYrTmSG4JcKZ4t3
bcP2Mxy3VBmgoJjwZ76ZOuf9V9AD6Xl83lyoR4bLBzqbSSU1R2N
IgUotCGWjZt5JX6CJF0=",
"refreshTimeoutSeconds":"300",
"lastName":"Washington",
"firstName":"George"
},
"children":[{
"aaaUserDomain":{
"attributes":{
"name":"all",
"rolesR":"0",
"rolesW":"2"
},
"children":[{
"aaaReadRoles":{
"attributes":{}
}
}, {
"aaaWriteRoles":{
"attributes":{},
"children":[{
"role":{
"attributes":{
"name":"admin"
}
}
}
]
}
}
]
}
}, {
"aaaUserDomain":{
"attributes":{
"name":"common",
"rolesR":"0",
"rolesW":"1"
},
"children":[{
"aaaReadRoles":{
"attributes":{}
}
}, {
"aaaWriteRoles":{
"attributes":{},
"children":[{
"role":{
"attributes":{
"name":"read-only"
}
}
}
]
}
}
]
}
}, {
"DnDomainMapEntry":{
"attributes":{
"dn":"uni/tn-common",
"readPrivileges":"0",
"writePrivileges":"3"
}
}
}
]
}
}
]
}
The response contains a session timeout period and a session token, along with domain and role information
about the user.
This example refreshes the session using the aaaRefresh API method:
GET https://192.0.20.123/api/aaaRefresh.json
{
"imdata":[{
"aaaLogin":{
"attributes":{
"token":
"Zs8jf2rcseiiYydx9WbyRVOScWs6c0Orti7EBg1H02jt0JV9oe
icX1ULLquI+LCN/93cAf46AErXpT4kN0mrCQRcCMRAl6m0ObT/r
G4D9UTm6/NNnqzhntCWTKt9IovTFDpD8Ocx1oXn2jpmS6PYDBJt
Wp4rIAu11sdM8BA24g6=",
"refreshTimeoutSeconds":"0",
"lastName":"",
"firstName":""
}
}
}
]
}
This example logs out a user using the aaaLogout API method:
POST https://192.0.20.123/api/aaaLogout.json
{
"aaaUser":{
"attributes":{
"name":"georgewa"
}
}
}
{
"imdata":[]
}
Adding a Tenant
A tenant is a policy owner in the virtual fabric. A tenant can be either a private or a shared entity. For example,
you can create a securely partitioned private tenant or a tenant with contexts and bridge domains shared by
other tenants. A shared type of tenant is typically named common, default, or infra.
In the management information model, a tenant is represented by a managed object (MO) of class fv:Tenant.
According to the Cisco APIC Management Information Model Reference, an object of the fv:Tenant class is
a child of the policy resolution universe (uni) class and has a distinguished name (DN) format of uni/tn-[name].
The following examples show how to add a new tenant named ExampleCorp using XML and JSON.
POST https://192.0.20.123/api/mo/uni.xml
<fvTenant name="ExampleCorp"/>
Alternatively, you can name the tenant in the URI, as in this example:
POST https://192.0.20.123/api/mo/uni/tn-ExampleCorp.xml
<fvTenant />
If a response is requested (by appending ?rsp-subtree=modified to the POST URI), a successful operation
returns the following response body:
<imdata>
<fvTenant
instanceId="0:0"
childAction="deleteNonPresent"
dn="uni/tn-ExampleCorp"
lcOwn="local"
name="ExampleCorp"
replTs="never"
rn=""
status="created"
/>
</imdata>
DELETE https://192.0.20.123/api/mo/uni/tn-ExampleCorp.xml
Alternatively, you can send an HTTP POST message with sufficient naming information and with
status="deleted" in the fv:Tenant attributes, as in this example:
POST https://192.0.20.123/api/mo/uni.xml
POST https://192.0.20.123/api/mo/uni.json
{
"fvTenant" : {
"attributes" : {
"name" : "ExampleCorp"
}
}
}
Alternatively, you can name the tenant in the URI, as in this example:
POST https://192.0.20.123/api/mo/uni/tn-ExampleCorp.json
{
"fvTenant" : {
"attributes" : {
}
}
}
If a response is requested (by appending ?rsp-subtree=modified to the POST URI), a successful operation
returns the following response body:
{
"imdata" :
[{
"fvTenant" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "deleteNonPresent",
"dn" : "uni/tn-ExampleCorp",
"lcOwn" : "local",
"name" : "ExampleCorp",
"replTs" : "never",
"rn" : "",
"status" : "created"
}
}
}
]
}
DELETE https://192.0.20.123/api/mo/uni/tn-ExampleCorp.json
Alternatively, you can send an HTTP POST message with sufficient naming information and with "status"
: "deleted" in the fv:Tenant attributes, as in this example:
POST https://192.0.20.123/api/mo/uni.json
{
"fvTenant" : {
"attributes" : {
"name" : "ExampleCorp",
"status" : "deleted"
}
}
}
Adding a User
An APIC user account contains, in addition to a name and password, information about the user's privilege
level (role) and the scope (domain) of the user's control in the fabric. A cloud administrator, for example,
might have global control, including the ability to create tenants and to assign additional administrators, while
a tenant administrator is typically restricted to the tenant's domain or network. When you configure a user
account, you can specify additional configuration items, such as a password expiration policy, or you can
omit those items to accept the default settings.
In the management information model, an APIC user is represented by a managed object (MO) of class
aaa:User. According to the Cisco APIC Management Information Model Reference, an object of the aaa:User
class has a distinguished name (DN) format of uni/userext/user-[name]. The direct properties (attributes)
of the aaa:User class do not include fields for the user domain or privilege level, but the reference for this
class indicates a child class (subtree) of aaa:UserDomain, which has a child class of aaa:UserRole. The API
command structure to add the new user can include the configuration of the user domain and privilege level
in these child classes in the following hierarchy:
• aaa:User—The user object can contain one or more user domain child objects.
◦aaa:UserDomain—The user domain object can contain one or more user role objects.
◦aaa:UserRole—The user role object specifies the privilege level of the user.
The following examples show how to add a new user to the user domain ExampleCorp with administrator
privileges using XML and JSON. An additional example shows how to use a cURL command to perform the
task from a command line.
POST https://192.0.20.123/api/mo/uni/userext/user-georgewa.xml
<aaaUser
pwd="password1"
firstName="George"
lastName="Washington"
phone="4085551212"
email="georgewa@example.com" >
<aaaUserDomain name="ExampleCorp" >
<aaaUserRole name="admin" />
</aaaUserDomain>
</aaaUser>
Alternatively, you can POST to /api/mo.xml and provide the DN attribute dn="uni/userext/user-georgewa",
or you can POST to /api/mo/uni/userext.xml and provide the name attribute name="georgewa".
The children sections of this command structure configure the new user to be in the ExampleCorp user domain
with a role of admin in that user domain. When you create a new user, you can specify less information or
more information than is shown in this example. Additional attributes can be configured in subsequent
operations.
If a response is requested (by appending ?rsp-subtree=modified to the POST URI), a successful operation
returns the following response body:
<imdata>
<aaaUser
instanceId="0:0"
accountStatus="active"
childAction="deleteNonPresent"
clearPwdHistory="no"
descr=""
dn="uni/userext/user-georgewa"
email="georgewa@example.com"
encPwd=""
expiration="never"
expires="no"
firstName="George"
intId="none"
lastName="Washington"
lcOwn="local"
name="georgewa"
phone="4085551212"
pwd="password1"
pwdLifeTime="no-password-expire"
pwdSet="no"
replTs="never"
rn=""
status="created" >
<aaaUserDomain
instanceId="0:0"
childAction="deleteNonPresent"
descr="" intId="none"
lcOwn="local"
name="common"
replTs="never"
rn="userdomain-common"
status="created" >
<aaaUserRole
instanceId="0:0"
childAction="deleteNonPresent"
descr=""
intId="none"
lcOwn="local"
name="read-only"
privType="readPriv"
replTs="never"
rn="role-read-only"
status="created" />
</aaaUserDomain>
<aaaUserDomain
instanceId="0:0"
childAction="deleteNonPresent"
descr=""
intId="none"
lcOwn="local"
name="ExampleCorp"
replTs="never"
rn="userdomain-ExampleCorp"
status="created" >
<aaaUserRole
instanceId="0:0"
childAction="deleteNonPresent"
descr=""
intId="none"
lcOwn="local"
name="admin"
privType="readPriv"
replTs="never"
rn="role-admin"
status="created" />
</aaaUserDomain>
</aaaUser>
</imdata>
This response indicates that the user has been created and added to two user domains. The user has admin
privileges in the ExampleCorp user domain, as requested. By default, the user also has read-only privileges
in the common user domain.
To delete the user, send this HTTP DELETE message:
DELETE https://192.0.20.123/api/mo/uni/userext/user-georgewa.xml
Alternatively, you can send an HTTP POST message with sufficient naming information and with
status="deleted" in the aaa:User attributes, as in this example:
POST https://192.0.20.123/api/mo.xml
POST https://192.0.20.123/api/mo/uni/userext/user-georgewa.json
{
"aaaUser" : {
"attributes" : {
"pwd" : "password1",
"firstName" : "George"
"lastName" : "Washington",
"phone" : "4085551212",
"email" : "georgewa@example.com"
},
"children" : [{
"aaaUserDomain" : {
"attributes" : {
"name" : "ExampleCorp"
},
"children" : [{
"aaaUserRole" : {
"attributes" : {
"name" : "admin"
}
}
}
]
}
}
]
}
}
{
"imdata" : [{
"aaaUser" : {
"attributes" : {
"instanceId" : "0:0",
"accountStatus" : "active",
"childAction" : "deleteNonPresent",
"clearPwdHistory" : "no",
"descr" : "",
"dn" : "uni/userext/user-georgewa",
"email" : "georgewa@example.com",
"encPwd" : "",
"expiration" : "never",
"expires" : "no",
"firstName" : "George",
"intId" : "none",
"lastName" : "Washington",
"lcOwn" : "local",
"name" : "georgewa",
"phone" : "5551212",
"pwd" : "password1",
"pwdLifeTime" : "no-password-expire",
"pwdSet" : "no",
"replTs" : "never",
"rn" : "",
"status" : "created"
},
"children" : [{
"aaaUserDomain" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "deleteNonPresent",
"descr" : "",
"dn" : "",
"intId" : "none",
"lcOwn" : "local",
"name" : "common",
"replTs" : "never",
"rn" : "userdomain-common",
"status" : "created"
},
"children" : [{
"aaaUserRole" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "deleteNonPresent",
"descr" : "",
"dn" : "",
"intId" : "none",
"lcOwn" : "local",
"name" : "read-only",
"privType" : "readPriv",
"replTs" : "never",
"rn" : "role-read-only",
"status" : "created"
}
}
}
]
}
}, {
"aaaUserDomain" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "deleteNonPresent",
"descr" : "",
"dn" : "",
"intId" : "none",
"lcOwn" : "local",
"name" : "ExampleCorp",
"replTs" : "never",
"rn" : "userdomain-ExampleCorp",
"status" : "created"
},
"children" : [{
"aaaUserRole" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "deleteNonPresent",
"descr" : "",
"dn" : "",
"intId" : "none",
"lcOwn" : "local",
"name" : "admin",
"privType" : "writePriv",
"replTs" : "never",
"rn" : "role-admin",
"status" : "created"
}
}
}
]
}
}
]
}
}
]
}
This response indicates that the user has been created and added to two user domains. The user has admin
privileges in the ExampleCorp user domain, as requested. By default, the user also has read-only privileges
in the common user domain.
DELETE https://192.0.20.123/api/mo/uni/userext/user-georgewa.json
Alternatively, you can send an HTTP POST message with sufficient naming information and with
"status":"deleted" in the aaa:User attributes, as in this example:
POST https://192.0.20.123/api/mo.json
{
"aaaUser" : {
"attributes" : {
"dn" : "uni/userext/user-georgewa",
"status" : "deleted"
}
}
}
Note Be sure to include the @ sign before the filename. The cURL tool is free and open software. You can find
detailed information about using cURL online.
If a response is requested (by appending ?rsp-subtree=modified to the POST URI), a successful operation
returns the response body shown in Example: Using the JSON API to Add a User, on page 29.
To delete the user, edit the JSON file to contain a aaaUser attribute of "status":"deleted" and send the
command again.
Alternatively, you can send this HTTP DELETE message:
Note For an expanded and comprehensive example of deploying a three-tier application, see the Cisco APIC
Getting Started Guide.
The configuration information is contained in a single XML structure that is sent to the distinguished name
(DN) of the tenant. In this example, the name of the tenant is ExampleCorp. To deploy the application using
the XML API, send this HTTP POST message:
POST https://192.0.20.123/api/mo/uni/tn-ExampleCorp.xml
<fvTenant name="ExampleCorp">
<fvAp name="OnlineStore">
<fvAEPg name="web">
<fvRsBd tnFvBDName="bd1"/>
<fvRsCons tnVzBrCPName="rmi"/>
<fvRsProv tnVzBrCPName="web"/>
<fvRsDomAtt tDn="uni/vmmp-VMware/dom-datacenter"/>
</fvAEPg>
<fvAEPg name="db">
<fvRsBd tnFvBDName="bd1"/>
<fvRsProv tnVzBrCPName="sql"/>
<fvRsDomAtt tDn="uni/vmmp-VMware/dom-datacenter"/>
</fvAEPg>
<fvAEPg name="app">
<fvRsBd tnFvBDName="bd1"/>
<fvRsProv tnVzBrCPName="rmi"/>
<fvRsCons tnVzBrCPName="sql"/>
<fvRsDomAtt tDn="uni/vmmp-VMware/dom-datacenter"/>
</fvAEPg>
</fvAp>
<vzFilter name="sql">
<vzEntry dFromPort="1521" name="DPort-1521" prot="tcp" etherT="ip" />
</vzFilter>
<vzBrCP name="web">
<vzSubj name="web">
<vzRsSubjFiltAtt tnVzFilterName="http"/>
</vzSubj>
</vzBrCP>
<vzBrCP name="rmi">
<vzSubj name="rmi">
<vzRsSubjFiltAtt tnVzFilterName="rmi"/>
</vzSubj>
</vzBrCP>
<vzBrCP name="sql">
<vzSubj name="sql">
<vzRsSubjFiltAtt tnVzFilterName="sql"/>
</vzSubj>
</vzBrCP>
</fvTenant>
In the XML structure, the first line modifies, or creates if necessary, the tenant named ExampleCorp.
<fvTenant name="ExampleCorp">
<fvAp name="OnlineStore">
The elements within the application network profile create three endpoint groups, one for each of the three
servers. The following lines create an endpoint group named web and associate it with an existing bridge
domain named bd1. This endpoint group is a consumer, or destination, of the traffic allowed by the binary
contract named rmi and is a provider, or source, of the traffic allowed by the binary contract named web. The
endpoint group is associated with the VMM domain named datacenter.
<fvAEPg name="web">
<fvRsBd tnFvBDName="bd1"/>
<fvRsCons tnVzBrCPName="rmi"/>
<fvRsProv tnVzBrCPName="web"/>
<fvRsDomAtt tDn="uni/vmmp-VMware/dom-datacenter"/>
</fvAEPg>
The remaining two endpoint groups, for the application server and the database server, are created in a similar
way.
The following lines define a traffic filter named http that specifies TCP traffic of types HTTP (port 80) and
HTTPS (port 443).
<vzFilter name="http">
<vzEntry dFromPort="80" name="DPort-80" prot="tcp" />
<vzEntry dFromPort="443" name="DPort-443" prot="tcp" />
</vzFilter>
The remaining two filters, for application data and database (sql) data, are created in a similar way.
The following lines create a binary contract named web that incorporates the filter named http:
<vzBrCP name="web">
<vzSubj name="web">
<vzRsSubjFiltAtt tnVzFilterName="http"/>
</vzSubj>
</vzBrCP>
The remaining two contracts, for rmi and sql data protocols, are created in a similar way.
The final line closes the structure:
</fvTenant>
Procedure
Step 4 In the Filters toolbar of the API Inspector window, choose the types of API log messages to display.
The displayed messages are color-coded according to the selected message types. This table shows the available
message types:
Name Description
trace Displays trace messages.
Name Description
debug Displays debug messages. This type includes most API commands and responses.
info Displays informational messages.
warn Displays warning messages.
error Displays error messages.
fatal Displays fatal messages.
all Checking this checkbox causes all other checkboxes to become checked. Unchecking any
other checkbox causes this checkbox to be unchecked.
Step 5 In the Search toolbar, you can search the displayed messages for an exact string or by a regular expression.
This table shows the search controls:
Name Description
Search In this text box, enter a string for a direct search or enter a regular expression for a regex
search. As you type, the first matched field in the log list is highlighted.
Reset Click this button to clear the contents of the Search text box.
Regex Check this checkbox to use the contents of the Search text box as a regular expression for
a search.
Match case Check this checkbox to make the search case sensitive.
Disable Check this checkbox to disable the search and clear the highlighting of search matches in
the log list.
Next Click this button to cause the log list to scroll to the next matched entry. This button
appears only when a search is active.
Previous Click this button to cause the log list to scroll to the previous matched entry. This button
appears only when a search is active.
Filter Check this checkbox to hide nonmatched lines. This checkbox appears only when a search
is active.
Highlight all Check this checkbox to highlight all matched fields. This checkbox appears only when a
search is active.
Step 6 In the Options toolbar, you can arrange the displayed messages.
This table shows the available options:
Name Description
Log Check this checkbox to enable logging.
Wrap Check this checkbox to enable wrapping of lines to avoid horizontal scrolling of the log
list
Name Description
Newest at the Check this checkbox to display log entries in reverse chronological order.
top
Scroll to latest Check this checkbox to scroll immediately to the latest log entry.
Clear Click this button to clear the log list.
Close Click this button to close the API Inspector.
Example
This example shows two debug messages in the API Inspector window:
Note Only the Firefox, Chrome, and Safari browsers are supported for Visore access.
Accessing Visore
Procedure
Step 1 Open a supported browser and enter the URL of the APIC followed by /visore.html.
Example:
https://192.0.20.123/visore.html
Step 2 When prompted, log in using the same credentials you would use to log in to the APIC CLI or GUI user
interfaces.
Name Description
Class or DN field Object class name or fully distinguished name of a managed object.
Property field The property of the managed object on which you want to filter the
results. If you leave the Property field empty, the search returns all
instances of the specific class.
Op drop-down list Operator for the values of the property on which you want to filter the
results. The following are valid operators:
• == (equal to)
• != (not equal to)
• < (less than)
• > (greater than)
• ≤ (less than or equal to)
• ≥ (greater than or equal to)
• between
• wildcard
• anybit
• allbits
Val1 field The first value for the property on which you want to filter.
Results Area
You can bookmark any query results page in your browser to view the results again because the query is
encoded in the URL.
Note Many of the managed objects are only used internally and are not generally applicable to APIC REST
API program development.
Name Description
Pink background Separates individual managed object instances and displays the class
name of the object below it.
Blue or green background Indicates the property names of the managed object.
dn link When clicked, displays all managed objects with that dn.
Class name link When clicked, displays all managed objects of that class.
Left arrow When clicked, takes you to the parent object of the managed object.
Right arrow When clicked, takes you to the child objects of the managed object.
Question mark Links you to the XML API documentation for the managed object.
Step 4 (Optional) Click the Display URI of last query link to display the API call that executed the query.
Step 5 (Optional) Click the Display last response link to display the API response data structure from the query.
Step 6 (Optional) In the dn field of the MO description table, click the < and > icons to retrieve the parent and child
classes of the displayed MO.
Clicking > sends a query to the APIC for the children of the MO. Clicking < sends a query for the parent of
the MO.
Step 7 (Optional) In the dn field of the MO description table, click the additional icons to display statistics, faults,
or health information for the MO.
Browser add-ons pass the session token as a cookie so that there is no need to include the token in the payload
data structure.
You must specify the name of your descriptor file and the URI of the API operation.
Note Make sure to include the "@" symbol before the descriptor filename.
This example creates a new tenant named ExampleCorp using the JSON data structure in the file
"newtenant.json":
Note When testing with cURL, you must log in to the API, store the authentication token, and include the token
in subsequent API operations.
Related Topics
Example: Using the JSON API to Add a User with cURL, on page 32
import json
import requests
base_url = 'https://192.0.20.123/api/'
# log in to API
login_url = base_url + 'aaaLogin.json'
post_response = requests.post(login_url, data=json_credentials)
In this example, you must manage the authentication token (cookie) for the session. The Python requests
module contains a Session() method that manages the token automatically.
For more information about the Python requests module, see http://www.python-requests.org.
The URI path contains 'ppi' (package programming interface) instead of 'api', and the command is sent as a
POST operation with the device package file as the body of the message. The device package file is a zip file.
This example shows an API operation that uploads a device package file:
POST https://192.0.20.123/ppi/node/mo/.json
For more information about installing L4-L7 service device packages, see Cisco APIC Layer 4 to Layer 7
Services Deployment Guide .
Example: Using the JSON API to Get Top Level System Elements
This example shows how to query the APIC to determine what system devices are present.
General information about the system elements (APICs, spines, and leafs) is contained in an object of class
top:System.
This example shows the API query message:
GET http://192.0.20.123/api/class/topSystem.json
{
"imdata" :
[{
"topSystem" : {
"attributes" : {
"instanceId" : "0:0",
"address" : "10.0.0.32",
"childAction" : "",
"currentTime" : "2013-06-14T04:13:05.584",
"currentTimeZone" : "",
"dn" : "topology/pod-1/node-17/sys",
"fabricId" : "0",
"id" : "17",
"inbMgmtAddr" : "0.0.0.0",
"lcOwn" : "local",
"mode" : "unspecified",
"name" : "leaf0",
"nodeId" : "0",
"oobMgmtAddr" : "0.0.0.0",
"podId" : "1",
"replTs" : "never",
"role" : "leaf",
"serial" : "FOX-270308",
"status" : "",
"systemUpTime" : "00:00:02:03"
}
}
}, {
"topSystem" : {
"attributes" : {
"instanceId" : "0:0",
"address" : "10.0.0.1",
"childAction" : "",
"currentTime" : "2013-06-14T04:13:29.301",
"currentTimeZone" : "PDT",
"dn" : "topology/pod-1/node-1/sys",
"fabricId" : "0",
"id" : "1",
"inbMgmtAddr" : "0.0.0.0",
"lcOwn" : "local",
"mode" : "unspecified",
"name" : "apic0",
"nodeId" : "0",
"oobMgmtAddr" : "0.0.0.0",
"podId" : "0",
"replTs" : "never",
"role" : "apic",
"serial" : "",
"status" : "",
"systemUpTime" : "00:00:02:26"
}
}
}
]
}
This response indicates that the system consists of one APIC (node-1) and one leaf (node-17).
GET http://192.0.20.123/api/mo/topology/pod-1/node-1/sys/ch/bslot/board/sensor-3.json
{
"imdata" :
[{
"eqptSensor" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "",
"dn" : "topology/pod-1/node-1/sys/ch/bslot/board/sensor-3",
"id" : "3",
"majorThresh" : "0",
"mfgTm" : "not-applicable",
"minorThresh" : "0",
"model" : "",
"monPolDn" : "",
"rev" : "0",
"ser" : "",
"status" : "",
"type" : "dimm",
"vendor" : "Cisco Systems, Inc."
}
}
}
]
}
GET http://192.0.20.123/api/class/firmwareIfcFwStatusCont.json?
query-target=subtree
&
target-subtree-class=firmwareIfcRunning
{
"imdata" : [{
"firmwareIfcRunning" : {
"attributes" : {
"instanceId" : "0:0",
"applId" : "3",
"childAction" : "",
"dn" : "ifcfwstatuscont/ifcrunning-3",
"lcOwn" : "local",
"replTs" : "never",
"rn" : "",
"status" : "",
"ts" : "2012-12-31T16:00:00.000",
"type" : "ifc",
"version" : "1.1"
}
}
}, {
"firmwareIfcRunning" : {
"attributes" : {
"instanceId" : "0:0",
"applId" : "1",
"childAction" : "",
"dn" : "ifcfwstatuscont/ifcrunning-1",
"lcOwn" : "local",
"replTs" : "never",
"rn" : "",
"status" : "",
"ts" : "2012-12-31T16:00:00.000",
"type" : "ifc",
"version" : "1.1"
}
}
}, {
"firmwareIfcRunning" : {
"attributes" : {
"instanceId" : "0:0",
"applId" : "2",
"childAction" : "",
"dn" : "ifcfwstatuscont/ifcrunning-2",
"lcOwn" : "local",
"replTs" : "never",
"rn" : "",
"status" : "",
"ts" : "2012-12-31T16:00:00.000",
"type" : "ifc",
"version" : "1.1"
}
}
}
]
}
This response describes three running instances of APIC firmware version 1.1.
Example: Using the JSON API to Add a Leaf Port Selector Profile
This example shows how to add a leaf port selector profile.
As shown in the Cisco APIC Management Information Model Reference, this hierarchy of classes forms a
leaf port selector profile:
• fabric:LePortP — A leaf port profile is represented by a managed object (MO) of this class, which has
a distinguished name (DN) format of uni/fabric/leportp-[name], in which leportp-[name] is the
relative name (RN). The leaf port profile object is a template that can contain a leaf port selector as a
child object.
◦fabric:LFPortS — A leaf port selector is represented by an MO of this class, which has a RN format
of lefabports-[name]-typ-[type]. The leaf port selector object can contain one or more ports
or ranges of ports as child objects.
◦fabric:PortBlk — A leaf port or a range of leaf ports is represented by an MO of this class,
which has a RN format of portblk-[name].
The API command that creates the new leaf port selector profile MO can also create and configure the child
MOs.
This example creates a leaf port selector profile with the name "MyLPSelectorProf." The example profile
contains a selector named "MySelectorName" that selects leaf port 1 on leaf switch 1 and leaf ports 3 through
5 on leaf switch 1. To create and configure the new profile, send this HTTP POST message:
POST http://192.0.20.123/api/mo/uni/fabric/leportp-MyLPSelectorProf.json
{
"fabricLePortP" : {
"attributes" : {
"descr" : "Selects leaf ports 1/1 and 1/3-5"
},
"children" : [{
"fabricLFPortS" : {
"attributes" : {
"name" : "MySelectorName",
"type" : "range"
},
"children" : [{
"fabricPortBlk" : {
"attributes" : {
"fromCard" : "1",
"toCard" : "1",
"fromPort" : "1",
"toPort" : "1",
"name" : "block2"
}
}
}, {
"fabricPortBlk" : {
"attributes" : {
"fromCard" : "1",
"toCard" : "1",
"fromPort" : "3",
"toPort" : "5",
"name" : "block3"
}
}
}
]
}
}
]
}
}
{
"imdata" : [{
"fabricLePortP" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "deleteNonPresent",
"descr" : "Select leaf ports 1/1 and 1/3-5",
"dn" : "uni/fabric/leportp-MyLPSelectorProf",
"lcOwn" : "local",
"name" : "MyLPSelectorProf",
"replTs" : "never",
"rn" : "",
"status" : "created"
},
"children" : [{
"fabricLFPortS" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "deleteNonPresent",
"dn" : "",
"lcOwn" : "local",
"name" : "MySelectorName",
"replTs" : "never",
"rn" : "lefabports-MySelectorName-typ-range",
"status" : "created",
"type" : "range"
},
"children" : [{
"fabricPortBlk" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "deleteNonPresent",
"dn" : "",
"fromCard" : "1",
"fromPort" : "3",
"lcOwn" : "local",
"name" : "block3",
"replTs" : "never",
"rn" : "portblk-block3",
"status" : "created",
"toCard" : "1",
"toPort" : "5"
}
}
}, {
"fabricPortBlk" : {
"attributes" : {
"instanceId" : "0:0",
"childAction" : "deleteNonPresent",
"dn" : "",
"fromCard" : "1",
"fromPort" : "1",
"lcOwn" : "local",
"name" : "block2",
"replTs" : "never",
"rn" : "portblk-block2",
"status" : "created",
"toCard" : "1",
"toPort" : "1"
}
}
}
]
}
}
]
}
}
]
}
To delete the new profile, send an HTTP POST message with a fabricLePortP attribute of "status":"deleted",
as in this example:
POST http://192.0.20.123/api/mo/uni/fabric/leportp-MyLPSelectorProf.json
{
"fabricLePortP" : {
"attributes" : {
"status" : "deleted"
}
}
}
DELETE http://192.0.20.123/api/mo/uni/fabric/leportp-MyLPSelectorProf.json
Procedure
A example (continued)
get top level system elements 47
about the API 3
API 3
information about 3
API Inspector 37 F
authentication 9, 11 filtering query results 12
firmware 49
example of query 49
C
challenge token 11
concrete object 1 G
Content-Type 6 GET 6
specifying 6
cURL 32, 42
example 32
using 42 J
JSON 3
D
deploying a three-tier application (XML) 33 L
distinguished name 2
description 2 logical object 1
DME 3 login 9, 22, 23
logout 9, 22, 23
logs 37
E
example 22, 23, 25, 26, 28, 29, 32, 47, 48, 49, 50 M
adding a profile 50
adding a tenant (JSON) 26 managed object, See MO
adding a tenant (XML) 25 managed object browser 39
adding a user (JSON) 29 management information model, See MIM
adding a user (XML) 28 management information tree 3
adding a user with cURL 32 See also MIM
authenticating a user (JSON) 23 MIM 1
authenticating a user (XML) 22 MO 1
get node information 48 concrete 1
get running firmware 49 logical 1
N tenant 25, 26
example of adding (JSON) 26
node 48 example of adding (XML) 25
example of accessing 48 testing 42, 43
using browser add-on 42
using cURL 42
P using Python 43
three-tier application 33
POST 6 deploying (XML) 33
profile 50 timeout 9, 22, 23
example of adding 50
Python 43
using 43
U
URI 6
Q structure 6
user 22, 23, 28, 29, 32
query 12, 14, 16 example of adding (JSON) 29
filter expressions 14 example of adding (XML) 28
filtering 12 example of adding with cURL 32
scoping 12 example of authenticating (JSON) 23
subscribing 16 example of authenticating (XML) 22
R V
refresh 9, 22, 23 Visore utility 39, 41
relative name 2 accessing 39
example 2 description 39
REST architecture 3 running a query 41
S W
scoping query results 12 WebSocket 16
subscription 16
X
T
XML 3
tags 19