Question

im doing an api for pin payment in pin.net.au and i encounter some errors like what you see in the bottom

`@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder'`,` version='0.5.0-RC2' )
    import groovyx.net.http.*
    import groovyx.net.http.HttpResponseDecorator
    import groovyx.net.http.RESTClient
    import static groovyx.net.http.ContentType.*
    import groovyx.net.http.HttpResponseException
    import groovy.swing.SwingBuilder
    import javax.swing.JFrame
    import wslite.http.auth.*
    class Customers {

        Customers(){
            def rst = new RESTClient( 'https://test-api.pin.net.au/1/')
    rst.auth.basic 'mySecretKey',''
            def res = rst.post( path: 'customers'){
                type ContentType.XML
                xml {
                    cards{
                        email('pk_qTj9Umqmlf3o7lfa6F9nWw')
                        card[expiry_month]('12')
                        card[expiry_year]('2015')
                        card[cvc]('123')
                        card[name]('patrick pl')
                        card[address_line1]('23 frfds')
                        card[address_city]('Angeles')
                        card[address_postcode]('2009')
                        card[address_state]('ph')
                        card[address_country]('Philippines')

                    }
                }

            }

        }
        public static void main(String []args){

            new Customers()
        }
    }

when i run the code the error was

   May 12, 2014 1:07:35 PM org.apache.http.impl.client.DefaultRequestDirector handleResponse
    WARNING: Authentication error: Unable to respond to any of these challenges: {}
    Caught: groovyx.net.http.HttpResponseException: Authorization Required
    groovyx.net.http.HttpResponseException: Authorization Required
        at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:240)
        at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:475)
        at groovyx.net.http.HTTPBuilder.post(HTTPBuilder.java:335)
        at groovyx.net.http.HTTPBuilder$post.call(Unknown Source)
        at PinPayment.Customers.<init>(Customers.groovy:16)
        at PinPayment.Customers.main(Customers.groovy:39)

how could i make the authentication work for the code to be runable?? here is the link for the docs pin.net.au

Was it helpful?

Solution 2

i found the right code for that particular api here def http = new RESTClient('https://test-api.pin.net.au/1/') http.headers['Authorization'] = 'Basic '+"tWqZl0MHsg5nUQdB6czrDQ:".getBytes('iso-8859-1').encodeBase64()

OTHER TIPS

Document indicates it requires basic HTTP authn.

Calls to the Pin Payments API must be authenticated using HTTP basic authentication, with your API key as the username, and a blank string as the password.

Therefore:

def rst = new RESTClient( 'https://test-api.pin.net.au/1/' )
rst.auth.basic 'secretAPIKeyHereAsString', ''
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top