Hi Guys,
Im attempting to post to a rest api but not sure if im doing right with the header.
1) i get the token via the following (works ok)
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper
import groovy.json.JsonOutput
def getToken(user, pw) {
def http = new HTTPBuilder('http://incognito/authentication')
http.request(POST) {
requestContentType = ContentType.JSON
body = [username: user, password: pw]
response.success = { resp, JSON ->
token = JSON.get('IncognitoUms auth')
return token
}
response.failure = { resp ->
return "Request failed with status ${resp.status}"
}
}
}
2) posting with header
def addModem(key) {
def http = new HTTPBuilder('incognito/devices/')
oui = "test"
serial='test'
model = 'test'
productClass = 'test'
subscriberId = 'test'
manufacturer = 'test'
description = ''
requestBody = """{
"oui": "${oui}",
"productClass": "${productClass}",
"serial": "${serial}",
"subscriberId": "${subscriberId}",
"manufacturer": "${manufacturer}",
"description": "${description}",
"deviceModel": {
"id": "${model}"
}
}"""
headerRequest = """{"authorization": "IncognitoUms auth=${key}",
"content-type": "application/json}"""
http.request(PUT) {
requestContentType = ContentType.JSON
body = requestBody
header = headerRequest
response.success = { resp, JSON ->
token = JSON.get('IncognitoUms auth')
return token
}
response.failure = { resp ->
return "Request failed with status ${resp.status}"
}
}
} 2nd method getting 403 response.
Not sure where i can go with this, any help is much appreciated.
Cheers,
Pon