Skip to main content
Solved

Can we make some web endpoints read-only? And can we do the same for individual fields?

  • 4 October 2022
  • 2 replies
  • 55 views

I’d like to be able to make one of the web endpoints read-only.  Is that possible without going through security/roles?

There are some other web endpoints that I would like to make specific fields read-only as well. Is there a way to do that?  I could make a non-persisted field that mirrors the value of the field I want to display and expose that in the endpoint. I’m wondering if I’ve overlooked something.

 

2 replies

Userlevel 6
Badge +5

Hi @ddunn 

Certainly using Roles to restrict which entities the API user can write would work. Having specific fields read only requires customizing the screen to prevent setting a value. Something like:

 

protected void _(Events.RowUpdating<DAC> e)
{
// If you want to validate only the REST API call
if(Base.IsContractBasedAPI && e.Row.Field != e.NewRow.Field)
{
throw new PXException("ERROR: FIELD READ ONLY") ;
}
}

 

Userlevel 7
Badge +5

I thought that there might be a property that would indicate if the code was running via the Contract API or not.  Thank you!

Reply