These are chat archives for request/request

13th
Feb 2015
joviwap
@joviwap
Feb 13 2015 11:00
hi there!
does anybody know how to send a post request with Content-Type: application/json
???
Gergo Szonyi
@szexigexi
Feb 13 2015 11:06
there is a json attribute in the options object
"json - sets body but to JSON representation of value and adds Content-type: application/json header. Additionally, parses the response body as JSON."
joviwap
@joviwap
Feb 13 2015 11:23
shoud I use the form field in options to send the data to the server?
simo
@simov
Feb 13 2015 11:24
form is for url encoded, json is for json, so it depends on what the server expects
joviwap
@joviwap
Feb 13 2015 11:25
thanks! I will test it
joviwap
@joviwap
Feb 13 2015 11:30
headers: {
Authorization: "Bearer pdsrjs4z6ezkv7kkgm3238ta"
Content-Type: "application/json"
User-Agent: "node-fuel/0.7.2"
json: Object
method: "POST"
uri: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
these are my call options
simo
@simov
Feb 13 2015 11:31
that's fine
joviwap
@joviwap
Feb 13 2015 11:31
I am doing the exact same call with postman and it works, but not throw nodejs
any guess
simo
@simov
Feb 13 2015 11:32
not all of the options should be inside the headers key
joviwap
@joviwap
Feb 13 2015 11:32
??
I can send you whole request information but it's quite long...
simo
@simov
Feb 13 2015 11:33
request.post('url',{auth:{bearer:''}, json:{}, headers:{'user-agent':''}})
joviwap
@joviwap
Feb 13 2015 11:34
I need to send it throw options parameter because I am using a middle library
my options are the object i sent before
simo
@simov
Feb 13 2015 11:35
{method:'POST', url:'', auth:{bearer:''}, json:{}, headers:{'user-agent':''}}
your options are wrong
joviwap
@joviwap
Feb 13 2015 11:36
url instead of uri?
simo
@simov
Feb 13 2015 11:36
it doesn't matter
either one should work
joviwap
@joviwap
Feb 13 2015 11:36
so, what is the mistake?
headers: {
Authorization: "Bearer pdsrjs4z6ezkv7kkgm3238ta",
Content-Type: "application/json",
User-Agent: "node-fuel/0.7.2"
},
json: {
keys: {...},
values: {...}
},
method: "POST",
uri: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
simo
@simov
Feb 13 2015 11:39
compared to what you posted above - not all of the options are inside the headers key
joviwap
@joviwap
Feb 13 2015 11:39
my previous paste was not well formated
simo
@simov
Feb 13 2015 11:39
use triple ` when you are pasting code blocks
joviwap
@joviwap
Feb 13 2015 11:39
ok
simo
@simov
Feb 13 2015 11:40
these options looks valid
joviwap
@joviwap
Feb 13 2015 11:42
{"headers":{"Content-Type":"application/json"},"uri":"/hub/v1/dataevents/a9537e24-a1b2-e411-b14c-38eaa791d005/rowset","json":{"keys":{"Email":"jovi5@email.com"},"values":{"Nombre":"Jovi5"}},"method":"POST","retry":true}
simo
@simov
Feb 13 2015 11:43
take a look at to the right of this textbox on how to format it
that looks weird
joviwap
@joviwap
Feb 13 2015 11:45
    "headers":{
        "User-Agent":"node-fuel/0.7.2",
        "Content-Type":"application/json",
        "Authorization":"Bearer eqtrrppw887amhwzr8mebcjt"
    },
    "uri":
    "https://www.exacttargetapis.com/hub/v1/dataevents/a9537e24-a1b2-e411-b14c-38eaa791d005/rowset",
    "json":{
        "keys":  {"Email":"jovi5@email.com"},
        "values":{"Nombre":"Jovi5"}
    },
    "method":"POST"
}
thats better
but still doesn't work
simo
@simov
Feb 13 2015 11:47
what's the error
joviwap
@joviwap
Feb 13 2015 11:48
{ 
    documentation: 'https://code.docs.exacttarget.com/rest/errors/500',
    errorcode: 0,
    message: 'Internal Server Error' 
}
simo
@simov
Feb 13 2015 11:48
oh that's nice :)
joviwap
@joviwap
Feb 13 2015 11:49
very nice...
but it works with postman
simo
@simov
Feb 13 2015 11:53
well apparently something isn't right, just double check what you are posting with postman and the developer docs
joviwap
@joviwap
Feb 13 2015 12:13
I found it...
the json had to be
[
    {
        "keys":  {"Email":"jovi5@email.com"},
        "values":{"Nombre":"Jovi5"}
    }
]
very good API by the way ¬_¬
Thank you very much for you help @simov
simo
@simov
Feb 13 2015 12:15
np