Consume api with input as .csv file

Hey,

Can anyone please help me consuming an external api with with input as .csv file .
I have created the csv file using the forge component (CSVUtil). I am not sure how to pass it to the service. 

Thanks,
Angha

Hi Anagha.

Have you checked this one-page help to call web services and APIs?

I guess you simply need to send the CSV to the binary/text input field.


Hi Toto,

Yes the external API does use Content-Type as Multipart/Form-Data. I also downloaded the component you just shared.
Do we have any sample for this particular forge component? It would be great help.


Thanks,
Anagha


Yes, the plugin is a little bit tricky.

I'm sorry I cannot provide you with oml (my Webservice is private use).


First, create local variable using the structure from the plugin (Part). You need Part variable and List of Part variable (see image below)


This is how to call the web service


You need to assign the part variable with component that you need (here in my example is image)

Then append it to list of part variable


Put the MultipartFormDataCreate

Boundary = hardcoded 

SyntaxEditor Code Snippet

----WebKitFormBoundary7MA4YWxkTrZu0gW



Then on the web service consume

with content-type hardcoded

SyntaxEditor Code Snippet

"multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"

Thanks For the reply Toto.

I used the component and what I got the response after converting it from binary to text is the below.

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="File"
Content-Type: multipart/form-data

Id,FName,LName,Email
1, Anagha, Chikate, achikate@xyz.com
2,Paree,Bansal,pbansal@xyz.com

------WebKitFormBoundary7MA4YWxkTrZu0gW--


When I hit the service with this file in request text, its giving me 400 error.

Am I missing on something?


Thanks,

Anagha 

Anagha Chikate wrote:

Thanks For the reply Toto.

I used the component and what I got the response after converting it from binary to text is the below.

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="File"
Content-Type: multipart/form-data

Id,FName,LName,Email
1, Anagha, Chikate, achikate@xyz.com
2,Paree,Bansal,pbansal@xyz.com

------WebKitFormBoundary7MA4YWxkTrZu0gW--


When I hit the service with this file in request text, its giving me 400 error.

Am I missing on something?


Thanks,

Anagha 


Id,FName,LName,Email
1, Anagha, Chikate, achikate@xyz.com
2,Paree,Bansal,pbansal@xyz.com

is this the file content or there is 3 parameter on webservice body ?

can you provide postman screenshot about your webservice (please blur the address, I just need to see the parameter)


Toto wrote:

Anagha Chikate wrote:

Thanks For the reply Toto.

I used the component and what I got the response after converting it from binary to text is the below.

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="File"
Content-Type: multipart/form-data

Id,FName,LName,Email
1, Anagha, Chikate, achikate@xyz.com
2,Paree,Bansal,pbansal@xyz.com

------WebKitFormBoundary7MA4YWxkTrZu0gW--


When I hit the service with this file in request text, its giving me 400 error.

Am I missing on something?


Thanks,

Anagha 


Id,FName,LName,Email
1, Anagha, Chikate, achikate@xyz.com
2,Paree,Bansal,pbansal@xyz.com

is this the file content or there is 3 parameter on webservice body ?

can you provide postman screenshot about your webservice (please blur the address, I just need to see the parameter)


Hey,

These are not the parameters, this is my csv content passed in body.


If you cannot provide postman screenshot, can you provide the action ?

hey Toto,



PostEmployee is the external rest service that I am calling, which is Post type with request set to binary type.

Hey, 

Find the attached test oml. 

Thanks,
Anagha

Hi Anagha,


In the PostEmployee, contenttype should filled with 

"multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"

In my case, this is the problems

Hi,

Changing the content type didnt help.

Please find the attached test oml.


Thanks,

Anagha.

Hi Anagha,


I'm waiting for the upload complete :D It seems there is a slowdown in the forum.

Yes I see that, I uploaded it twice. Please see the previous file in conversion. 

Still not updated, still uploading

Anagha Chikate wrote:

Hey, 

Find the attached test oml. 

Thanks,
Anagha


Uploaded in here :-D

Ups, my mistake sorry

Let me check it.


And this is the translation from your code to the postman

is this correct ?

key : employees.csv

filename and content : employees.csv


This will translate as key

I guess that is correct. 

I am hitting service A (that I have exposed) and in that service I am consuming service B (PostEmployee in the test oml), to which I want to send the employee.csv.


Anagha Chikate wrote:

I guess that is correct. 

I am hitting service A (that I have exposed) and in that service I am consuming service B (PostEmployee in the test oml), to which I want to send the employee.csv.



But its very uncommon that key is filename.

You said you expose the API? Using outsystems?

Usually expose using outsystems resulted in json type (raw json in postman)