How to post data including images to kobotoolbox form using the Kobo API?

220 views Asked by At

so this is similar question to : How to post data to kobotoolbox form using the Kobo API?

but in my case, I want to post a form that includes one or multiple image files.

I'm trying to submit the requests through POSTMAN since I have multiple submissions to make from an old csv, based on these instructions: https://www.linkedin.com/posts/islamburcu_postman-kobo-kobotoolbox-activity-7012761732402065408-1R_L?utm_source=share&utm_medium=member_android

from that article, the request inside POSTMAN should be of the form:

Body:
{    
    "id": "aaaaaaaaaaaaaaaaaaa", // form ID from the kobo    
    "submission":       {         
        "q1": "{{q1}}" , // q1 is a question in the form  
        "meta": {           
            "instanceID": "uuid:{{_uuid}}" // uuid is the unique submission  in the form        
             }     
        } 
} 

Which as I understand, structures the link between my old csv and the form I am submitting to. So this seems straightforward enough for text based questions, but how to handle images?? Lets say q1 in the above is a "photo" type of question in kobo, in that case the data for each response in the csv will be the name of an image. In a folder next to the csv, I have all the corresponding images. How can I post the right image along with the JSON when I submit the forms?

I'm not really expert (at all) in all of this POST/GET type of requests, so sorry if the question isn't very clear. I will rephrase if needed as I get to understand better.

Thanks for your suggestions!

*update:

I tried converting the image to base64 and submitting that, so now my POSTMAN JSON looks like this:

{    
    "id": "aaaaaaaaaaaaaaaaaaa", // form ID from the kobo    
    "submission":       {         
        "q1": "{{q1}}" ,

        "image": "data:image/jpg;base64,/9j/4AAQSkZJx..............==",

        "meta": {           
            "instanceID": "uuid:{{_uuid}}"
             }     
        } 
} 

... which successfully submits, but when I click on the image icon inside kobotoolbox, nothing loads. If I look in the devtools, the icon is linked to https://kobo.humanitarianresponse.info/undefined and returning 404, compared to clicking on a working icon which links to https://kobo.humanitarianresponse.info/api/v2/assets/<_uuid>/data/<_id>/attachments/<unknown_id_9digit>/ and returns 200.

Any ideas what is wrong?

0

There are 0 answers