- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
The UsageApi has a pOSTUsage method. In the signature there is only a String parameter named contentType.
How do I attach the CSV Data?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
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>>() {});
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
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.
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
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>>() {});
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
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