Skip to main content
Version: 3.x

Axios instances

This reference explains how to create `axios` instances to interact with Magento's API.

makeAdminClientFromRequest

The makeAdminClientFromRequest function creates an axios instance that can be used to interact with Magento's API as an Admin.

makeAdminClientFromRequest(request);

Arguments:

NameTypeDescription
requestRequestv2 compatible request object

Example:

import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import { makeAdminClientFromRequest } from "@front-commerce/magento1/axios";

export default createGraphQLRuntime({
contextEnhancer: ({ req }) => {
const adminAxiosInstance = makeAdminClientFromRequest(req);

// rest of logic
},
});

makeAuthServiceFromRequest

The makeAuthServiceFromRequest function creates a service that expose related session information.

makeAuthServiceFromRequest(request);

Arguments:

NameTypeDescription
requestRequestv2 compatible request object

Example:

import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import { makeAuthServiceFromRequest } from "@front-commerce/magento1/axios";

export default createGraphQLRuntime({
contextEnhancer: ({ req }) => {
const authService = makeAuthServiceFromRequest(req);

// rest of logic
},
});

makeUserClientFromRequest

The makeUserClientFromRequest function creates an axios instance that can be used to interact with Magento's API as a customer.

makeUserClientFromRequest(request);

Arguments:

NameTypeDescription
requestRequestv2 compatible request object

Example:

import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import { makeUserClientFromRequest } from "@front-commerce/magento1/axios";

export default createGraphQLRuntime({
contextEnhancer: ({ req }) => {
const axiosInstance = makeUserClientFromRequest(req);

// rest of logic
},
});

makeCartUrlBuilderFromRequest

The makeCartUrlBuilderFromRequest function creates a CartUrlBuilder instance.

makeCartUrlBuilderFromRequest(request);

Arguments:

NameTypeDescription
requestRequestv2 compatible request object

Example:

import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import { makeCartUrlBuilderFromRequest } from "@front-commerce/magento1/axios";

export default createGraphQLRuntime({
contextEnhancer: ({ req }) => {
const cartUrlBuilder = makeCartUrlBuilderFromRequest(req);

// rest of logic
},
});

makeFilterParams

The makeFilterParams function creates a filter for Magento API request to filter on properties.

makeFilterParams(filters, initialFilters);

Arguments:

NameTypeDescription
filtersobject[]Array of filters
initialFiltersobject[]Initial filters computed by other means

Example:

import { makeFilterParams } from "@front-commerce/magento1/axios";

const params = makeFilterParams([{ code: "is_filterable", value: "1" }], {
initialParams: { limit: 0 },
});

makeSkuFilters

The makeSkuFilters function creates a filter for Magento API request to filter on SKU.

makeSkuFilters(skus);

Arguments:

NameTypeDescription
skusstring[]Array of SKU
codestringFilter code (default to sku)

Example:

import { makeSkuFilters } from "@front-commerce/magento1/axios";

const filter = makeSkuFilters(["sku1", "sku2", "sku3"]);