Rest API subscription and Subscriber issue  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Rest API subscription and Subscriber issue

Postby SBarnes » Tue Feb 22, 2022 3:46 pm

I think there is a bug in the REST API in that the below code from the start up does not take into consideration if the subscriber is enabled or not?


Code: Select all
 _webhookSubscribers = AppHost.GetDbConnection().Select<SY_WebhookSubscriber>();
            // Read all the web hook subscriptions
            _webhookSubscriptions = AppHost.GetDbConnection().Select<SY_WebhookSubscription>();
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Rest API subscription and Subscriber issue  Topic is solved

Postby Mike.Sheen » Tue Feb 22, 2022 5:05 pm

SBarnes wrote:I think there is a bug in the REST API in that the below code from the start up does not take into consideration if the subscriber is enabled or not?


Code: Select all
 _webhookSubscribers = AppHost.GetDbConnection().Select<SY_WebhookSubscriber>();
            // Read all the web hook subscriptions
            _webhookSubscriptions = AppHost.GetDbConnection().Select<SY_WebhookSubscription>();


Fixed in DEV-8178
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: Rest API subscription and Subscriber issue

Postby SBarnes » Tue Feb 22, 2022 5:09 pm

Can I get the code I need to retrofit it into 7.2.0 SR6?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Rest API subscription and Subscriber issue

Postby Mike.Sheen » Tue Feb 22, 2022 6:08 pm

SBarnes wrote:Can I get the code I need to retrofit it into 7.2.0 SR6?


Code: Select all
public void Post(WebhooksEventPOSTRequest request)
{
   // This is the route invoked by clients to indicate an event has occurred.

   // Check key               
   Helper.Service.ValidateInternalRequest(this.Request);

   // Add items to the message queue with status 0 (not sent) whose subscriber is enabled.
   foreach (var activeSubscription in RESTAPIPlugin.WebhookSubscriptions.Join(RESTAPIPlugin.WebhookSubscribers,
           x => x.SY_WebhookSubscriber_RecID,
           y => y.RecID,
            (subscription, subscriber) => new {IsEnabled = subscriber.IsEnabled, EventName = subscription.EventName, URL = subscription.URL, RecID = subscription.RecID, SY_WebhookSubscriber_RecID = subscriber.RecID })
            .Where(z => z.IsEnabled == true && z.EventName == request.EventName))
   {
      SY_WebhookMessage newMessage = new SY_WebhookMessage { RecID = System.Guid.NewGuid(), SY_WebhookSubscription_RecID = activeSubscription.RecID, Body = request.Body, Status = 0, Retries = 0 };
      Db.ExecuteSql(@"INSERT INTO SY_WebhookMessage (RecID, SY_WebhookSubscription_RecID, Body, ItemNo, Status, LastSavedDateTime, AddedDateTime, Retries)
                        SELECT @RecID, @SY_WebhookSubscription_RecID, @Body, (SELECT COALESCE(MAX(ItemNo), 0) + 1 FROM SY_WebhookMessage), @Status, SYSUTCDATETIME(), SYSUTCDATETIME(), @Retries WHERE @SY_WebhookSubscription_RecID IN (SELECT RecID FROM SY_WebhookSubscription)",
                 new { RecID = newMessage.RecID, SY_WebhookSubscription_RecID = newMessage.SY_WebhookSubscription_RecID, Body = newMessage.Body, Status = newMessage.Status, Retries = newMessage.Retries });

      // read back and keep that in our internal list as our item no and lastsaved date time is set at the database level.
      newMessage = Db.SingleById<SY_WebhookMessage>(newMessage.RecID);

      if(newMessage != null)
      {
         RESTAPIPlugin.WebhookMessages.Add(newMessage);
         // send to url         
         WebHookController.CallWebhook(newMessage);               
      }
   }
}
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757


Return to REST API

Who is online

Users browsing this forum: No registered users and 1 guest