Calling REST API Patch from an ECM Datalink

I’m not using the datalink in a workflow yet.
I’m verifying that the datalink returns accurate results before I try to use it.

It’ll be this portion of your CallDefinition we’ll want to update. You’ll need the URL in the following format, but will need to update the sections I’ve put in italics.

https://URL/EpicorInstance/api/v1/BaqSvc/DS-UpdateS02(Company)/?$filter=Company eq ‘Company’ and OrderNum eq @OrderNum"

Update these:
URL/EpicorInstance
(Company)

1 Like

I’ve tried this before and just did again and get the same results…or variations of the same errors.

Here is the URL:

[
    {
        "URL": "https://erp.*********.com/kinetic/api/v1/BaqSvc/DS-UpdateSO2(***)/?$filter=Company eq ‘Company’ and OrderNum eq @OrderNum",
        "Method": "GET",
        "AuthScheme": "@TokenType",
        "AuthParameter": "@AccessToken",
        "Body": "",
        "CollectionPath": "value",
        "WSHeaders": [
            {
                "Key": "CallSettings",
                "Value": "{Company: \"@company\", OrderNum: \"@OrderNum\"}"
            }
        ],
        "Columns": [
            {
                "Name": "Company",
                "Path": "OrderHed_Company",
                "ChainOutput": null
            },
            {
                "Name": "OrderHeld",
                "Path": "OrderHed_OrderHeld",
                "ChainOutput": null
            },
            {
                "Name": "OrderNum",
                "Path": "OrderHed_OrderNum",
                "ChainOutput": null
            }
        ],
        "ContentType": "application/json",
        "Parser": 0,
        "EscapeParameters": true,
        "XMLNameSpaces": null
    }
]

Here is the BAQ. It is updateable.
It does not make a difference if I use an updateable BAQ or standard query. Same results.
I have the parameter in the BAQ with a lowercase c in Company because I get errors in the query if not. This is I believe an Epicor issue but not related to this topic.

select 
	[OrderHed].[Company] as [OrderHed_Company],
	[OrderHed].[OrderNum] as [OrderHed_OrderNum],
	[OrderHed].[OrderHeld] as [OrderHed_OrderHeld]
from Erp.OrderHed as OrderHed
where (OrderHed.OrderNum = @OrderNum  and OrderHed.Company = @company)

BadRequest: Bad Request
400:REST API Exception
Microsoft.Data.OData.ODataException:Syntax error: character ‘‘’ is not valid at position 11 in ‘Company eq ‘Company’ and OrderNum eq 5’.

1 Like

Ah, I think I have the next thing to test. When you are using the values from different tables within Epicor in a BAQ, they will likely need to be identified by their full value. Basically, you need to use OrderHed_Company eq ‘@Company’ and OrderHed_OrderNum eq @OrderNum in your URL.

2 Likes

I also see this as being a potential issue. This could come down to copying from this forum and the Datalink not using the proper character when pasting into it. You may have to set this yourself.

I set the parameter field in the datalink as varchar and tried nvarchar that makes no difference.

I tried to set the field type in the call settings and it wiped the all the json out completely. Blank.

The parameters being varchar or nvarchar should both work, so yes, that will not make a difference.

As for the “field type in the call settings” you mentioned, I am not sure what you may be referring to. The CallDefinition box can be a huge pain to write the code in as clicking in there will always highlight everything on the first click. I tend to write things out in Notepad++ and then paste it into ECM for that exact reason. Fortunately, you have your code posted here if it wiped it out.

Does your BAQ have parameters required while just testing it in Epicor? If so, the parameters you’re using in ECM to pass into Epicor should negate needing those, unless you need that BAQ for other things only being done in Epicor, too.

I hate to make this thread longer, but it has provided me the best information… I have a BAQ call w parameters working. Am trying to convert to a Update BAQ. I cannot seem to pass the parameters from the datalink call as input to update a field in the UBAQ… Has anyone done this ? Or do I need to do a Patch call to a BO ?

I haven’t done this myself, but I would expect that you should still be able to send the values into the BAQ, but it may need to be that you first pull the records, update them and then pass back the entire table. Once that happens, you’d have to initiate the update part of the BAQ.

1 Like

There seems to be no way to drop the parameter into the Update process… I got the JSON Patch working, seems so much more straightforward. Now to add records via JSON and DataLink. Thanks for the Reply.

Thanks for all the help!
Because of your help, we were able to get an update to work properly. (We gave up on the Updateable BAQ idea). Now we are on to other ways to use this.

In this example, we have a Sales Order Approval process that gets kicked off by a BPM in Kinetic, that BPM sends a copy of the Sales Order Acknowledgement with the MetaData to DocStar.
The Sales Order gets sent to an Approval Workflow.
When the Sales Order gets approved, it moves on to a step where it emails the customer a copy of the approved Sales Order and with this DataLink, takes the Sales Order off hold. (One of the coolest things about all of this is that there is sooo much automation going on that nobody really knows about…unless something doesn’t work. LOL)

When that order gets taken off of hold, then we run through the EDI form 855 processing if it applies.

[
    {
        "URL": "api/v1/Erp.BO.SalesOrderSvc/SalesOrders(@CompanyId,@OrderNum)",
        "Method": "Patch",
        "AuthScheme": "@TokenType",
        "AuthParameter": "@AccessToken",
        "Body": "{ \"OrderHeld\": \"@paramOrdHeld\" }",
        "CollectionPath": null,
        "WSHeaders": [
            {
                "Key": "CallSettings",
                "Value": "{Company: \"@CompanyId\"}"
            }
        ],
        "Columns": null,
        "ContentType": "application/json",
        "Parser": 0,
        "EscapeParameters": false,
        "XMLNameSpaces": null
    }
]

Thanks again!!!

2 Likes

Glad you got it all working! Datalinks can be a powerhouse once developed.

I think that every developer on here is all too familiar with the dichotomy of things working perfectly be the expected outcome and any issue, no matter how small, is met with “Why doesn’t it just work?” lol

1 Like

This made me smile, and that’s another half of the battle, sometimes I get to building a workflow that works so well (when it works well) that I completely forget to handle errors in a helpful/user friendly way.

1 Like

Thanks for sharing your success, proud of you! :muscle:

1 Like

As of 23.2.93 the SaaS ECM client has an issue with patch/post rest calls. If anyone is having issues with using patch/post rest calls and is SaaS check with support. The ECM client had an update 2 weeks ago that resulted in only get datalinks being workable.

1 Like

Nice, thanks for letting us know.