I'm a bit late to the party, but here's my two cents: Create a useful script that lets you send stuff to the API as a testbed. Here's some code I use to talk to Freshdesk:

#!/usr/bin/perl use strict; use warnings; # 2018-0425: Test script to access the Freshdesk API. ... use LWP::UserAgent; use JSON; use Data::Dumper; use utf8; # Path to authentication module ... { my $ua = LWP::UserAgent->new; my $headers = $ua->default_headers; $ua->default_header( 'Accept', 'application/json' ); $ua->default_header( 'Accept-Charset', 'UTF-8' ); $headers->authorization_basic( $Auth::User, $Auth::Password ); binmode STDOUT, ":utf8"; foreach my $arg (@ARGV) { # 2018-0426: If it's a query, then that stuff has to be within # double quotes. The command line processing throws them out. if ( $arg =~ /^(.+query=)(.+)/ ) { $arg = join ( '', $1, '"', $2, '"' ); } my $this_url = join ( '', $Auth::Url, $arg ); print "GET $this_url ..\n"; my $response = $ua->get($this_url); if ( $response->is_success ) { my $result = decode_json( $response->content ); print Dumper ($result); if ( exists ( $result->{'description_text'} ) ) { my $as_is = $result->{'description_text'}; print "Text as-is: $as_is.\n"; } } else { print "Ugh, not a good response.\n"; print "Response:\n" . " " . $response->status_line . "\n" . " " . $response->message . "\n" . " " . $response->content . "\n"; } } }

I don't know if this is applicable to your situation, but it's a way of handling good and bad responses as a way of testing what works and what doesn't with an API. I've used this approach with Freshdesk, BigCommerce and Stripe. You'll probably find that some adjustments are necessary.

Also note that I've put my authentication (URL, user and password) into a separate module .. that's a really good idea, in case you end up copying and pasting your code on-line. That module is in another directory that's not under source control -- because there's no reason to put that kind of sensitive information into version control.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.


In reply to Re: 400 bad request curl post by talexb
in thread 400 bad request curl post by bigup401

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.