Planning Analytics

Planning Analytics

Get AI-infused integrated business planning

 View Only
  • 1.  Trouble accessing async object from RestAPI Prefer: respond-async

    Posted Fri June 28, 2024 02:23 PM
    Edited by William Smith Fri June 28, 2024 02:26 PM

    Hi all,

    I'm having trouble interacting with the TM1 rest API in the following way. I'm hoping maybe there's some obvious that I'm missing :)

    Kick-off TI process

    public async static Task<string> RunProcessWithPolingAsync(TM1SharpConfig tm1, string processName, Dictionary<string, string>? parameters = null)
    {
    	var client = tm1.GetTM1RestClient();
    
    	client.DefaultRequestHeaders.Add("Prefer", "respond-async");
    
    	var jsonBody = new StringBuilder();
    
    	if (parameters != null)
    	{
    		jsonBody.Append("{\"Parameters\":[");
    
    		parameters.AsEnumerable().ToList().ForEach(x =>
    		{
    			jsonBody.Append("{\"Name\":\"" + x.Key + "\", \"Value\":\"" + x.Value + "\"}");
    		});
    
    		jsonBody.Append("]}");
    	}
    
    	var jsonPayload = new StringContent(jsonBody.ToString(), new MediaTypeWithQualityHeaderValue("application/json"));
    
    	var response = await client.PostAsync(tm1.ServerHTTPSAddress + @"/api/v1/Processes('" + processName + "')/tm1.ExecuteWithReturn", jsonPayload);
    
    	var asyncId = ParseAsyncId(response.Headers.Where(x => x.Key.Equals("Location")).First().Value.First());
    
    	return await GetAsyncStatus(tm1, asyncId);
    }

    Returns location header, parse out ID: 

    ../_async('OLTJUN4E4XFBAoV1fiSrQsmK9tn1U')

    Call to check status always 404s. Doesn't matter how long I wait or how many times I check.

    https://server:port/api/v1/_async('OLTJUN4E4XFBAoV1fiSrQsmK9tn1U')
    Status Code: 404
    Content: {"error":{"code":"278","message":"Resource '/api/v1/_async('OLTJUN4E4XFBAoV1fiSrQsmK9tn1U')' not found"}}



    ------------------------------
    William Smith
    ------------------------------



  • 2.  RE: Trouble accessing async object from RestAPI Prefer: respond-async

    Posted Fri June 28, 2024 02:25 PM

    Reference: https://community.ibm.com/community/user/businessanalytics/discussion/executewithreturn-asynchronously

    User Robert Gordy advised that he was able to resolve the issue with 404 / not found, but I don't see specific steps taken :(



    ------------------------------
    William Smith
    ------------------------------



  • 3.  RE: Trouble accessing async object from RestAPI Prefer: respond-async

    Posted Fri June 28, 2024 06:08 PM

    Solution: Make sure you're attempting to access the async object / endpoint from the same http session that you started the TI process on. Trying to access it from a different http session will always 404.



    ------------------------------
    William Smith
    ------------------------------



  • 4.  RE: Trouble accessing async object from RestAPI Prefer: respond-async

    Posted Fri June 28, 2024 06:43 PM

    See below for implementation details:

    https://github.com/WilliamSmithEdward/AndromedaTM1Sharp/blob/master/AndromedaTM1Sharp/TM1RestAPI_AsyncStatus.cs

    https://github.com/WilliamSmithEdward/AndromedaTM1Sharp/blob/master/AndromedaTM1Sharp/TM1RestAPI_RunProcess.cs



    ------------------------------
    William Smith
    ------------------------------



  • 5.  RE: Trouble accessing async object from RestAPI Prefer: respond-async

    Posted Thu July 04, 2024 02:56 PM

    Hi William,

    I am the Community Manager for Planning Analytics and i'm just checking to see if the problem you raised above has been resolved. If not, I will follow-up on your behalf.

    Thanks,

    Nick



    ------------------------------
    Nick Plowden
    AI Community Engagement
    IBM
    ------------------------------



  • 6.  RE: Trouble accessing async object from RestAPI Prefer: respond-async

    Posted Fri August 16, 2024 01:14 AM

    Hi, Nick

    Thanks for follow-up. One thing I want to confirm, does it have to be the same HTTP session to do query this async id? Is it possible across sessions?



    ------------------------------
    mvp morgan
    ------------------------------



  • 7.  RE: Trouble accessing async object from RestAPI Prefer: respond-async

    Posted Fri August 16, 2024 11:38 AM

    async jobs are session scope, so 'yes' as as generalization.

    glancing at the code reference, did not see the response cookies get stored for reuse into subsequent calls, so that seems like the likely thing to change.



    ------------------------------
    Ted Phillips
    IBM
    ------------------------------