Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Product import with flag --upsert outputs error #203

Open
ana-r-goncalves-alb opened this issue May 16, 2023 · 4 comments
Open

API Product import with flag --upsert outputs error #203

ana-r-goncalves-alb opened this issue May 16, 2023 · 4 comments

Comments

@ana-r-goncalves-alb
Copy link

ana-r-goncalves-alb commented May 16, 2023

Hi,

When importing a new API Product using the import command with the --upsert flag, the product gets created in Apigee but I still get the following error:

{
  "error": {
    "code": 404,
    "message": "ApiProduct with name TestImport does not exist",
    "status": "NOT_FOUND",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.PreconditionFailure",
        "violations": [
          {
            "type": "keymanagement.service.apiproduct_doesnot_exist",
            "subject": "[2002:a17:531:292b::]:4169:wmfz23:9825:260695:117263226",
            "description": "ApiProduct with name TestImport does not exist"
          }
        ]
      },
      {
        "@type": "type.googleapis.com/google.rpc.RequestInfo",
        "requestId": "6579398348678207337"
      }
    ]
  }
}

Is there a way of hiding this error while still getting the API Product data from the response?

Thank you in advance for your time!

@srinandan
Copy link
Collaborator

This error isn't really an error (or perhaps it is better to say is, the 404 is expected). The upsert command does a GET first to decide between a create vs. update. Since you are importing a new API Product, the GET returns a 404.

You can hide errors (and usage message) with two environment variables

export APIGEECLI_NO_USAGE=true and APIGEECLI_NO_ERRORS=true. This preserves the exit code in bash.

@kurtkanaskie
Copy link
Collaborator

I was just trying those env settings and various flags, but I was not able to block the output. Nor was I able to see appropriate exit codes using echo $?.

export APIGEECLI_NO_USAGE=true
export APIGEECLI_NO_ERRORS=true
apigeecli products import --file products.json --upsert=true

The above shows the 404 errors regardless of the env settings. It returns exit status of 0 when products exists or not.

apigeecli products import --file products.json --upsert=false

The above returns 409 and exit status of 0 in both cases.

The env settings do affect the display of errors (e.g. Error: unknown flag: --foo) and usage (e.g. after a bad param).

The use of --print-output=false doesn't seem to do anything. The use of --no-outout blocks all output but exit status code is still 0.

Attached is a simple products.json file that I used to test.
products_json.txt

@srinandan
Copy link
Collaborator

@kurtkanaskie and I chatted, #204 will address the exit status when importing API products.

@ana-r-goncalves-alb - What is the reason for getting the API Product data from the response? It is not possible to suppress 404 and get the API response.

@ana-r-goncalves-alb
Copy link
Author

ana-r-goncalves-alb commented May 17, 2023

The scenario I was testing was importing an API product that doesn't exist in Apigee yet, while using the --upsert flag (because I don't know beforehand if it exists or not and want to update if it doesn't), APIGEECLI_NO_USAGE=true and APIGEECLI_NO_ERRORS=true. I want to retreive the API response because I need the updated createdAt and lastModifiedAt values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants