zscaler / zscaler-sdk-go

Zscaler SDK for Golang (ZPA/ZIA/ZDX/ZCC APIs)
https://zscaler.com
MIT License
10 stars 1 forks source link

ZIA Location creation with VPN credentials ( FQDN ) is failing with error code 400 #232

Closed gauravv9 closed 6 months ago

gauravv9 commented 6 months ago

Confirmation

zscaler-sdk-go version

2.3.9

Go environment

GO111MODULE='' GOARCH='amd64' GOBIN='' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='darwin' GOINSECURE='' GONOPROXY='' GONOSUMDB='' GOOS='darwin' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOVCS='' GOVERSION='go1.21.3' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='clang' CXX='clang++' CGO_ENABLED='1' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/zc/07hyz5qs2qg1b9ymjmyzqm140000gq/T/go-build2681715156=/tmp/go-build -gno-record-gcc-switches -fno-common'

Expected output

Expected Location to be configured. Is this the right way to configure a location with VPN credentials? VPN was configured correctly. Activation is not done as part of the test code. The same config is successful via postman.

Actual output

Error configuring location:FAILED: POST, https://zsapi.zscalerbeta.net/api/v1/locations, 400, 400 , {"message":"Request body is invalid."}, api responded with code: 400

Code demonstrating the issue

func TestZiaLocation(t *testing.T) {
        // Details hidden for security reasons. NewZiaClient is a wrapper around ZIA service.
    ziaClient, _ := NewZiaClient(nil) 
    vpnCreds := vpn.VPNCredentials{
        FQDN:        "vpn57@companydomain.com",
        Type:         "UFQDN",
        PreSharedKey: "Sample123!",
    }
    configuredVpn, _, err := ziaClient.vpnc.Create(&vpnCreds)
    if err != nil {
        t.Fatalf("Error creating vpn credentials: %v", err)
    }
    loc := lm.Locations{
        Name: "Location57",
        VPNCredentials: []lm.VPNCredentials{
            {
                ID:   configuredVpn.ID,
                FQDN: vpnCreds.FQDN,
                Type: vpnCreds.Type,
                Location: []lm.Location{
                    {
                        Name: "Location57",
                    },
                },
            },
        },
    }
    configuredLoc, err := ziaClient.ls.Create(&loc)
    if err != nil {
        t.Errorf("Error configuring location:%v", err)
    }
    glog.Infof("Configured location: %v", configuredLoc)
}

Steps to reproduce

By running the sample code.

References

NA

gauravv9 commented 6 months ago

It seems Location is not required to be set in VPNCredentials. Without it, it works.

willguibr commented 6 months ago

@gauravv9 Please take a look at the test suite for vpn credential creation here For context: A location is not required when creating a VPN credential; however, a VPN Credential may be required when creating a location. Please refer to the ZIA API Swagger documentation here Thanks

gauravv9 commented 6 months ago

Thanks @willguibr.