<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Update relationship via REST API</title><link>https://www.aras.com/community/f/development/3862/update-relationship-via-rest-api</link><description>I&amp;#39;m trying to change the file that a Document/Document File relationship is using with the REST API. According to the documentation:
 In order to set a value for an Item property, the client must send a PUT request to the Item property
reference:
 PUT</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Update relationship via REST API</title><link>https://www.aras.com/community/thread/1901?ContentTypeID=1</link><pubDate>Mon, 27 Aug 2018 13:03:40 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:bef0bf3a-efc9-4a8d-a324-4db31d66cb1b</guid><dc:creator>mmoales</dc:creator><description>Hi Chris,

That worked perfect for the delete. To create the relationship, I am first locking the Document, creating the Document File relationship, querying the Document for its new ID, and then unlocking the Document:
&lt;pre&gt;def attach_file(s, keyed_name, fileId, item_id, item_type=&amp;#39;Document&amp;#39;, rel_type=&amp;#39;Document File&amp;#39;):
    # lock
    data = { &amp;#39;@aras.action&amp;#39;: &amp;#39;lock&amp;#39; }
    r = s.post(
       host + &amp;quot;/InnovatorServer/Server/odata/{0}(&amp;#39;{1}&amp;#39;)&amp;quot;.format(item_type, item_id),
       headers = REST_HEADERS,
       data=json.dumps(data))
    r.raise_for_status()
    # Create relationship
    data = { &amp;#39;related_id@odata.bind&amp;#39;: &amp;quot;File(&amp;#39;{0}&amp;#39;)&amp;quot;.format(fileId) }
    r = s.post(
        host + &amp;quot;/InnovatorServer/Server/odata/{0}(&amp;#39;{1}&amp;#39;)/{2}&amp;quot;.format(item_type, item_id, rel_type),
        headers = REST_HEADERS,
        data=json.dumps(data))
    r.raise_for_status()
    # Get the updated item
    r = s.get(
        host + &amp;quot;/InnovatorServer/Server/odata/{0}?$filter=keyed_name eq &amp;#39;{1}&amp;#39;&amp;quot;.format(item_type, keyed_name),
        headers = REST_HEADERS)
    r.raise_for_status()
    item_id = r.json()['value'][0]['id']
    # Unlock
    data = { &amp;#39;@aras.action&amp;#39;: &amp;#39;unlock&amp;#39; }
    r = s.post(
        host + &amp;quot;/InnovatorServer/Server/odata/{0}(&amp;#39;{1}&amp;#39;)&amp;quot;.format(item_type, item_id),
        headers = REST_HEADERS,
        data=json.dumps(data))
    r.raise_for_status()&lt;/pre&gt;
Is there a cleaner way to do this?

Thanks,

Mark&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update relationship via REST API</title><link>https://www.aras.com/community/thread/1900?ContentTypeID=1</link><pubDate>Thu, 23 Aug 2018 09:52:14 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:fe24d033-1586-4498-b0c2-19ad4e3cdcc8</guid><dc:creator>Christopher Gillis</dc:creator><description>Hi Mark,

If you know the ID of the Document File relationship, you could perform a single REST call like &lt;code&gt;localhost/.../Document File(&amp;#39;5B2466563B5547FAA8268EC4E5F4C5F8&amp;#39;)&lt;/code&gt;. This will delete the relationship directly without updating the parent at all, so the ID will be the same. Please note that if you have version tracking enabled on your Document ItemType, this kind of REST call will &lt;strong&gt;not&lt;/strong&gt; create a new version of the parent Document.

Chris

&lt;hr /&gt;

Christopher Gillis

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update relationship via REST API</title><link>https://www.aras.com/community/thread/1899?ContentTypeID=1</link><pubDate>Wed, 22 Aug 2018 12:02:57 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:b340ac8d-d3ab-46cd-890c-7a8a26a2cd61</guid><dc:creator>mmoales</dc:creator><description>Another issue is after you delete the relationship, the previous Document ID is no longer valid. So an additional query is needed to get the ID of the modified Document.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update relationship via REST API</title><link>https://www.aras.com/community/thread/1898?ContentTypeID=1</link><pubDate>Wed, 22 Aug 2018 11:58:13 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:f20d1e4b-a0d1-4113-a33a-9ce91c6fdaee</guid><dc:creator>mmoales</dc:creator><description>Okay. So it appears  you need to do an explicit lock call first:

POST host/.../Document(&amp;#39;178D8999B5B54EBB8F943E9934088A03&amp;#39;)
{
&amp;quot;@aras.action&amp;quot;: &amp;quot;lock&amp;quot;
}

After that, I can delete the relationship. Finally, I have to send an explicit unlock. It would be nice if there was a way to do all of this in a single call.

Mark&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update relationship via REST API</title><link>https://www.aras.com/community/thread/1897?ContentTypeID=1</link><pubDate>Wed, 22 Aug 2018 11:44:48 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:897509ff-47ff-4565-82f4-ca716781be54</guid><dc:creator>mmoales</dc:creator><description>Hi Chris,

If I try to delete the relationship to an existing file first, I still get the ItemIsNotLockedException. I am trying to send the delete request as shown in the documentation:
&lt;blockquote&gt;To remove a relationship, the client sends a DELETE request to the $ref URL of the corresponding
relationship property, passing the $id query string option:
DELETE host/.../$ref&lt;/blockquote&gt;
Here is my request:
&lt;pre&gt;DELETE host/.../Document File/$ref?$id=Document File(&amp;#39;30776875F5674ECA8AE3ED803CA8B4B4&amp;#39;)&lt;/pre&gt;
Here is the response:
&lt;pre&gt;{
    &amp;quot;error&amp;quot;: {
        &amp;quot;code&amp;quot;: &amp;quot;SOAP-ENV:Server.ItemIsNotLockedException&amp;quot;,
        &amp;quot;message&amp;quot;: &amp;quot;Aras.Server.Core.ItemIsNotLockedException&amp;quot;
    }
}&lt;/pre&gt;
Adding the lock action does not help.

Mark&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update relationship via REST API</title><link>https://www.aras.com/community/thread/1896?ContentTypeID=1</link><pubDate>Fri, 10 Aug 2018 04:18:35 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:39407670-4a91-454f-970b-c2322c658c31</guid><dc:creator>AngelaIp</dc:creator><description>Hi Chris,

is there a reason why it´s not recommended to change the &lt;strong&gt;related_id&lt;/strong&gt; directly? 
I have a &amp;quot;replace this Part in the BOM with the latest generation of this Part&amp;quot; Action that can be used on BOM items.
The Action will replace the related_id.

I agree that for certain ItemTypes replacing the related_id may cause some problems, as changing the Relationshp often triggers additional Methods.
I think ItemType File is one potential candidate that would cause us trouble. 

But is there something else that could go wrong, espcially considering the ItemType &amp;quot;Part BOM&amp;quot;? 

Angela&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update relationship via REST API</title><link>https://www.aras.com/community/thread/1895?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 13:56:38 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:8c5242c1-d31d-41c3-a251-7fd07e9eb3be</guid><dc:creator>Christopher Gillis</dc:creator><description>Hello,

We recommend against modifying the &lt;strong&gt;related_id&lt;/strong&gt; of a relationship directly. Instead, you should delete the existing relationship and then create a new relationship to the desired item.

You can take a look at &lt;a href="http://community.aras.com/en/tech-tip-using-aras-restful-api/"&gt;this blog post&lt;/a&gt; for an example of how to both delete and create an item through the REST API.

Chris

&lt;hr /&gt;

Christopher Gillis

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update relationship via REST API</title><link>https://www.aras.com/community/thread/1894?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 13:56:37 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:e8cff16f-8c4d-4812-b490-372bc37cd49f</guid><dc:creator>Christopher Gillis</dc:creator><description>Hello,

We recommend against modifying the &lt;strong&gt;related_id&lt;/strong&gt; of a relationship directly. Instead, you should delete the existing relationship and then create a new relationship to the desired item.

You can take a look at &lt;a href="http://community.aras.com/en/tech-tip-using-aras-restful-api/"&gt;this blog post&lt;/a&gt; for an example of how to both delete and create an item through the REST API.

Chris

&lt;hr /&gt;

Christopher Gillis

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>