Accessing Workorder Image json

burdeensjewelreyburdeensjewelrey Member Posts: 14
edited September 23 in Development

We are working to pull the the json for workorder images in order to add the images to our receipts like we have had with previous POS systems. We have successfully pulled the images for sales by using https://us.merchantos.com/API/Account/(acountID)/Item/{{ Line.Item.itemID }}/Image.json but I seem to be unable to find the image json for workorders. We have pulled https://us.merchantos.com/API/Account/(acountID)/Workorder/{{ Workorder.workorderID }}.json which accesses the json information about the workorder but we cannot get further to find an image.


The only other conversation I have found about workorder images was a post back in 2019 but it looks like the writing for the request is no longer in the body of the comment, though the comment lays out where to go once you are able to get the image json. Very furstating!

6 comments

  • paul1_apaul1_a Member, Moderator, Lightspeed Staff Posts: 72 moderator
    edited September 27

    Hey,

    To obtain the image of a workorder, you need to load the Images relation. Here's the request:

    /API/Account/{ accountID }/Workorder/{workorderID}.json?load_relations=["Images"]

    Thanks

  • burdeensjewelreyburdeensjewelrey Member Posts: 14
    edited September 27

    @paul1_a

    Paul,

    Thank you for your response. I did not know about the load relations option.

    our code is now:

    <script>


    (async() => {


    const request = await fetch('https://us.merchantos.com/API/Account/{ accountID }/Workorder/{workorderID}.json?load_relations=["Images"]', {credentials:"same-origin"});


    const response = await request.json();


    if(Array.isArray(response.Image)){


    document.getElementById("{{workorderID }}").src = response.Image[0].baseImageURL + response.Image[0].publicID + ".png";


    } else {


    document.getElementById("{{ workorderID }}").src = response.Image.baseImageURL + response.Image.publicID + ".png";


    }


    })()


    </script>


    When exciting we receive this error. It loaded the {workorderID} once with the work order value, but now is just outputting "{workorderID}"

  • burdeensjewelreyburdeensjewelrey Member Posts: 14

    can't edit a second time. I was able to change it to {{workorder.workorderID}} to get it to spit out the number. That said it does not build an src still.

  • paul1_apaul1_a Member, Moderator, Lightspeed Staff Posts: 72 moderator

    Try using another method such as Postman to test the request and get it working and then try inserting it in your code. I tested the request I posted and I can confirm it is working.

    Let me know if you get it working!

  • burdeensjewelreyburdeensjewelrey Member Posts: 14

    I figured it out. Thank you so much this has been huge for us.


    for anyone from the future looking for this the code is below:

    <script>


    (async() => {


    const request = await fetch('https://us.merchantos.com/API/Account/{store ID}/Workorder/{{ Workorder.workorderID }}.json?load_relations=["Images"]', {credentials:"same-origin"});


    const response = await request.json();


    if(Array.isArray(response.Image)){


    document.getElementById("{{ Workorder.workorderID }}").src = response.Workorder[0].Images[0].WorkorderImage[0].baseImageURL + response.Workorder[0].Images[0].WorkorderImage[0].publicID + ".png";


    } else {


    document.getElementById("{{ Workorder.workorderID }}").src = response.Workorder.Images.WorkorderImage.baseImageURL + response.Workorder.Images.WorkorderImage.publicID + ".png";


    }


    })()


    </script>



    <!-- safetest -->

    <p>

    <img id="{{ Workorder.workorderID }}" width="150px" ></p>

  • paul1_apaul1_a Member, Moderator, Lightspeed Staff Posts: 72 moderator

    Hey,

    No problem! I'm glad it worked out for you!

    Best,

    Paul

Sign In or Register to comment.