Generic Inquiry Access Through OData: To Retrieve Data by Using a Custom Generic Inquiry

This activity will walk you through the process of retrieving a list of records by using a custom generic inquiry through the OData interface.

Story

In the business intelligence (BI) application of the MyStore company, a marketing manager should be able to view analytics for the distribution of existing customers by geographical state. To display to the marketing manager the information about the customers, you need to retrieve from MYOB Acumatica the information about the customers, their contacts, and their addresses. The data of these customers has been entered on the Customers (AR303000) form in MYOB Acumatica. You want to use the generic inquiry–based OData interface to obtain this data.

Through the generic inquiry–based OData interface, you cannot export records directly from a data entry form, such as Customers. Thus, before the export, you have to configure a generic inquiry that retrieves the needed data from MYOB Acumatica. In this activity, you will use the Customer Contacts (ARGI0015) custom generic inquiry, which has been preconfigured for this activity.

Process Overview

You will verify that the Customer Contacts (ARGI0015) generic inquiry is exposed through OData, review the results of the generic inquiry in MYOB Acumatica, and obtain the results of the generic inquiry through the OData interface.

System Preparation

Before you begin performing the steps of this activity, do the following:

  1. Deploy an instance of MYOB Acumatica with the name MyStoreInstance and a tenant that has the MyStore name and contains the T100 data.
  2. Make sure the Postman application is installed on your computer. To download and install Postman, follow the instructions on https://www.postman.com/downloads/.
  3. Complete the following prerequisite activity: Generic Inquiry Access Through OData: To Sign In to MYOB Acumatica and Retrieve the Metadata.
  4. If you have created a Postman collection with the basic authentication configured, add a new request to the collection and configure the request to inherit the authorization type from the parent collection.

Step 1: Reviewing the Generic Inquiry

To provide the list of customers to the BI application, you need to retrieve the following values from MYOB Acumatica, which are listed with the corresponding locations on the Customers (AR303000) form:

  • Customer ID (the Customer ID box of the Summary area)
  • Account name (the Account Name box of the Account Info section on the General tab)
  • Customer class (the Customer Class box of the Summary area)
  • Details of the main contact of the customer (the Additional Account Info section of the General tab):
    • Email address (the Account Email box)
    • Primary phone number (the Business 1 box)
  • Customer address (the Account Address section of the General tab):
    • City (the City box)
    • State (the State box)
    • Postal code (the Postal Code box)
    • Address line (the Address Line 1 and Address Line 2 boxes)

These elements are shown in the following screenshot.

Figure 1. Elements on the Customers form


The Customer Contacts (ARGI0015) custom generic inquiry, which you will use for this activity, retrieves the values of these elements. The generic inquiry has no parameters and is based on the PX.Objects.AR.Customer, PX.Objects.CR.Address, and PX.Objects.CR.Contact data access classes. To review this generic inquiry and make sure it includes the needed elements, do the following:

  1. In the Summary area of the Generic Inquiry (SM208000) form, select the inquiry with the Customer Contacts title.
  2. Make sure the Expose via OData check box is selected for this generic inquiry. This means that the generic inquiry results are available through OData.
  3. On the form toolbar, click View Inquiry to review the resulting generic inquiry form.

Step 2: Retrieving the List of Customers Through OData

To retrieve the list of customers with contacts through the generic inquiry–based OData interface, do the following:

  1. In the Postman collection, add a request with the following settings:
    • HTTP method: GET
    • URL: http://localhost/MyStoreInstance/t/MyStore/api/odata/gi/Customer Contacts
  2. Send the request. If the request is successful, its response contains the 200 OK status code. The following code example shows a fragment of the response body.
    {
      {
      "@odata.context": 
        "http://localhost/MyStoreInstance/t/MyStore/api/odata/gi/$metadata#Customer%20Contacts",
      "value": [
        {
          "CustomerID": "C000000001",
          "CustomerName": "Jersey Central Office Equip",
          "CustomerClass": "DEFAULT",
          "Email": "jersey-equip@mail.con",
          "Phone1": "+1 (777) 283-0414",
          "City": "Johannesburg",
          "State": null,
          "PostalCode": null,
          "AddressLine1": "1 De Villiers & Harrison St, 11-th Flr.",
          "AddressLine2": null,
          "ContactID": 5764,
          "AddressID": 5759
        },
        ...
      ]
    }
  3. Save the request.