Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Alanna Larson
    REST API: Creating a Custom Object With a RelationshipAnswered
    Topic posted October 18, 2019 by Alanna LarsonBlue Ribbon: 750+ Points, tagged REST 
    15 Views, 2 Comments
    Title:
    REST API: Creating a Custom Object With a Relationship
    Content:

    Hi,

    I would like to create a custom object using the REST API that has a relationship with the incident ID field. I am able to create custom objects that don't have a relationship but I'm having trouble figuring out how to represent the incident ID in the body of the request when there is a relationship. Attached image shows the details for a much-simplified version of the object I'm dealing with. 

    When I try to represent the incident ID value with a simple int or string I get back a 400 error: " Invalid type specified for property SimpleThread.incidentID". When I GET a thread I receive a list of links for the incidentID field. I included the code showing what is returned below. I tried using something similar to represent the incident when I create the object but that also throws up errors.

    Basically I am looking for the content that should replace the ??? in the body of my REST call.

    {
        "incidentID": ???,
        "text": "I'm the text content",
    }


    Thanks!

    Image:
    Code Snippet:

    Best Comment

    Robert Surujbhan

    Hi Alana!  Here is the correct format for the body.  Since your "incidentID" field represents the object relationship for an Incident, you need to pass the ID as a sub-object.

    If 12345 were the Incident ID:

    {
        "incidentID": {
            "id": 12345
        },
        "text": "I am the text content!"
    }
    

    Alternatively, in the sub-array for incidentID, you could also use the Incident Reference Number via the lookupName property:

    {
        "incidentID": {
            "lookupName": "191015-000001"
        },
        "text": "I am the text content!"
    }
    

    Comment

     

    • Robert Surujbhan

      Hi Alana!  Here is the correct format for the body.  Since your "incidentID" field represents the object relationship for an Incident, you need to pass the ID as a sub-object.

      If 12345 were the Incident ID:

      {
          "incidentID": {
              "id": 12345
          },
          "text": "I am the text content!"
      }
      

      Alternatively, in the sub-array for incidentID, you could also use the Incident Reference Number via the lookupName property:

      {
          "incidentID": {
              "lookupName": "191015-000001"
          },
          "text": "I am the text content!"
      }