Buzz API

Where to specify _token in <batch> commands?

Follow
Answered
Matthew Marichiba

The DLAP API docs for issuing batch commands doesn't seem to state explicitly where to place the _token if I already have an authenticated session token, and the example doesn't show the token at all. Do I stick a _token attribute on the <batch> element, or do I have to repeat it in each of the <request>s? Or do you recommend including it as part of the URL query string, out of the POST body?

An example would be nice. (JSON preferred. :)  Thanks!

Comments (8)

Sort by
Matthew Marichiba

Oh, and is there an upper bound on how many requests can be stuck into a single batch command? I have a couple situations where I look up over 1000 users and courses at a time. Can I pack thousands into one batch request, or do I need to bundle them in sub-groups? 

0 Comment actions Permalink
Brad Marshall
  • Agilix team member

You would pass it as the "query-string" parameter. 

For example: 

Query-String

https://api.agilixbuzz.com/cmd?_token=~XXXX

Post Data

<batch>
  <request cmd="restoreuser" userid="id" />
  <request cmd="restoreuser" userid="id" />
  <request cmd="restoreuser" userid="id" />
</batch>
1 Comment actions Permalink
Brad Marshall
  • Agilix team member

You don't have to bundle them, but I personally do so that I know there is progress occurring. Otherwise, the request could take a long time. 

But I normally do this in 1-2,000 chunks. 

0 Comment actions Permalink
Darren Severino

Getting items is one thing but updating them is another. If I try to update more than ~1000 items (~500 during the day) I'll get a "504 Gateway Timeout". Merge courses is the really frustrating one. If I have a ton of changes to merge I can't get one to finish without calling it multiple times. This is why I've never used the batch function, I'll just call each individual command. No need to add the additional layer of complexity. I wish you could submit things as jobs, like inferroles.

0 Comment actions Permalink
Luke Rebarchik

A json example would help me. The docs indicate such a thing is possible, but nothing I've tried has worked.

0 Comment actions Permalink
Brad Marshall
  • Agilix team member

Howdy, Luke!

Example JSON example for a batch request:

{
"batch":{
"request":[
{
"cmd":"getentitywork2",
"outstanding":true,
"include":"user,course",
"entityid":"123"
},
{
"cmd":"getentitywork2",
"outstanding":true,
"include":"user,course",
"entityid":"456"
},
{
"cmd":"getentitywork2",
"outstanding":true,
"include":"user,course",
"entityid":"789"
}
]
}
}
1 Comment actions Permalink
Luke Rebarchik

That helps, but I'm still inches from the goal. Maybe I'm misunderstanding something. Here's my javascript ala jquery:

 

//!!! I've repaired it!!! I was silly and forgot to JSON.stringify!

$.ajax({
  url:"https://gls.agilix.com/cmd/?_format=json&_token="+token,
  type:"POST",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  data: JSON.stringify({
    batch:{
      request:[
        {
          cmd:"listcourses",
          domainid:domain1,
          limit:5000
        },{
          cmd:"listcourses",
          domainid:domain2,
          limit:5000
        }
      ]
    }
  })
});

What got from the above before I JSON.stringified it is:

{
"response":{
"code":"BadRequest",
"message":"No DLAP command specified.",
"errorId":"8a6aa2ad069e457a9dae0fd3c22f7909"
}
}
0 Comment actions Permalink
Matthew Marichiba

I think there's an unnecessary "/" in between the URL & your query parameters. 

Try: https://gls.agilix.com/cmd?_format=json&_token=...

Nothttps://gls.agilix.com/cmd/?_format=json&_token=...

 

That's the form that's working for me.

0 Comment actions Permalink
Please sign in to leave a comment.