apigeecli icon indicating copy to clipboard operation
apigeecli copied to clipboard

API Product import with flag --upsert outputs error

Open ana-r-goncalves-alb opened this issue 2 years ago • 4 comments

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!

ana-r-goncalves-alb avatar May 16 '23 09:05 ana-r-goncalves-alb

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.

srinandan avatar May 16 '23 15:05 srinandan

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

kurtkanaskie avatar May 16 '23 16:05 kurtkanaskie

@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.

srinandan avatar May 17 '23 14:05 srinandan

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.

ana-r-goncalves-alb avatar May 17 '23 14:05 ana-r-goncalves-alb