Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Import Item Image?

(1) ShareShare
ReportReport
Posted on by 289

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!

  • Greg Kujawa Profile Picture
    Greg Kujawa 289 on at
    RE: Import Item Image?

    You are correct. There are custom supplementary elements sitting atop BC 365 V19 W1 on-prem. That explains the differences in behavior. I'll provide screen shots of what I experience going through this Picture element in the Item Card.

    Picture.png 

    Link-List.png

    This explains why the PATCH request did work fine in the BC 365 cloud API Sandbox. The new picture I added "stuck," in that I could export it and manage things in the Item Card as expected. Although it appears as if the default BC 365 implementation only allows a single picture to be linked to an item.

    The on-prem implementation I am testing against is provided by LS Retail. And their add-ins allow for multiple pictures to be linked to a single item. The issue appears to be the PATCH request uploads the picture, yet it's not linked to the item if the user drills into the images. And if I manually link multiple pictures to a single item in the BC 365 web client, issuing a GET request to that item-picture-content API endpoint only responds with the primary image (i.e. - Display Order = 0). Will need to defer to our LS Retail VAR once the implementation project is underway.

    Thanks so much for your time and insight!

  • RE: Import Item Image?

    Hello,

    Exactly which drop down do you go to? Here, I only see these actions (BC19):

    pastedimage1641984062205v1.png

    And your lists show "Retail image link" lists, which makes me thing there are some custom tables involved?

  • Greg Kujawa Profile Picture
    Greg Kujawa 289 on at
    RE: Import Item Image?

    Thanks for the links. Both of these appear to cover a GET request for an item picture. To pull the item picture out of NAV in order to send to the client requesting it. I specifically am looking for a method that can take a picture and load it into NAV so that it's associated with an existing item. An item that's newly-created and doesn't have any existing picture linked with it. The thread above pointed to the PATCH API request as a possible solution. While this did appear to load the picture in NAV, it wasn't truly linked with the item. When clicking the Images button from the Picture drop-down in the NAV web client, no Image ID was visible and the picture just disappears. The only way I could see that this PATCH API request works is if an item already has an existing image linked with it. Using BC 365 on-prem V19 W1. When I tried the same operation using the BC 365 API Sandbox "in the cloud" everything worked fine. Screen shot below of that. I think this might be a difference due to how our LS Retail implementation layers atop of BC 365. Since the on-prem generic Cronos company for the default instance handles pictures much as the API Sandbox does. Same Import, Export, Delete, etc. options appear when the Picture drop-down is selected in the Item Card. Just one picture can be worked with at a time, whereas the LS Retail implementation allows for multiple pictures.

    API-Sandbox-Item-Image.jpg

    If there is an AL solution that can publish a specific Codeunit as a web service endpoint, so that I can do this at scale then that would be an option I'd explore. At scale I'm meaning importing in around 25,000 items, each one of them with 3-4 pictures associated with them. I did see some small sample Codeunit routines that could look in a local drive and match up a handful of images with items. With a 1-to-1 ratio where the image filename would have to match the item's ID. That's about it. :(  

  • RockwithNav Profile Picture
    RockwithNav 6,562 on at
    RE: Import Item Image?

    Do you wish Import Items Image via Webservice OR anyway to NAV?

    Via Webservice this can help, have a look

    rockwithnav.wordpress.com/.../

    rockwithnav.wordpress.com/.../

  • Greg Kujawa Profile Picture
    Greg Kujawa 289 on at
    RE: Import Item Image?

    I was easily able to verify the behavior above, but when I chose an item with an existing picture (e.g. - the ATHENS desk sample in Chronos) the new picture took the place of the old one. And I was able to view the assigned Image ID in the Edit List. Screen shot below.

    So unless I'm mistaken, it appears as if this PATCH API request won't actually auto-assign a new Image ID to the new image that's loaded. Based on the premise that the item doesn't already have a picture assigned. Let alone my original quandary in that we have an average of 3-4 images assigned to each item we have stocked in our legacy system.

    ATHENS-Desk-Picture.jpg

  • Greg Kujawa Profile Picture
    Greg Kujawa 289 on at
    RE: Import Item Image?

    I just went back into the BC Administration app, redefined the same exact OData Base URL I had before, restarted the instance, and it works fine now. Very strange, but positive :)

    Here is what I found now that I uploaded a new item to associate with an existing item. 

    • I can view the item image via the ../content GET request.

    PATCH-Item-Image-Content.jpg

    • I can also view the new item image in the BC web client's item card.

    Web-Client-Item-Card.jpg

    • If I click on the Picture dropdown and choose Images, then there is nothing linked with an Image ID. So once I back out of that edit screen the image disappears.

    1376.Retail-Image-Link-List.jpg

    So I'm thinking this PATCH API request will overwrite an existing image that's already associated with an item (i.e. - based on the Image ID). But since we are talking about new items that have no images already associated with them, it's more like a temporary placeholder. Unless I'm missing something to commit the change to the DB somehow.

  • Greg Kujawa Profile Picture
    Greg Kujawa 289 on at
    RE: Import Item Image?

    In the on-prem BC Administration app I had to manually provide the OData Base URL value to be used. So reading up on (somewhat conflicting) documentation I specified h t t p : / / ls-test01:9048 / LSCentral / api / beta / for the value. I tried changing the beta URL segment to v2.0 in the OData Base URL, but after restarting the service the endpoint wasn't providing a response. 

    According to what I see, the on-prem version we are testing out is Version: W1 19.1 (Platform 19.0.31889.32155 + Application 19.1.31886.32186). Most of the online documentation I see refers to the cloud-based version, so there appear to be some differences in terms of what's possible and how it's configured.  

  • RE: Import Item Image?

    The onprem one refers to beta, while the online one is using v2.0. I am not sure this will work for the beta version.

  • Greg Kujawa Profile Picture
    Greg Kujawa 289 on at
    RE: Import Item Image?

    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

  • Greg Kujawa Profile Picture
    Greg Kujawa 289 on at
    RE: Import Item Image?

    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. :-/ 

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,784 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,476 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans