Chilkat Online Tools

Android / Salesforce Platform APIs / Request Product Information (No Bundles)

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();
    boolean success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "productContexts": [
    //     {
    //       "product2Id": "{{ClassTrainingProduct}}",
    //       "productSellingModelId": "{{OneTimePSM}}"
    //     },
    //     {
    //       "product2Id": "{{VirtualRouterProduct}}"
    //     }
    //   ],
    //   "fields": [
    //     "id",
    //     "name",
    //     "IsActive",
    //     "ProductCode"
    //   ],
    //   "retrievalType": "ExcludeChildComponents"
    // }

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("productContexts[0].product2Id","{{ClassTrainingProduct}}");
    json.UpdateString("productContexts[0].productSellingModelId","{{OneTimePSM}}");
    json.UpdateString("productContexts[1].product2Id","{{VirtualRouterProduct}}");
    json.UpdateString("fields[0]","id");
    json.UpdateString("fields[1]","name");
    json.UpdateString("fields[2]","IsActive");
    json.UpdateString("fields[3]","ProductCode");
    json.UpdateString("retrievalType","ExcludeChildComponents");

    // Adds the "Authorization: Bearer <access_token>" header.
    http.put_AuthToken("<access_token>");
    http.SetRequestHeader("Content-Type","application/json");

    CkHttpResponse resp = http.PostJson3("https://domain.com/services/data/v{{version}}/commerce/catalog-products/actions/get-products","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, String.valueOf(resp.get_StatusCode()));
    Log.i(TAG, resp.bodyStr());


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
  "productContexts": [
    {
      "product2Id": "{{ClassTrainingProduct}}",
      "productSellingModelId": "{{OneTimePSM}}"
    },
    {
      "product2Id": "{{VirtualRouterProduct}}"  
    }
  ],
  "fields": [
    "id",
    "name",
    "IsActive",
    "ProductCode"
  ],
  "retrievalType": "ExcludeChildComponents"
}'
https://domain.com/services/data/v{{version}}/commerce/catalog-products/actions/get-products

Postman Collection Item JSON

{
  "name": "Request Product Information (No Bundles)",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"productContexts\": [\n    {\n      \"product2Id\": \"{{ClassTrainingProduct}}\",\n      \"productSellingModelId\": \"{{OneTimePSM}}\"\n    },\n    {\n      \"product2Id\": \"{{VirtualRouterProduct}}\"  \n    }\n  ],\n  \"fields\": [\n    \"id\",\n    \"name\",\n    \"IsActive\",\n    \"ProductCode\"\n  ],\n  \"retrievalType\": \"ExcludeChildComponents\"\n}"
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/commerce/catalog-products/actions/get-products",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "commerce",
        "catalog-products",
        "actions",
        "get-products"
      ]
    },
    "description": "Request information for two products that aren't bundles. For the first product, request only the information about the specified product selling model. For the second product, request information about all related product selling models.\n\nSee [Request Product Information](https://desktop.postman.com/?desktopVersion=10.13.6&webVersion=10.13.7-ui-230522-1730&userId=10709048&teamId=0)."
  },
  "response": [
  ]
}