Salesforce Commerce Cloud OCAPI and Hooks


salesforce commerce cloud
      
          {
  "_v":"19.10",
  "clients":
  [
    {
      "client_id":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "resources":
      [
        {
          "resource_id":"/customers",
          "methods":["post"],
          "read_attributes":"(**)",
          "write_attributes":"(**)"
        },
       {
          "resource_id":"/customers/auth",
          "methods":["post"],
          "read_attributes":"(**)",
          "write_attributes":"(**)"
        },
      {
          "resource_id":"/customers/{customer_id}/addresses/{address_name}",
          "methods":["get","patch"],
          "read_attributes":"(**)",
          "write_attributes":"(**)"
        }

      ]
    }
  ]
}
        
      
          {
   "hooks": "./cartridge/scripts/hooks.json"
}

hooks.json
{
    "hooks": [
        {
            "name": "dw.ocapi.shop.customer.address.afterPATCH",
            "script": "./cartridge/scripts/hooks/addressAfterPatch"
        }
    ]
}
        
      
          'use strict';

const Status = require('dw/system/Status');
const Transaction = require('dw/system/Transaction');

exports.afterPATCH = function (customer, addressName, customerAddress) {

    Transaction.wrap(function () {
        customerAddress.title = 'HOOK modified Title';
    });

    return new Status(Status.OK);
}
        
      
          {
  "_v":"19.10",
  "clients":
  [
    {
      "client_id":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "resources":
      [
        {
          "resource_id":"/customer_lists/{list_id}/customers/{customer_no}",
          "methods":["patch"],
          "read_attributes":"(**)",
          "write_attributes":"(**)"
        }
      ]
    }
  ]
}
        
blog author

Srđan Đukić

Salesforce Commerce Cloud Developer