Skip to main content

Data Source

Follow the instructions below to create a new data flow that ingests data from a Magento API source in Nexla.
magentograph_api.png

Magento API

Create a New Data Flow

  1. To create a new data flow, navigate to the Integrate section, and click the New Data Flow button. Then, select the desired flow type from the list, and click the Create button.

  2. Select the Magento API connector tile from the list of available connectors. Then, select the credential that will be used to connect to the Magento instance, and click Next; or, create a new Magento API credential for use in this flow.

  3. In Nexla, Magento API data sources can be created using pre-built endpoint templates, which expedite source setup for common Magento GraphQL queries. Each template is designed specifically for the corresponding Magento GraphQL query type, making source configuration easy and efficient.
    • To configure this source using a template, follow the instructions in Configure Using a Template.

    Magento API sources can also be configured manually, allowing you to execute custom GraphQL queries not included in the pre-built templates or apply further customizations to exactly suit your needs.
    • To configure this source manually, follow the instructions in Configure Manually.

Configure Using a Template

Nexla provides pre-built templates that can be used to rapidly configure data sources to execute common Magento GraphQL queries. Each template is designed specifically for the corresponding Magento GraphQL query type, making data source setup easy and efficient.

Endpoint Settings

  • Select the endpoint from which this source will fetch data from the Endpoint pulldown menu. Available endpoint templates are listed in the expandable boxes below. Click on an endpoint to see more information about it and how to configure your data source for this endpoint.

    Query One Page of Data

    This endpoint template executes a GraphQL query that fetches a single page of data from your Magento instance. Use this template when you need to retrieve a fixed set of data that doesn't require pagination, such as category information, product details for a specific SKU, or customer information for a specific ID.

    • Enter your GraphQL query in the Query field. This should be a valid Magento GraphQL query that retrieves the data you need. The query should follow Magento GraphQL syntax and reference the appropriate Magento schema fields. For example, to retrieve categories, use: { categories { items { id name } } }. The query is sent as a POST request to the Magento GraphQL endpoint (/graphql) with the query in the request body.
    • Enter the JSONPath expression in the JSONPath to Data in Response field to specify which part of the API response should be treated as the relevant data by Nexla. This JSONPath expression should point to the array of items in the GraphQL response. For example, if your query returns categories, use $.data.categories.items[*] to extract all category items from the response. The JSONPath expression determines which data will be extracted and processed by Nexla.

    This template is designed for queries that return a single page of results. If your query returns paginated data, use the "Query Paginated Data" template instead. The GraphQL query must be valid according to the Magento GraphQL schema. You can reference the Magento GraphQL queries documentation for available queries and schema information.

    The JSONPath expression must correctly reference the structure of your GraphQL response. GraphQL responses typically have a data property containing the query results. Ensure your JSONPath expression matches the structure returned by your specific query.

    Query Paginated Data

    This endpoint template executes a GraphQL query that fetches multiple pages of data from your Magento instance using pagination. Use this template when you need to retrieve large datasets that span multiple pages, such as all products, all orders, or all customers. The template automatically handles pagination by incrementing the page number for subsequent requests.

    • Enter your GraphQL query in the Query field. This should be a valid Magento GraphQL query that includes pagination variables. The query must include variables for page number and page size that will be used for pagination. For example, to retrieve paginated products, use: query Products ($currentPage: Int $pageSize: Int){ products(filter:{} pageSize: $pageSize, currentPage: $currentPage){ items{ id name sku } total_count page_info {page_size current_page total_pages}}}. The query is sent as a POST request to the Magento GraphQL endpoint (/graphql) with the query and variables in the request body.
    • Enter the JSONPath expression in the JSONPath to Data in Response field to specify which part of the API response should be treated as the relevant data by Nexla. This JSONPath expression should point to the array of items in the GraphQL response. For example, if your query returns products, use $.data.products.items[*] to extract all product items from the response. The JSONPath expression determines which data will be extracted and processed by Nexla for each page.
    • Enter the variable name for the page number in the Query Variable for Page Number field. This should match the variable name used in your GraphQL query for pagination. For example, if your query uses $currentPage, enter currentPage in this field. Nexla will automatically increment this value to fetch subsequent pages of data.
    • Enter the starting page number in the Start from Page Number field. This is the initial page number that Nexla will use when fetching data. Typically, this should be set to 1 to start from the first page. Nexla will automatically increment this value for subsequent pages.
    • Enter the variable name for the page size in the Query Variable for Page Size field. This should match the variable name used in your GraphQL query for specifying the number of items per page. For example, if your query uses $pageSize, enter pageSize in this field.
    • Enter the number of items to fetch per page in the Number of items per page field. This determines how many items will be retrieved in each API request. A larger page size reduces the number of API calls but may increase response time. A smaller page size increases the number of API calls but may improve response time. Choose a value that balances performance with API rate limits.

    This template automatically handles pagination by incrementing the page number for each subsequent request. Ensure your GraphQL query includes pagination variables and that the variable names match the values you enter in the configuration fields. The query must return pagination metadata (such as total_count and page_info) to enable proper pagination handling.

    The GraphQL query must be valid according to the Magento GraphQL schema and must include pagination variables. You can reference the Magento GraphQL queries documentation for available queries and schema information. The JSONPath expression must correctly reference the structure of your GraphQL response, typically pointing to the items array within the data property.

    Consider your API rate limits when setting the page size. Larger page sizes reduce the number of API calls but may take longer to process. Smaller page sizes increase the number of API calls but may be more responsive. Monitor your API usage to optimize the page size for your specific use case.

