Happy Business Starts Here

Advanced Tutor

How do I upload the usages with the java rest client?

The UsageApi has a pOSTUsage method. In the signature there is only a String parameter named contentType.

How do I attach the CSV Data?

Tags (2)
4 REPLIES 4
Highlighted
Zuora Support

Re: How do I upload the usages with the java rest client?

Hi,

 

Could you please let me know what tool you are using for your REST calls?

I am using POSTMAN and where you can attached usage file in body, I have attached a screenshot below for reference.

 

Screen Shot 2017-01-24 at 4.40.30 PM.png






If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Tags (1)
Advanced Tutor

Re: How do I upload the usages with the java rest client?

I can test the call with curl. It works fine. 

 

I want to integrate it into our application with your java library.

https://github.com/zuora/rest-java-client

 

The service class for the usage upload is called UsageApi.

Advanced Tutor

Re: How do I upload the usages with the java rest client?

 

Fixed it myself. I implemented it with a spring RestTemplate call.

In case someone has the problem, here is the code:

 

public class FileMessageResource extends ByteArrayResource {

	private final String filename;

	public FileMessageResource(final byte[] byteArray, final String filename) {
		super(byteArray);
		this.filename = filename;
	}

	@Override
	public String getFilename() {
		return filename;
	}
}




final
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", new FileMessageResource(..., ...));

final MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("apiAccessKeyId", ...);
headers.add("apiSecretAccessKey", ...);
final HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
final ResponseEntity<Map<String, String>> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, new ParameterizedTypeReference<Map<String, String>>() {});

 

Community Manager

Re: How do I upload the usages with the java rest client?

Thanks for sharing your solution with the community, @magicline!

 

Lana

 

 


Lana Lee | Senior Community Manager and Strategist
"A little consideration, a little thought for others, makes all the difference." —A. A. Milne