How to Trigger API?

This might be a dumb question, but I tried playing around and can’t seem to figure it out: how can I trigger an API call?

For example, if I have a POST request that I made in Divhunt’s API, and I want it to execute when I push a button, how would I make that happen?

Hi @chelce

That part is not possible yet, we need to have workflow system first in order to support that.
The only way for now is to trigger API manually with custom code.

I’ll write you detailed example here in 1-2 once I get back home

Here’s the system that will be used by workflow once we create the UI for it.

So this is called mdActions.

To see list of all actions, check console

mdActions.ItemsGet();

image

But as for now, there’s only 1 action (REST)

If you check more deeply, you can see the input and output options, input is what you send, output is what you receive.

So for REST API, you send the ID and Properties.

let input = {
    id: 90, // Your REST API Request ID (find it inside admin panel from URL section
    properties: [ // Properties that are configured inside Request. 
        {key: 'property-key1', value: 'property-value2'},
        {key: 'property-key2', value: 'property-value2'}
    ]
};

mdActions.ItemGet('REST').Fn('run', {}, input, (success) => 
{
    console.log(success); // Will return {success, message, data}
}, 
(error) => 
{
    console.log(error);  // Will return {success, message}
});

So what you would want to do, is to catch form submission and run this code with provided values.

Or wait until we create workflow :slight_smile:

Awesome, @dejan, thank you so much! I know you guys are working like crazy on development (it shows in the changes to the builder). You guys have made it so easy to do all of the easy stuff that I actually feel curious enough to venture into some of the more advanced stuff. Thank you for all of your help! :slight_smile:

2 Likes

I’m trying this and getting 422 unprocessable content

I’m wondering if I set up the variables well in the call function in the admin panel.

Request URL: https://opsmachine.co/api/rest/run

payload:

{id: "223", properties: {email: "test@gmail.com", source: aHR0cHM6Ly9vcHNtYWNoaW5lLmNv"}}

Response:

    "success": false,
    "message": "Failed to execute request. Request failed.",
    "out": [],
    "fatal": false,
    "framework": {
        "mode": "app",
        "time.connection": 1.4,
        "time.database": 7.6000000000000005,
        "time.query": 6.2,
        "time": "268.1"
    }}

Code:

 $('#emailSubForm').submit(function(event) {
      console.log("Form is submitted");
      event.preventDefault();
      
      
      const source = encodeURI("https://opsmachine.co")
      
      let email = $('#subFormEmail').val(); // Replace 'email' with the actual name attribute of your email input field
      
      
      let input = {
          id: 223, // Your REST API Request ID
          properties: [
              {key: 'email', value: email},
              {key: 'source', value: source}
              // Add other properties here
          ]
      };

      mdActions.ItemGet('REST').Fn('run', {}, input, (success) => {
          console.log(success); // Will return {success, message, data}
        },
        (error) => {
            console.log(error); // Will return {success, message}
      });
    });