1

I am working with AWS REST API. I am trying to invoke glue job via REST API. For that, I need to pass arguments as JSON object. And withing this json object, I should pass python dictionary as JSON value. This is the request body,

   {
    "Arguments":{
    "jobParameter":"{
  'key1':'keyname=subvalue',
  'key2':'value2'
}"

},
    "JobName":"jobname"
    }

python dictionary = { 'key1':'keyname=subvalue', 'key2':'value2' }

When I test the API by giving this as input, it gives an error,

{ "__type": "SerializationException" }

Please can anyone help with this?

Dinuka
  • 37
  • 1
  • 9
  • This link suggests using escape characters for the quotes inside jobParameter. https://stackoverflow.com/questions/48211335/serializationexceptionstart-of-structure-or-map-found-where-not-expected-api-gs – Lucas Raza Mar 31 '20 at 16:19
  • Thanks for the response. But that also gives the same error. And my header Content-Type is 'application/x-amz-json-1.1'. is the issue with this? – Dinuka Mar 31 '20 at 16:52
  • I check this by adding Content-Type as 'application/json'. It also gives error. – Dinuka Mar 31 '20 at 16:59

2 Answers2

2

I think it's not recognizing as a valid JSON. Try send something diferente as parameter of jobParameter to test.

  • I tried with the string value (not python dictionary). it invokes glue job.But since it is wrong input, glue job is failing with an error. To invoke glue job, I should pass python dictionary as jobParameter. – Dinuka Mar 31 '20 at 17:34
  • 1
    Alright, try to escape now with two single quotes ''. like this: "jobParameter":"{ ''key1'':''keyname=subvalue'', ''key2':'value2''}" – Rafael Ribeiro Mar 31 '20 at 18:40
-1

This problem often occur when a json item has as value another dict. Another solution is to pass it as a json.dumps()

import json
body = {
    "Arguments":{
    "jobParameter":{
        'key1':'keyname=subvalue',
        'key2':'value2'
        }    
    },
    "JobName":"jobname"
    }
body_parsed = json.dumps(body)

then in your request, you should do:

requests.post(url=url, body=body_parsed , headers=headers)

L F
  • 548
  • 1
  • 7
  • 22