Contracts API

Hello! I write a lot of scripts for our team to create automations for repetitive workflows in Service Desk. Looking over the doc at apidoc.samanage.com, I'm trying to UPDATE an item on a contract. Evidently I need the item ID, which is not to be found via API when creating a new one, retreiving the current contract information, or anywhere online. Am I missing something?

  • Hi Josh, if you're not receiving a response payload containing the ID after creating a contract, it usually means the API endpoint that you're using is incorrect. Most often, the issue is using https://api.samanage.com/contracts instead of https://api.samanage.com/contracts.json 

    If that isn't the issue, you can post an example payload that you're sending and I'd be happy to take a look!

  • I appreciate your time!

    So creating the Contract works, and creating new Items on the contract works. However I cannot get the ID of current Items so I can update them, and creating a new Item does NOT give me the ID of the Item. I have to, evidently, have the ID of the item except it's never revealed.

    I use powershell, so bear with me if you don't. The following codeblock returns the Contract as exptected, but Items have no ID listed.

    $URL = 'https://api.samanage.com/contracts/{CONTRACTID}.xml'
    $Response = Invoke-RestMethod $URL -Method 'GET' -Headers $SAMHeaders

    The following code creates an item on the same contract, as expected, but does NOT return an ID.

    $CreateURL = "https://api.samanage.com/contracts/{CONTRACTID}/items"
    $CreateBody = '{
        "item": {
        "name": "Test Item Name",
        "version": "1",
        "qty": "1"
        }
    }'
    $CreateResponse = Invoke-RestMethod $CreateURL -Method 'POST' -Headers $SAMHeaders -Body $CreateBody

    With no way to retrieve the ID of the Items, I can't use the following command to update them.

    $UpdateURL = "https://api.samanage.com/contracts/{CONTRACTID}/items/{ITEMID}"
    $UpdateBody = '{
        "item": {
          "version": "1.5",
          "qty": "10"
        }
      }'
    $UpdateResponse = Invoke-RestMethod $UpdateURL -Method 'PUT' -Headers $SAMHeaders -Body $UpdateBody

  • FYI, they finally got back to me with this response:

    Hi there, as I have checked with our level two team there was a mistake from the API documentation as there has never been the ability to update contract items as they really do not have an ID.

    That sucks, but it is what it is. It must be something down the pipeline they haven't fully implemented yet.