These are chat archives for ushahidi/Community

5th
Aug 2017
azizfall
@azizfall
Aug 05 2017 20:04
Dear @ushbot I am trying to embed an image into a post on my ushahidi deployment by solely using the API, but I am unsure as how to do this, since the user post API does not include an image field. I tried uploading an image on the media section of the API using postman but I get the following error
Screen Shot 2017-08-05 at 4.01.01 PM.png
will anyone please help me with this, I will extremely appreciate it , thank you in advanced
Romina Suarez
@rowasc
Aug 05 2017 20:27
@azizfall Hey. I just tried this, and you have to name your field "file" as far as I can tell. That will give you a valid response with a media id. You can then use that id to "link" the file to a post.
Sending a screenshot as reference, just in case.
Disclaimer: this is literally the first time I tried this in Ushahidi, use my advice at your own discretion.
Screen Shot 2017-08-05 at 5.24.00 PM.png
Romina Suarez
@rowasc
Aug 05 2017 20:59

You can then use that id to "link" the file to a post

In the field where you are expecting the image, you can use the id returned by the media endpoint
ie: I have a media_test field in my local environment where the returned ID is sent like this: "media_test":[5]

azizfall
@azizfall
Aug 05 2017 21:24
ok thanks that is actually very helpful, I thought in order to link an image to the post it had to be included as a form attribute in the values section of the post request, I just determined this by looking at the database on my API server but even so I dont know how I would add this field in to the post, any thoughts on this @rowasc would be very helpful
Romina Suarez
@rowasc
Aug 05 2017 22:15

I'm sending that value in a field inside the values section of the post request and I see the image just fine when I go to my local environment to check
Of course your field names will be different most likely, I'm just using the ones from the test suite.

This is my values object in the request, in case it's any help:
"values":{
"markdown":[
"ff"
],
"test_varchar":[
"ff"
],
"test_point":[
{
"lon":-94.710388,
"lat":54.876607
}
],
"date_of_birth":[
"2017-08-05T20:15:26.833Z"
],
"missing_date":[
"2017-08-05T20:15:26.833Z"
],
"last_location":[
"m"
],
"last_location_point":[
{
"lon":-94.710388,
"lat":54.876607
}
],
"media_test":[
5
]
},

azizfall
@azizfall
Aug 05 2017 22:26
ok thanks that's really helpful, hopefully I am not disturbing you in any way but I have three questions and I should stop asking questions, 1) how would add embedded vidoes, would you just add the link in the after the key field. 2) I dont see a key field in the form_attribute request it seems to give you a default one, how did you change it? 3) this is my last question I am getting the following error when I submit a request for form_stages
Screen Shot 2017-08-05 at 6.25.31 PM.png
even though form_id 2 already exist in my database
when i check it, I am sorry for all the questions but these should be my last set of questions, thank you for any help in advanced @rowasc I really appreciate it
Romina Suarez
@rowasc
Aug 05 2017 22:44

1) I never uploaded videos. I'd guess you need a post type supporting videos, though.
2) When you say "after the key field" , what do you mean ? I don't see a key field in your screenshots.
3) I think this might be because you don't have the correct content type header. Change "Raw" to application/json and let me know if that helps.

Also: You don't have to apologize for the questions !! I'm pretty sure I'll be asking questions myself later ha, I'm still learning this stuff myself.

FYI: I only have ~15minutes before I need to leave, but I'll be around tomorrow ,too.
Romina Suarez
@rowasc
Aug 05 2017 22:50
Screen Shot 2017-08-05 at 7.50.31 PM.png
azizfall
@azizfall
Aug 05 2017 23:08
key as in date_of_birth, media_test
the only keys I have on my database are location_default and message_location
3) I did change to application json but I still get the same problem
its weird since I see the form_id in my database