web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Import Item Image?

(1) ShareShare
ReportReport
Posted on by 583

So far I have a Visual Studio project that is able to interact with the OData and SOAP web service endpoints associated with our NAV company. For example, I can query items, customers, vendors, etc. as well as create new records for them.

The one mechanism I am struggling with is uploading a new image to associate with a new item. The OData picture endpoint allows me to set a ContentType property, set an Item property, etc. but the actual Content property appears to be a DataServiceStreamLink datatype that's not assignable (i.e. - likely read-only based on getting an existing object). I exposed the Import Item Pictures - Object ID 348 page in Web Services, but still can't see where I can programmatically import in an image and assign it to any item. Looking online I don't see any working examples so far.

The big picture is that I am looking to import in ~25K items using a custom VS app I'm developing. So I can have more granular control about mapping the various fields. Seeing the CSV import tools inherent in NAV are a bit limiting. Anyone have ideas how to import images to assign to these items? I am well aware of how to stream in an image via its URL, in order to convert into Base64, for example. Just looking for any sort of NAV web services endpoint that will allow me to do something with it!

I have the same question (0)
  • Lars Lohndorf-Larsen Profile Picture
    on at

    Hello, how about this - does that help you:?

    community.dynamics.com/.../how-to-get-picture-from-mediaset-through-standard-apis

    Or this:

    docs.microsoft.com/.../dynamics_picture_update

    In both cases, use API instead of OData (though its kind of the same thing anyway).

  • Greg Kujawa Profile Picture
    583 on at

    Thanks for the feedback! I spent a decent amount of time searching around for the general concept, and ran across some similar examples. In the case of what links you provided, these are for the equivalent of a GET operation (pulling an existing picture) or a PUT operation (updating an existing picture). What I am looking to do is essentially a POST operation --- inserting a new picture into NAV so that I can associate it with an existing item. That's where I'm coming up empty. For example, here's a link to the API Picture endpoint --> https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/resources/dynamics_picture. If you review the sections, there isn't a method to create a new picture.

    For our data conversion, I will need to insert around 25,000 items into NAV. And each most of these items will have up to 4 pictures associated with them.

  • Lars Lohndorf-Larsen Profile Picture
    on at

    I see what you mean. Our documentation only covers GET, PATCH and DELETE:

    Update picture - Business Central | Microsoft Docs

    This small sample shows a create function:

    dynamics365smb-devitpro-pb/dynamics_item_create_picture.md at main · MicrosoftDocs/dynamics365smb-devitpro-pb · GitHub

    (POST https://{businesscentralPrefix}/api/v2.0/companies({companyId})/items({itemId})/picture). I don't know if that, followed by a PATCH could work? If not, let me know and I can research it further.

  • Greg Kujawa Profile Picture
    583 on at

    Thanks for checking more into this! Looking at the GitHub link, there isn't documentation about the actual JSON request body. So I'm not sure if this POST method just adds a link to an existing picture to the item, or actually allows for inserting a new picture to be linked to an existing item. I tagged the GitHub contributor to an Issues post on the project to see if she has additional insight --> https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb/issues/2183 

  • Greg Kujawa Profile Picture
    583 on at

    Also found this circa-2012 article --> www.kauffmann.nl/.../. Which might be worth refactoring into a custom CodeUnit that might work.

  • Verified answer
    Lars Lohndorf-Larsen Profile Picture
    on at

    I got this working, with a "little" help (Thanks Onat and Susanne):

    Pictures are uploaded through PATCH requests. Note that when you do a GET call to My-PC:19048/.../picture you get two links:

    "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 needs to be application/octet-stream, and the request body should be the image itself in binary. Here is a PS sample for my local instance:

    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

    }

    Then run it like this:

    $MyPic = "C:\Pictures\MyDog.png"
    $ItemUrl = 'My-PC:19048/.../pictureContent'
    Upload-File -Url $ItemUrl -SourceFilePath $MyPic

    Official documentation has also been noted to get updated with this. So thank you for asking. Let me know if you have problems getting this to work.

  • Greg Kujawa Profile Picture
    583 on at

    Appreciate the info. Quick question. The PATCH method will _replace_ an existing picture then, correct? What if an item doesn't have any picture associated yet? I'm starting to go down the rabbit hole of CodeUnits and AL, but if there's a way to just publish or update an API endpoint for this that would be huge.

    So in your example above, it appears as if you are hitting a .../picture endpoint to retrieve the proper URI endpoints for a GET or a PATCH. What if that endpoint is hit when there aren't any pictures?

  • Lars Lohndorf-Larsen Profile Picture
    on at

    I think it should work regardless. In my example, I was updating Item 70001 which did not already have any picure. Just to doublecheck I also tested with a new item. First in Postman insert the new item:

    POST My-PC:19048/.../items

    BODY:

               {

               "number": "99000",

               "displayName": "Side Panel"

               }

    HEADER:

    Content-type = application/json

    Then I ran the PS script abvove, and it imported the picture to the new item.

  • Greg Kujawa Profile Picture
    583 on at

    Interesting! What is the full URL path you are using? In the BC 365 Administration app I defined my OData URL prefix as ls-test01:9048/.../beta. When I tried to perform a GET request against ls-test01:9048/.../picture, I received a 404 Resource Not Found response. I also see a different OData URL prefix of ls-test01:9048/.../Company('CRONUS - LS Central') as well. For example, I can perform a GET request of ls-test01:9048/.../Chart_of_Accounts and get back a response. Does it make a difference that we are using an on-prem version of the software?

    *EDIT* guess this forum truncates the full URL links. :-/ 

  • Greg Kujawa Profile Picture
    583 on at

    I took the time to take a crack at it using the Sandbox API for the cloud version. This logic worked fine for retrieving an existing item picture. When I used the same request URI syntax for my on-prem version it failed. And I did verify the company and item ID's were valid, since I could GET their details just fine. Attaching screen shots of both.

    Sandbox-API.jpg   On-Prem-API.jpg

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans