2

I am using this call in AMPScript To retrieve: https://www.exacttargetapis.com/data/v1/customobjectdata/key/[Data extension key]?$filter= Name%20eq%20'Test'

To insert: https://www.exacttargetapis.com/hub/v1/dataevents/key:[Data extension key]/rowset

Body:
  [{ 
   "keys":{
          "FA_Response_ID": "1234567"
          },
    "values":{
    "Email":"abc@gmail.com"
     "Subscriber_Key":"abc@gmail.com",
      "TS_Status_Message":"NEW_MSG" 
          }
     }]

both calls are working in POSTMAN but not in AMPScript Getting error while insert call "JSON Deserialization Exception: Location Unknown"

  • 1
    You could add your non working AMPScript (without customer values etc). This would help us to figure out what is wrong in your ampscript – Johannes Schapdick Apr 10 at 5:40
  • @Vasudha You should make sure your using the same account which you asked the question under to make edits to it. Otherwise 2+ people need to approve your edits. See Merging Accounts – battery.cord Apr 10 at 13:38
1

I don't believe it's possible to include your access token with AMPscript's HTTPGet when requesting the GET route to retrieve DE rows (i.e., you'll need to momentarily step into SSJS), but here's one approach...

External Key: xyz789
┌───────────────┬──────┐
│ EmailAddress  │ User │
├───────────────┼──────┤
│ foo@bar.baz   │ foo  │
├───────────────┼──────┤
│ qux@quux.quuz │ qux  │
└───────────────┴──────┘

...

%%[
set @creds =
'{
  "clientId": "abc123",
  "clientSecret": "456def"
}'
set @reqTokenStatus = HTTPPost(
  'https://auth.exacttargetapis.com/v1/requestToken',
  'application/json',
  @creds,
  @reqTokenResponse
)
set @accessToken = RegExMatch(
  @reqTokenResponse,
  '"accessToken"\s*?:\s*?"(.+?)"',
  1,
  'None'
)



if (@reqTokenStatus == 200) and (Length(@accessToken) > 0) then
  set @dataExtKey = 'xyz789'
  set @payload =
'[
  {
    "keys": {
      "EmailAddress": "foo@bar.baz"
    },
    "values": {
      "User": "foo"
    }
  },
  {
    "keys": {
      "EmailAddress": "qux@quux.quuz"
    },
    "values": {
      "User": "qux"
    }
  }
]'

  set @reqInsertRowsStatus = HTTPPost(
    Concat('https://www.exacttargetapis.com/hub/v1/dataevents/key:', @dataExtKey, '/rowset'),
    'application/json',
    @payload,
    @reqInsertRowsResponse,
    'Authorization', Concat('Bearer ', @accessToken)
  )

  if (@reqInsertRowsStatus == 200) then
    Output(Concat('Rows inserted:<br>', @reqInsertRowsResponse, '<br><br>'))

    set @retrieveRowsFilter = Concat('$filter=', URLEncode("User eq 'Foo'", 0, 1))
    set @retrieveRowsRoute = Concat('https://www.exacttargetapis.com/data/v1/customobjectdata/key/', @dataExtKey, '/rowset/?', @retrieveRowsFilter)
    set @reqRetriveRowsResponse = ''
]%%
<script runat="server">
Platform.Load('Core', '1');
var accessToken = Variable.GetValue('@accessToken');
var retrieveRowsRoute = Variable.GetValue('@retrieveRowsRoute');
var headerNames = ['Authorization'];
var headerValues = [('Bearer ' + accessToken)];
var reqRetriveRowsResponse = HTTP.Get(retrieveRowsRoute, headerNames, headerValues);
Variable.SetValue('@reqRetriveRowsResponse', reqRetriveRowsResponse.Content);
</script>
%%[
    Output(Concat('Rows retrieved:<br>', @reqRetriveRowsResponse))
  endif

/* unable to complete request */

endif
]%%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.