Jump to content

REST API with deactivated htaccess based SEO friendly URLs


Recommended Posts

Posted

When using the REST API, a GET request is quite easy as long as .htaccess based SEO URLs are activated, this URL string would work:

/api/forums/topics?sortBy=date&sortDir=desc

But with deactivated SEO friendly URLs, this string would work:

/api/index.php?/forums/topics

but this one not:

/api/index.php?/forums/topics?sortBy=date&sortDir=desc

So how should I add the extra GET variables without generating an 3S290/4 INVALID_CONTROLLER error?

Posted
13 hours ago, CodingJungle said:

have you tried:

/api/index.php?/forums/topics/&sortBy=date&sortDir=desc

In this case you get an error 

errorCode: "1F294/1",
errorMessage: "INVALID_ID"

 

12 hours ago, Ryan Ashbrook said:

/api/index.php?/forums/topics&sortBy=date&sortDir=desc

 

In this case you get an error 

errorCode: "3S290/4",
errorMessage: "INVALID_CONTROLLER"

 

Posted
1 hour ago, CodingJungle said:

ryan got it right

Try him example and you get an error 

errorCode: "3S290/4",
errorMessage: "INVALID_CONTROLLER"

system/Dispatcher/Api.php

		if ( \IPS\Settings::i()->use_friendly_urls and \IPS\Settings::i()->htaccess_mod_rewrite )
		{
			/* We are using Mod Rewrite URL's, so look in the path */
			$path = mb_substr( \IPS\Request::i()->url()->data[ \IPS\Http\Url::COMPONENT_PATH ], mb_strpos( \IPS\Request::i()->url()->data[ \IPS\Http\Url::COMPONENT_PATH ], '/api/' ) + 5 );
		}
		else
		{
			/* Otherwise we are not, so we need the query string instead, which is actually easier */
			$path = \IPS\Request::i()->url()->data[ \IPS\Http\Url::COMPONENT_QUERY ];
		}
		$pathBits = array_filter( explode( '/', $path ) );

$pathBits in this case is 

Array
(
    [1] => forums
    [2] => topics&sortBy=date&sortDir=desc
)

go ahead

			/* Work out the app and controller. Both can only be alphanumeric - prevents include injections */
			$app = array_shift( $pathBits );
			if ( !preg_match( '/^[a-z0-9]+$/', $app ) )
			{
				throw new \IPS\Api\Exception( 'INVALID_APP', '3S290/3', 400 );
			}
			$controller = array_shift( $pathBits );
			if ( !preg_match( '/^[a-z0-9]+$/', $controller ) )
			{
				throw new \IPS\Api\Exception( 'INVALID_CONTROLLER', '3S290/4', 400 );
			}

$controller is topics&sortBy=date&sortDir=desc

Posted
7 hours ago, newbie LAC said:

Try him example and you get an error 


errorCode: "3S290/4",
errorMessage: "INVALID_CONTROLLER"

system/Dispatcher/Api.php


		if ( \IPS\Settings::i()->use_friendly_urls and \IPS\Settings::i()->htaccess_mod_rewrite )
		{
			/* We are using Mod Rewrite URL's, so look in the path */
			$path = mb_substr( \IPS\Request::i()->url()->data[ \IPS\Http\Url::COMPONENT_PATH ], mb_strpos( \IPS\Request::i()->url()->data[ \IPS\Http\Url::COMPONENT_PATH ], '/api/' ) + 5 );
		}
		else
		{
			/* Otherwise we are not, so we need the query string instead, which is actually easier */
			$path = \IPS\Request::i()->url()->data[ \IPS\Http\Url::COMPONENT_QUERY ];
		}
		$pathBits = array_filter( explode( '/', $path ) );

$pathBits in this case is 


Array
(
    [1] => forums
    [2] => topics&sortBy=date&sortDir=desc
)

go ahead


			/* Work out the app and controller. Both can only be alphanumeric - prevents include injections */
			$app = array_shift( $pathBits );
			if ( !preg_match( '/^[a-z0-9]+$/', $app ) )
			{
				throw new \IPS\Api\Exception( 'INVALID_APP', '3S290/3', 400 );
			}
			$controller = array_shift( $pathBits );
			if ( !preg_match( '/^[a-z0-9]+$/', $controller ) )
			{
				throw new \IPS\Api\Exception( 'INVALID_CONTROLLER', '3S290/4', 400 );
			}

$controller is topics&sortBy=date&sortDir=desc

Did you try my suggestion?

Posted

Ryan's suggestion is correct, however a bug exists in the current release that results in the INVALID_CONTROLLER error that you are seeing. We apologize for this issue, and a patch for the issue will be available in 4.1.16.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...