Enterprise Data Catalog REST API Reference > Use Cases > Update a Custom Attribute and Custom Reference Attribute for an Object
  

Update a Custom Attribute and Custom Reference Attribute for an Object

The sample use case is to update a custom attribute and a custom reference attribute for an object. To update the object, you fetch the object and create a request object from the response. Next, configure the facts and send the request.
You can use the REST API to retrieve the information in one of the following ways:
Using Java code and the Bundled Java Client
public void setContactAndRegion(String contactAttrId, String regionAttrId) {
try {
// Fetch the object you want to update
ApiResponse<ObjectResponse> objApiResponse = this.api.catalogDataObjectsIdGetWithHttpInfo("resource://obj1");

String etag = objApiResponse.getHeaders().get("ETag").get(0);
ObjectResponse obj = objApiResponse.getData();

// Always create a request object from response.
ObjectIdRequest request = ObjectAdapter.INSTANCE.copyIntoObjectIdRequest(obj);

// Set the fact values.
// Since the contact is a reference attribute, set the projectedFrom field to the id of the object that you are referencing instead of the value
request.getFacts().add(new FactRequest().attributeId(contactAttrId).projectedFrom("resource://User1"));

// Region is a string, so set the value directly
request.getFacts().add(new FactRequest().attributeId(regionAttrId).value("North East"));

// Send the request, etag is required to ensure no concurrent modifications are made to the object.
this.api.catalogDataObjectsIdPut("resource://obj1", request, etag);
} catch (ApiException e) {}

}

}
Using Curl
Fetch the object JSON to has to be updated. Also, read the ETag header returned in the response.
curl -X GET --header "Accept: application/json" --header "Content-Type: application/json" "http://localhost:13000/2/catalog/data/objects/resource~3a~~2f~~2f~obj1"
From the returned JSON, remove all the read only facts and links. Do not remove any custom facts and links or they get deleted. Add the updated facts to JSON. Send the JSON along with ETag using curl command.

curl -X PUT --header "If-Match: 0f7ddbbfc724c49364bf632aa73a906b" --header "Accept: application/json" --header "Content-Type: application/json" -d "{
\"facts\": [
{
\"attributeId\": \"com.infa.appmodels.ldm.LDM_c952777e_e2bd_4dfe_871c_80fa1a51087f\",
\"projectedFrom\": \"resource://User1\"
},
{
\"attributeId\": \"com.infa.appmodels.ldm.LDM_de552671_6939_4f13_b68c_7b4f8d5e4c80\",
\"value\": \"North East\"
}
],
\"srcLinks\": [],
\"businessTerms\": []
}" "http://localhost:13000/2/catalog/data/objects/resource~3a~~2f~~2f~obj1"