SData 2.0 How to assign relation (for instance email to a person)

SUGGESTED

Hi,

I am able to list emails for a person like this:

→ curl -H "Authorization: Basic $AUTH" "http://192.168.22.198/sdata/crmj/sagecrm2/-/Person('1502')/Email" | jq
{
  "$url": "http://msedgewin10/sdata/crmj/sagecrm2/-/Person('1502')/Email?startindex=1&count=10",
  "$first": "http://msedgewin10/sdata/crmj/sagecrm2/-/Person('1502')/Email?startindex=1&count=10",
  "$last": "http://msedgewin10/sdata/crmj/sagecrm2/-/Person('1502')/Email?startindex=1&count=10",
  "$totalResults": 1,
  "$startIndex": 1,
  "$itemsPerPage": 10,
  "$resources": [
    {
      "$key": 2736,
      "$title": "",
      "$url": "http://msedgewin10/sdata/crmj/sagecrm2/-/Email('2736')",
      "Emai_EmailId": 2736,
      "emai_IntForeignID": null,
      "emai_intlastsyncdate": null,
      "Emai_EmailAddress": "[email protected]",
      "emai_IntId": null,
      "emai_promote": false,
      "Company": {
        "$url": {
          "Association": "http://msedgewin10/sdata/crmj/sagecrm2/-/Email('2736')/Company?startindex=1&count=10"
        }
      },
      "Account": {
        "$url": {
          "Association": "http://msedgewin10/sdata/crmj/sagecrm2/-/Email('2736')/Account?startindex=1&count=10"
        }
      },
      "Person": {
        "$url": {
          "Association": "http://msedgewin10/sdata/crmj/sagecrm2/-/Email('2736')/Person?startindex=1&count=10"
        }
      }
    }
  ]
}

I'm also able to create email like this:

→ curl -H "Authorization: Basic $AUTH" "http://192.168.22.198/sdata/crmj/sagecrm2/-/Email" -X POST -H "Content-Type: application/json;vnd.sage=sdata" -d '{"Emai_EmailAddress":"[email protected]"}'
{"$key":4190,"Emai_EmailAddress":"[email protected]"}

But I don't know how to create email assigned to a person. I tried this:

→ curl -H "Authorization: Basic $AUTH" "http://192.168.22.198/sdata/crmj/sagecrm2/-/Person('1502')/Email" -X POST -H "Content-Type: application/json;vnd.sage=sdata" -d '{"Emai_EmailAddress":"[email protected]"}'
<!doctype html><html lang="en"><head><title>HTTP Status 405 – Method Not Allowed</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 405 – Method Not Allowed</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Request method 'POST' not supported</p><p><b>Description</b> The method received in the request-line is known by the origin server but not supported by the target resource.</p><hr class="line" /><h3>Apache Tomcat/8.5.24</h3></body></html>

As you see it doesn't work. What I'm doing wrong?

Also, is there a way to create person and emails using one API call?

Parents
  • +1
    SUGGESTED

    Hi,

    Note: These request were constructed using the minimum required fields, further field/support method information for the Person endpoint can be found here.

    1. 

    A new Email address can be added to an existing Person record by using a PUT request to the Person endpoint and passing the Email values in the JSON request body, example below:

    PUT - http://{server}/sdata/{installName}j/sagecrm2/-/Person(‘17’)

    Request body:

    {
    "Email": [
    {
    "Emai_EmailAddress": "[email protected]",
    "$type": "Business"
    }
    ]
    }
    

    Response:

    {
        "$key": 17,
        "Email": {
        "$resources": [
        {
            "$key": 3189,
            "Emai_EmailAddress": "[email protected]"
                }
            ]
        }
    }

    Note: You could also use a PATCH request, however, this will set non-populated values (such as emai_deleted in my example) to 0 rather than NULL.

    2. 

    To create a new Person record with an Email address, in the same API request, the Email information can passed as part of the initial POST request to the Person endpoint, see example below:

    POST - http://{server}/sdata/{installName}j/sagecrm2/-/Person

    Request body:

    {
    "Email": [
    {
    "Emai_EmailAddress": "[email protected]",
    "$type": "Business"
    }
    ],
    "Pers_PrimaryAddressId": 25,
    "Pers_FirstName": "John",
    "Pers_LastName": "Smith",
    "Pers_CompanyId": 18
    }

    Reponse:

    {
        "$key": 1779,
        "Pers_PrimaryAddressId": 25,
        "Pers_FirstName": "John",
        "Pers_LastName": "Smith",
        "Pers_CompanyId": 18,
        "Email": {
            "$resources": [
                {
                    "$key": 3190,
                    "Emai_EmailAddress": "[email protected]"
                }
            ]
        }
    }
    

Reply
  • +1
    SUGGESTED

    Hi,

    Note: These request were constructed using the minimum required fields, further field/support method information for the Person endpoint can be found here.

    1. 

    A new Email address can be added to an existing Person record by using a PUT request to the Person endpoint and passing the Email values in the JSON request body, example below:

    PUT - http://{server}/sdata/{installName}j/sagecrm2/-/Person(‘17’)

    Request body:

    {
    "Email": [
    {
    "Emai_EmailAddress": "[email protected]",
    "$type": "Business"
    }
    ]
    }
    

    Response:

    {
        "$key": 17,
        "Email": {
        "$resources": [
        {
            "$key": 3189,
            "Emai_EmailAddress": "[email protected]"
                }
            ]
        }
    }

    Note: You could also use a PATCH request, however, this will set non-populated values (such as emai_deleted in my example) to 0 rather than NULL.

    2. 

    To create a new Person record with an Email address, in the same API request, the Email information can passed as part of the initial POST request to the Person endpoint, see example below:

    POST - http://{server}/sdata/{installName}j/sagecrm2/-/Person

    Request body:

    {
    "Email": [
    {
    "Emai_EmailAddress": "[email protected]",
    "$type": "Business"
    }
    ],
    "Pers_PrimaryAddressId": 25,
    "Pers_FirstName": "John",
    "Pers_LastName": "Smith",
    "Pers_CompanyId": 18
    }

    Reponse:

    {
        "$key": 1779,
        "Pers_PrimaryAddressId": 25,
        "Pers_FirstName": "John",
        "Pers_LastName": "Smith",
        "Pers_CompanyId": 18,
        "Email": {
            "$resources": [
                {
                    "$key": 3190,
                    "Emai_EmailAddress": "[email protected]"
                }
            ]
        }
    }
    

Children
No Data