JavaSDK throws msgpack error with purestake.io V2 api endpoint

Hi,

I am using Java SDK to interact with Algorand Node. Some of the use cases are Transfer Algo, Create App etc.
My code is working fine with my local Algorand node on testnet.

But when I try to do the same using purestake.io api endpoint, it’s throwing “msgpack decode” error from the node.

Here’s the response message I am getting for purestake endpoint for a transfer call:

{
“message” : “msgpack decode error [pos 1]: only encoded map or array can be decoded into a struct”
}

Purestake api endpoint: https://testnet-algorand.api.purestake.io/ps2

BTW, I am encoding using message pack before posting the transaction.
Sample code:
byte encodedTxBytes = Encoder.encodeToMsgPack(signedTxn);
logListener.info(“Posting transaction to the network …”);
Response postTransactionsResponse = client.RawTransaction().rawtxn(encodedTxBytes).execute();

Any pointer ?

Thanks in advance.

Take a look here at the Java examples posted - https://github.com/PureStake/api-examples/tree/master/java-examples/v2 - there is a v2 submission example as well.

Is there a reason you are message packing ahead of time? That is not the expected format for the POST (x-binary).

1 Like

@Tim Thanks for the link.

It works now. I didn’t have Content-type header in my call.

String txHeaders = ArrayUtils.add(headers, “Content-Type”);
String txValues = ArrayUtils.add(values, “application/x-binary”);

1 Like

Glad to hear!

In the Java V1 that was fixed at some point to automatically include the necessary content-type header, but left out of V2.

If this happens on servers other than Purestake, here is the code to add appropriate headers:

        // Submit the transaction to the network
        byte[] encodedTxBytes = Encoder.encodeToMsgPack(signedTxn);
        String[] headers = {"Content-Type"};
        String[] values = {"application/x-binary"};
        Response < PostTransactionsResponse > rawtxresponse = client.RawTransaction().rawtxn(encodedTxBytes).execute(headers, values);
1 Like