The SmartObject OData API v4 supports file and image SmartObject properties.
When you create or update records, you cannot also do file and image operations. You must do file and image operations in separate requests. Because of this, you cannot have file and image properties in your SmartObject marked as Required. This is an OData convention. If you have SmartObjects containing file and image properties marked as Required, you must first make them optional before being able to create or update records containing files and/or images.
When you load/create an entity in OData you receive a response like the following:
Copy
1
2
3
4
5
6
7
8
9
10
11
{
"ID": 1,
"FirstName": "Andre",
"LastName": "Pretorius",
"HireDate": "2020-10-14T00:00:00Z",
"DepartmentCode": 1,
"Joblevel": "Senior ",
"EmployeeImage@odata.mediaReadLink": "https://**********.com/api/odatav4/resources/EmployeeSample(1)/EmployeeImage",
"MyFile@odata.mediaReadLink": "https://**********.com/api/odatav4/resources/EmployeeSample(1)/MyFile"
}
Use the odata.mediaReadLink key's value (the URI) to view or download the file or image with the HTTP GET method. Also, use the same link to PUT a file or image when doing a Save or Update. The URI to use is like the Sample response shown above: "https://*********.com/api/odatav4/resources/EmployeeSample(1)/EmployeeImage". Yours will be different:
https://[Domain]/api/odatav4/resources/[entity name]([primary key value])/[property name]?method=Save
-
Entity name: the name of the entity you want to interact with.
-
Primary key value: the value of the primary key for the record in the SmartObject associated with the entity name. This is usually the ID field of the record.
-
Property name: the name of the property in the SmartObject's record you are interacting with.
In the SmartObject, the property’s data type is either Image or File.
Passing a file or image
When you call the endpoint to create or update a file or image, use the Content-Type header of application/json and pass the following structure in the body of your request:
Copy
1
2
3
4
5
{
"fileName":"[filename]",
"content":"[base64-encoded file or image]"
}
Remember you can only add or update a file or image to SmartObject record that already exists. You cannot create a new record that includes a file or image.
This image shows an example in Postman where a file named Martha.jpg is added to a record with the ID of 1, in a SmartObject called EmployeeSample, with a property called EmployeeImage. The Method used to add the image is Save. All images and files added to SmartObjects must be base 64-encoded and passed in the content key.
The URI for a file or image is different from the URI for the entity operations. For files and images, replace /v4/ with /resources/.