XF 2.2 Problem with POST method in new API endpoint

Orit

Active member
Hello :)

I've added a new API endpoint to an addon we use (Snogs Advanced forms).

So far the GET method works as it should.
I am now trying to get the POST method to function.

I have two controller classes:
class Form extends AbstractController
class Forms extends AbstractController

The Forms class fetches a list of forms (actionGet).
I currently don't want to allow creating a form,
but added the actionPost function to see when it gets rendered:
PHP:
public function actionPost()
{
    $this->assertRequiredApiInput(['title']);
}

The Form class fetches a specific form (actionGet)
I created a POST method in the Form class, but when I try out the api it keeps reading the POST method in the Forms class,
and I get the expected error for not sending the correct input:
JSON:
{
    "errors": [
        {
            "code": "required_input_missing",
            "message": "Required input missing: title",
            "params": {
                "missing": [
                    "title"
                ]
            }
        }
    ]
}

What am I missing?

EDIT: Just to clarify I have added the api scopes in XF: forms:read, forms:write
But I don't know where and when to call them....
 
Last edited:
Edit:
I have also got the routes set with the correct controller class in each.

Do I need to declare this somewhere else too?
 
Update:
Apparently one of my Api/Controller classes does not get called.

I've set it in /admin.php?routes/#api
as:

1689879401619.png

1689879449337.png

Where is the controller called?

Thanks!
 
I think the routes look fine, but without the code or an example of how you're sending the requests it's hard to say for sure (or test myself).

EDIT: Just to clarify I have added the api scopes in XF: forms:read, forms:write
But I don't know where and when to call them....
You check required scopes in the controller's preDispatchController method:

PHP:
protected function preDispatchController($action, ParameterBag $params)
{
    $this->assertApiScopeByRequestMethod('forms');
}
 
I think the routes look fine, but without the code or an example of how you're sending the requests it's hard to say for sure (or test myself).


You check required scopes in the controller's preDispatchController method:

PHP:
protected function preDispatchController($action, ParameterBag $params)
{
    $this->assertApiScopeByRequestMethod('forms');
}
Thank you @Jeremy P
I found my mistake, and have finalized the addon :)
Thanks for your help!
 
Top Bottom