question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create User API Not passing in function

See original GitHub issue

Problem

When using Create User API, error received, does not appear to parse body.

Version

Version 1.22.0

Environment

Docker on Ubuntu 18.10 Host

Command;

curl -X POST "https://grocy.fish.local/api/users/create" -H "GROCY-API-KEY: SecretKey" -H "accept: application/json" -H "Content-Type: application/json" -d "{"id":5,"username":"string12","first_name":"string12","last_name":"string12","password":"string2","row_created_timestamp":"2018-12-30T21:30:39.906Z"}"

Error:

\/www\/controllers\/UsersApiController.php(35): Grocy\\Services\\UsersService->CreateUser(NULL, NULL, NULL, NULL)"

If I change the function to;

public function CreateUser(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
        {
                $requestBody = $request->getParsedBody();

                try
                {
                        $this->UsersService->CreateUser('username','first','last','pass');
                        return $this->ApiResponse(array('success' => true));
                }
                catch (\Exception $ex)
                {
                        return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
                }
        }

It creates the user matching the test variables, however I couldn’t get it to work trying to parse $request. I tried to match from the ChoreTrackExecution with

$request->getQueryParams()['username']

But it seems the $request variable isn’t populating correctly.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
gen2fishcommented, Dec 31, 2018

So the Swagger worked when I fixed the trailing comma that you pointed out.

I also believe I fixed my issue. Powershell was not passing the body of the request as JSON and so it wasn’t getting accepted. Once I adjusted my script to convert to JSON as so;

$params = @{
    body =  @{
      "id" = 0
      "username" = $UserName
      "first_name" = $FirstName
      "last_name" = $LastName
      "password" = $Passwd
      "row_created_timestamp"= $Execute
    } | ConvertTo-Json -Depth 5
      uri = "$URI/api/users/create"
      headers = @{
        "accept" = "application/json"
        "Content-Type" = "application/json"
        "GROCY-API-KEY" = $global:grocyGlobal.APIKEY
      }
      method = "Post"
  }

It worked as expected.

Thank you for the responses and the great app.

0reactions
berrndcommented, Dec 31, 2018

Great, and thanks!

Maybe you’re the first who uses the API with gen2fish/grocy-posh, at least the first project that I saw - so hope the API covers everything needed…

If you think this is something “everyone” could need, feel free to request it to be added under the github.com/grocy organization.

Happy new year! 🎆 🥂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get the current user, within an ApiController action, without ...
My scenario involved an AngularJS frontend and a Web API 2 backend application, both running under IIS. ... No need to pass any...
Read more >
Pass API Gateway REST API parameters to a Lambda ... - AWS
I need my Amazon API Gateway REST API to pass query string parameters to a backend AWS Lambda function and an HTTP endpoint....
Read more >
Use Web API functions (Microsoft Dataverse) - Power Apps
In this article. Passing parameters to a function; Pass record reference to a function; Bound and unbound functions; Compose a query with ...
Read more >
Functions as REST API | Zoho Developer Help
You can invoke a REST API function from a widget using the ZOHO.CRM.FUNCTIONS.execute() function. Using this function, you can pass user input values...
Read more >
Setup User Registration In ASP.NET Core API - YouTube
Authentication is the process of determining a user's identity. Authorization is the process of determining whether a user has access to a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found