Create item picture
Creates the picture of the item in Business Central.
HTTP request
Replace the URL prefix for Business Central depending on environment following the guideline.
POST businesscentralPrefix/companies({companyId})/items({itemId})/picture
Request headers
Header | Value |
---|---|
Authorization | Bearer {token}. Required. |
Content-Type | application/json |
Request body
In the request body, supply a JSON representation of items object.
Response
If successful, this method returns 201 Created
response code and a item object in the response body.
Remarks
You will see two links in the response, pictureContent@odata.mediaEditLink
and pictureContent@odata.mediaReadLink
. Use these by making a GET
request to download the picture, or making a PATCH
request to upload a new picture.
Content-Type
in the request header must be application/octet-stream
and the request body should be the image itself in binary format.
On a local instance, using PowerShell you can then do as in the following example:
function Upload-File
(
[string] $Etag = '*',
[string] $Url,
[string] $SourceFilePath
)
{
$headers = @{"If-Match"=$Etag}
#Win auth
#Invoke-RestMethod -Uri $Url -Method Patch -InFile $SourceFilePath -Headers $headers -ContentType "application/octet-stream" -UseDefaultCredentials
#NavUserPwd
$Credentials = Get-Credential
Invoke-RestMethod -Uri $Url -Method Patch -InFile $SourceFilePath -Headers $headers -ContentType "application/octet-stream" -Credential $Credentials
}
And then run the function as follows:
$MyPic = "C:\Pictures\MyDog.png"
$ItemUrl = 'My-PC:19048/.../pictureContent'
Upload-File -Url $ItemUrl -SourceFilePath $MyPic
Example
Request
Here is an example of a request.
Note
The response object shown here may be truncated for brevity. All of the properties will be returned from an actual call.
POST https://{businesscentralPrefix}/api/v2.0/companies({companyId})/items({itemId})/picture
Related information
Tips for working with the APIs
Item
Get item defaultDimensions
Update item defaultDimensions
Delete item defaultDimensions