api_request_v1

api_request_v1 is an Aurora template function that can be used to access the Aurora API. This article describes what this function does and how to use it.

Introduction

The function allows you to access a set of API methods without requiring authentication. Only a subset of API functions are allowed, primarily GET based functions but some others are allowed for logged in users only.

API Token

No API token is required to use this smarty function as only whitelisted methods can be accessed. There is a token called Front-end V1 API Access that can be used to manage access in the future.

Parameters

ParameterExampleRequiredExplanation
methodProductSearchYThe API method from the Allowed API methods list that is to be accessed. Must also match the method contained in the request_xml.
version1.5YThe version of the API to be used.
request_xmlSee the example usageYThe API request. This is an xml string containing the API Request, it is the same as a normal xml request but only contains the information between and including the <AuroraRequestEnvelope> elements.

Allowed API methods

Only the following methods are whitelisted for access via Smarty.

  • ProductSearch
  • ProductReviewGet
  • ProductReviewAdd
  • ProductReviewUpdate
  • ProductCategoryGet
  • ProductAdditionalFieldGet
  • ProductAttributeGet
  • StockGet
  • OrderEmailSend
  • OrderStatusGet
  • OrderReturnAdd
  • OrderReturnGet
  • OrderRefundGet
  • CustomerGet
  • CustomerUpdate
  • CustomerEmailSend
  • ShippingTypeGet
  • ShippingCourierGet
  • ProductStyleGet
  • MailingListSubscriptionGet
  • MailingListSubscriptionAdd
  • MailingListSubscriptionUpdate
  • CustomerStatsGet

A subset of these functions will also work only when the user is logged in.

  • OrderEmailSend
  • OrderRefundGet
  • OrderReturnGet
  • OrderReturnAdd
  • CustomerGet
  • CustomerUpdate
  • CustomerEmailSend
  • CustomerStatsGet

For an explanation of these API methods and examples of their usage please view the API v1 documentation.

Example usage

ProductSearch

The below example is a simple request using the ProductSearch API method. In this example we search for all products in the /clothes product category.

Firstly capture the API request to be used and any other variables that will be inside the request_xml. You may add any parameters within the request_xml that are supported in that method, either within the xml itself or via a Smarty variable.

Use the xml_escape function to ensure that the variable is xml safe.

{capture assign=path}/clothes/{/capture}
{capture assign=api_request}<?xml version="1.0" encoding="utf-8"?>
<AuroraRequestEnvelope>
	<Requests>
		<Request>
			<Product>
				<Search>
					<RequestID>1</RequestID>
					<Path>{$path|xml_escape}</Path>
					<DetailLevel>Minimum</DetailLevel>
					<Paging>
						<Limit>20</Limit>
						<Page>1</Page>
					</Paging>
					<OrderBy>2</OrderBy>
				</Search>
			</Product>
		</Request>
	</Requests>
</AuroraRequestEnvelope>
{/capture}

Execute the API request.

{api_request_v1 method=ProductSearch version=1.5 request_xml=$api_request}

Output the response to the screen.

{$api_response_v1|@print_r}

CustomerGet

Requests to the Customer API methods require that the user is logged in. The Customer ID in the xml will be replaced by the logged in User ID.

{capture assign=api_request}<?xml version="1.0" encoding="utf-8"?>
<AuroraRequestEnvelope>
	<Requests>
		<Request>
			<Customer>
        <Get>
        	<RequestID>1</RequestID>
      		<CustomerIDs>
        		<CustomerID>12345</CustomerID>
      		</CustomerIDs>
      		<Limit>1</Limit>
      		<Paging>
        		<Limit>20</Limit>
      		</Paging>
      	</Get>
      </Customer>
		</Request>
	</Requests>
</AuroraRequestEnvelope>
{/capture}

If the <CustomerID> element is not present an error will occur. Any value in <CustomerID> will be replaced by the logged in User ID.

OrderReturnAdd

Request to Order API methods that specify an <OrderID> require the user to be logged in and any Order IDs in the request must belong to the user. If any <OrderID> doesn't exist or doesn't belong to the logged in user, an error will be raised.

{capture assign=api_request}<?xml version="1.0" encoding="utf-8"?>
<AuroraRequestEnvelope>
	<Requests>
		<Request>
			<Order>
      	<Return>
  				<Get tracking="automatic">
  					<OrderIDs>
  						<OrderID>889508</OrderID>
  						<OrderID>889509</OrderID>
  					</OrderIDs>
  					<ReturnIDs>
  						<ReturnID>1</ReturnID>
  						<ReturnID>2</ReturnID>
  					</ReturnIDs>
  					...
  				</Get>
  			</Return>
  		</Order>
		</Request>
	</Requests>
</AuroraRequestEnvelope>
{/capture}