Endpoint Testing

Once the selected endpoint template has been configured, Nexla can retrieve a sample of the data that will be fetched according to the current settings. This allows users to verify that the source is configured correctly before saving.

  • To test the current endpoint configuration, click the Test button to the right of the endpoint selection menu. Sample data will be fetched & displayed in the Endpoint Test Result panel on the right.

  • If the sample data is not as expected, review the selected endpoint and associated settings, and make any necessary adjustments. Then, click the Test button again, and check the sample data to ensure that the correct information is displayed.

Configure Manually

Magento API data sources can be manually configured to execute custom GraphQL queries not covered by pre-built templates. Manual configuration provides maximum flexibility for accessing custom queries or when you need advanced GraphQL query configurations.

With manual configuration, you can also create more complex Magento API sources, such as sources that use multiple GraphQL queries or sources that require custom variables or fragments.

API Method

  1. To manually configure this source, select the Advanced tab at the top of the configuration screen.

  2. Select the API method that will be used for calls to the Magento GraphQL API from the Method pulldown menu. Magento GraphQL API uses POST method for all queries, as GraphQL queries are sent in the request body.

API Endpoint URL

  1. Enter the URL of the Magento GraphQL API endpoint in the Set API URL field. This should be the complete URL to your Magento GraphQL endpoint, typically {magento_server_url}/graphql where {magento_server_url} is your Magento server URL configured in the credential (e.g., https://yourstore.com/graphql).

Ensure the API endpoint URL is correct and accessible with your current credentials. The Magento GraphQL endpoint is typically located at /graphql relative to your Magento server URL. You can test the endpoint using the Test button after configuring the URL.

Request Body

  1. Configure the request body that will be sent to the Magento GraphQL API. The request body should contain your GraphQL query in JSON format. The request body format is: {"query": "{ your_graphql_query }"} for simple queries, or {"query": "{ your_graphql_query }", "variables": { "variable_name": "variable_value" }} for queries with variables.

The request body must be valid JSON and must include a query property containing your GraphQL query. If your query uses variables, include a variables property with the variable values. The GraphQL query must be valid according to the Magento GraphQL schema. You can reference the Magento GraphQL queries documentation for available queries and schema information.

Response Data Path

  1. Enter the JSONPath expression in the Response Data Path field to specify which part of the API response should be treated as the relevant data by Nexla. This JSONPath expression should point to the array of items in the GraphQL response. For example, if your query returns products, use $.data.products.items[*] to extract all product items from the response.

The JSONPath expression must correctly reference the structure of your GraphQL response. GraphQL responses typically have a data property containing the query results. Ensure your JSONPath expression matches the structure returned by your specific query. The JSONPath expression determines which data will be extracted and processed by Nexla.

Pagination (if applicable)

  1. If your GraphQL query supports pagination, configure the pagination settings in the Pagination section. Select the pagination type that matches your Magento GraphQL query's pagination mechanism. Magento GraphQL typically uses page-based pagination with variables for currentPage and pageSize.

  2. Configure the pagination parameters based on your selected pagination type. For page-based pagination, specify the page number parameter name, starting page number, page size parameter name, and page size value.

Save the Data Source

  1. Once all of the relevant steps in the above sections have been completed, click the Next button to proceed with the rest of the data flow configuration, or click Save to save the data source configuration for later use.