Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Synthetics API fails with 400


#1

I’m attempting to script the creation of a number of pings, labelling as I go. The various GET calls work but I get the following when attempting to label. I think the issue is with the Content-Type as the http builder automatically adds a default charset. Is this the case? If so, is there a valid charset I should use?

17:09:06.206 [main] DEBUG groovyx.net.http.JavaHttpBuilder - Request-URI(POST): https://synthetics.newrelic.com/synthetics/api/v4/monitors/e4596879-24ba-4a93-a4ba-909e9ffab317/labels
17:09:06.207 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Request-Header: Accept-Encoding -> [gzip, deflate]
17:09:06.207 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Request-Header: X-Api-Key -> []
17:09:06.207 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Request-Header: Content-Type -> [application/json; charset=utf-8]
17:09:06.704 [main] DEBUG g.net.http.JavaHttpBuilder.content - Request-Body(application/json): {“Environment”:“Demo”}
17:09:07.032 [main] DEBUG g.net.http.JavaHttpBuilder.content - Response-Body: {“errors”:[{“error”:“Labels may only include letters, numbers, hyphens, and underscores.”},{“error”:“Labels must be title cased.”}],“count”:2}
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Date -> Tue, 05 Nov 2019 06:09:06 GMT
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Content-Type -> application/json
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Transfer-Encoding -> chunked
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Connection -> keep-alive
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Proxied-By -> Service Gateway
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Content-Security-Policy -> frame-ancestors *.newrelic.com
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Cache-Control -> private, no-cache, no-store, max-age=0, must-revalidate
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Expires -> Fri, 01 Jan 1990 00:00:00 GMT
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Pragma -> no-cache
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Strict-Transport-Security -> max-age=31536000; includeSubdomains
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: X-Frame-Options -> Deny
17:09:07.033 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: content-encoding -> gzip
Caught: groovyx.net.http.HttpException: Bad Request
groovyx.net.http.HttpException: Bad Request
at groovyx.net.http.NativeHandlers.failure(NativeHandlers.java:69)
at groovyx.net.http.HttpBuilder$ResponseHandlerFunction.apply(HttpBuilder.java:2305)
at groovyx.net.http.JavaHttpBuilder$Action.lambda$execute$2(JavaHttpBuilder.java:168)
at groovyx.net.http.JavaHttpBuilder$ThreadLocalAuth.with(JavaHttpBuilder.java:331)
at groovyx.net.http.JavaHttpBuilder$Action.execute(JavaHttpBuilder.java:122)
at groovyx.net.http.JavaHttpBuilder.createAndExecute(JavaHttpBuilder.java:374)
at groovyx.net.http.JavaHttpBuilder.doPost(JavaHttpBuilder.java:389)
at groovyx.net.http.HttpObjectConfigImpl.nullInterceptor(HttpObjectConfigImpl.java:47)
at groovyx.net.http.HttpBuilder.post(HttpBuilder.java:732)
at groovyx.net.http.HttpBuilder.post(HttpBuilder.java:1391)
at groovyx.net.http.HttpBuilder$post$1.call(Unknown Source)
at au.com.wargh.devops.NewRelic$_run_closure4.doCall(NewRelic.groovy:65)
at au.com.wargh.devops.NewRelic.run(NewRelic.groovy:58)


#2

@michael.rutherfurd1

I see that the response body returned reports:

Response-Body: {“errors”:[{“error”:“Labels may only include letters, numbers, hyphens, and underscores.”},{“error”:“Labels must be title cased.”}],“count”:2}

To start, can you confirm that the labels you are trying to apply conforms to the guidelines provided here:


#3

The request body is a basic JSON block. Both the label and the value are Titlecased and contain only alphabetic chars.

Request-Body(application/json): {“Environment”:“Demo”}


#4

@michael.rutherfurd1

This endpoint accepts labels just a string, for example:

curl -v -X POST -H 'X-Api-Key:xxxxxxxx' -H 'Content-Type: application/json'  https://synthetics.newrelic.com/synthetics/api/v4/monitors/xxxxxxxx/labels -d 'Category:Label' 

In our docs it appears the use of the curly braces to signify “insert your value here” can be interpreted as JSON. The Content-Type header being application/json doesn’t make this clear either, although the request does work with this header. We’ll be sure to review this.


#5

Ah, that’s it. Thank you