I’m trying to use the netlify API to create a webhook and I’m running up against a wall. The following curl request returns an error and I can’t decipher what it means or how to fix it:
{"url":["is not a valid URL"]}. I get this error regardless of what I put in the body of the request (including an empty request) and I don’t know how to get Netlify to accept my POST.
Hi, @jt.white. My best recommendation would be to make these hooks in the web UI and then look at the browser devtools to see how the data is formatted. When I see this, I see this format:
Also, please note, for a HTTP or HTTPS URL to be a URL it must have at least a path of /.
This is a URL: http://example.com/
This is not a URL: http://example.com
The second example has no path so it isn’t a valid URL.
The HTTP specification always requires a least a path of /. It is not optional. Browsers won’t always show it but it is always there. (Browsers often hide or otherwise distort the reality of what they do. For example, Chrome now hides the www before apex domains regardless of if it is there or not.)
Please let us know if there are other questions about this.
Thanks for your quick response. My problem was indeed that my payload was shaped incorrectly - using the proposed shape does make it through the API. I actually had a second issue where my CuRL request didn’t have a “Content-Type: application/json” header, which explained why I would get an error regardless of payload.
As a small FYI, in case you encounter this issue with someone else - it looks like the “url” part of the “data” object doesn’t get validated at all. I can send through something like “this is not a url” and the API will accept it.