Guzzle Service Description x-www-form-urlencoded example

Created on 16 January 2024, 5 months ago
Updated 27 February 2024, 4 months ago

Problem/Motivation

I need to get a token with x-www-form-urlencoded request.
In my yml i have

operations:
  login:
    httpMethod: "POST"
    uri: "myurl"
    summary: "Return web service token."
    parameters:
      content-type:
        location: "header"
        default: "application/x-www-form-urlencoded"
      appId:
        type: "string"
        location: "form_params"
      appKey:
        type: "string"
        location: "form_params"
    responseModel: "ResponseLogin"

If i try to get token from http client manager test page, i have this error:

GuzzleHttp\Command\Exception\CommandException: There was an error executing the login command: No location registered for appId in GuzzleHttp\Command\Exception\CommandException::fromPrevious() (line 56 of /var/www/html/vendor/guzzlehttp/command/src/Exception/CommandException.php).
GuzzleHttp\Command\Guzzle\Serializer->__invoke(Object) (Line: 198)
GuzzleHttp\Command\ServiceClient->transformCommandToRequest(Object) (Line: 176)
GuzzleHttp\Command\ServiceClient->GuzzleHttp\Command\{closure}()
Generator->current() (Line: 72)
GuzzleHttp\Promise\Coroutine->__construct(Object) (Line: 83)
GuzzleHttp\Promise\Coroutine::of(Object) (Line: 169)
GuzzleHttp\Command\ServiceClient->GuzzleHttp\Command\{closure}(Object) (Line: 77)
GuzzleHttp\Command\Guzzle\Handler\ValidatedDescriptionHandler->GuzzleHttp\Command\Guzzle\Handler\{closure}(Object) (Line: 86)
GuzzleHttp\Command\ServiceClient->executeAsync(Object) (Line: 78)
GuzzleHttp\Command\ServiceClient->execute(Object) (Line: 379)
Drupal\http_client_manager\HttpClient->call('login', Array) (Line: 104)
Drupal\http_client_manager\Entity\HttpConfigRequest->execute() (Line: 65)
Drupal\http_client_manager\Controller\HttpConfigRequestController->execute('alias_thron_asset_services_yaml', 'login', 'login')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

When i try to get token programmatically, i have the right response

/*$client = \Drupal::httpClient();
      $request = $client->request('POST', 'myurl', [
        'form_params' => [
          'appKey' => $this->getConfig('app_key'),
          'appId' => $this->getConfig('app_id'),
        ],
        'debug' => true,
      ]);*/

How can setup my yml to have the token?
Thank you

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Closed: outdated

Version

9.3

Component

Code

Created by

🇮🇹Italy trickfun

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024