SOAP API: Delete Asset Link


(Tbaatar) #1

**Matrix Version:5.4.3.1

Hi.

We’re working on a SOAP API to delete Matrix asset links using the DeleteAssetLink function.
We want to selectively delete specific Notice Link ID from a parent.

It seems to work partially but it removes all other Link Types and removes the web path. This is the code we’ve used to selectively delete.

   $client->DeleteAssetLink([
          'LinkID' => $linkId,
    ]);

Are we missing something else or is there a bug with the DeleteAssetLink function in this version of Matrix or with the SOAP API?

Any pointers or helper very much appreciated.

Thanks


(John gill) #2

(usual disclaimer that I don’t actually understand PHP)

Looks like a bug in the SOAP API DeleteAssetLink method. It tries to check if the child of the link only has one significant link, and if so it trashes the asset instead of deleting the link, however it fails to check whether the link being deleted is that significant link. By my read, if there is an asset with a single TYPE_1 parent, and many NOTICE parents, then trying to delete any of those NOTICE links will incorrectly trash the asset.

...
$significant_parent_links       = $GLOBALS['SQ_SYSTEM']->am->getLinks($link['minorid'], SQ_SC_LINK_SIGNIFICANT, '', TRUE, 'minor');
if (count($significant_parent_links) > 1) {
	// More than one parent link, we can delete the link
	$result = $GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($linkid);
} else {
	// Only one link holly cow, lets trash it instead, otherwise we'l have an orphan asset in the system
	$result = $GLOBALS['SQ_SYSTEM']->am->trashAsset($link['minorid']);
}//end if
...

(David Schoen) #3

I’ve had a look and agree with this assessment, I’ve lodged a bug https://jira.squiz.net/browse/MATRIX-932 .


(Tbaatar) #4

Thanks for the feedback John and David.

What would be the best way around setting link type outside of Matrix? We are trying to manage all content from Contentful and everything is working quite well apart from the link type.

Thanks.


(John gill) #5

removeLink in the JS API doesn’t suffer from the same problem, so you could use that instead if you don’t mind mixing the two APIs.


(Adrian Dobre) #6

@JohnGill, thank you for your reply. How would you make an JS Api call to remove de Link from a remote server.

Our flow that we try to achieve is the following:

Contentful post updated > webhook triggered > Api Server formats the data and sends it to the Matrix instance via SOAP calls, creating/updating an “news_item” type asset, setting its metadata, setting notice links to parent assets.
Everything works perfectly until we need to update child to parent notice links ex. an editor removes a tag from a post and we need to sync it back to matrix removing the tag.

SOAP call removes all links via 1 single call. I presumed it was a bug in the SOAP Api call, thank you for confirming it. The JS api works perfectly from the browser in a test page removing the desired link. But when we try to call it via Guzzle from the server CORS kicks in and blocks it. Am i missing something here is there another way to call the jsApi?

I am quite new to Matrix implementations and probably i am not getting the whole picture.

Many thank for your help.

Adrian


(John gill) #7

It’s not CORS giving you trouble, it’ll be that js_api requires a session token and a CSRF token. If you want to call it from non-browser code you’ll need to perform the login post to get a session cookie, and then you’ll need to fetch a page to extract the value of <input type="hidden" name="token"> so you can provide that with each API call. It’s a pain, especially for just one method.

You might be able to get the same thing happening with triggers. Set the Metadata with the SOAP API, and use a trigger to update the NOTICE links. Not sure on the nitty gritty, I don’t wade into Trigger-land very much.