Sample code for 30+ languages & platforms
Swift Requires Chilkat v11.0.0+

Peoplevox SaveData

See more Peoplevox Examples

Demonstrates how to call the Peoplevox SaveData SOAP method. This example adds a new carrier (DHL) to the system.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    //  Sends a POST that looks like this:

    //  	POST /PEOPLEVOX_CLIENT_ID/resources/integrationservicev4.asmx HTTP/1.1
    //  	Content-Type: text/xml;charset=UTF-8
    //  	SOAPAction: http://www.peoplevox.net/SaveData
    //  	Content-Length: (automatically computed and added by Chilkat)
    //  	Host: qac.peoplevox.net
    //  
    //  	<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:peop="http://www.peoplevox.net/">
    //  	   <soap:Header>
    //  	      <peop:UserSessionCredentials>
    //  	         <peop:UserId>PEOPLEVOX_USER_ID</peop:UserId>
    //  	         <peop:ClientId>PEOPLEVOX_CLIENT_ID</peop:ClientId>
    //  	         <peop:SessionId>PEOPLEVOX_SESSION_ID</peop:SessionId>
    //  	      </peop:UserSessionCredentials>
    //  	   </soap:Header>
    //          <soap:Body>
    //            <peop:SaveData>
    //               <peop:saveRequest>
    //                  <peop:TemplateName>Carriers</peop:TemplateName>
    //                  <peop:CsvData>CSV_DATA</peop:CsvData>
    //                  <peop:Action>0</peop:Action>
    //               </peop:saveRequest>
    //            </peop:SaveData>
    //         </soap:Body>
    //  	</soap:Envelope>
    //  

    //  Notice that a UserId is needed here.  This is different than the username required for Peoplevox authentication.
    //     The UserId for the admin account is 1.
    //      
    let sbSoapXml = CkoStringBuilder()!
    sbSoapXml.append(value: "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n")
    sbSoapXml.append(value: "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:peop=\"http://www.peoplevox.net/\">\r\n")
    sbSoapXml.append(value: "   <soap:Header>\r\n")
    sbSoapXml.append(value: "      <peop:UserSessionCredentials>\r\n")
    sbSoapXml.append(value: "         <peop:UserId>PEOPLEVOX_USER_ID</peop:UserId>\r\n")
    sbSoapXml.append(value: "         <peop:ClientId>PEOPLEVOX_CLIENT_ID</peop:ClientId>\r\n")
    sbSoapXml.append(value: "         <peop:SessionId>PEOPLEVOX_SESSION_ID</peop:SessionId>\r\n")
    sbSoapXml.append(value: "      </peop:UserSessionCredentials>\r\n")
    sbSoapXml.append(value: "   </soap:Header>\r\n")
    sbSoapXml.append(value: "   <soap:Body>\r\n")
    sbSoapXml.append(value: "      <peop:SaveData>\r\n")
    sbSoapXml.append(value: "         <peop:saveRequest>\r\n")
    sbSoapXml.append(value: "            <peop:TemplateName>Carriers</peop:TemplateName>\r\n")
    sbSoapXml.append(value: "            <peop:CsvData>CSV_DATA</peop:CsvData>\r\n")
    sbSoapXml.append(value: "            <peop:Action>0</peop:Action>\r\n")
    sbSoapXml.append(value: "         </peop:saveRequest>\r\n")
    sbSoapXml.append(value: "      </peop:SaveData>\r\n")
    sbSoapXml.append(value: "   </soap:Body>\r\n")
    sbSoapXml.append(value: "</soap:Envelope>")

    let sbCsvData = CkoStringBuilder()!
    sbCsvData.append(value: "Name,Reference\r\n")
    sbCsvData.append(value: "DHL,D0001")
    var numReplacements: Int = sbSoapXml.replace(value: "CSV_DATA", replacement: sbCsvData.getAsString()).intValue

    let req = CkoHttpRequest()!
    req.httpVerb = "POST"
    req.sendCharset = true
    req.charset = "utf-8"
    req.addHeader(name: "Content-Type", value: "text/xml")
    req.addHeader(name: "SOAPAction", value: "http://www.peoplevox.net/SaveData")
    req.path = "/PEOPLEVOX_CLIENT_ID/resources/integrationservicev4.asmx"
    success = req.loadBody(fromString: sbSoapXml.getAsString(), charset: "utf-8")

    let http = CkoHttp()!
    http.followRedirects = true

    let resp = CkoHttpResponse()!
    success = http.httpSReq(domain: "qac.peoplevox.net", port: 443, ssl: true, request: req, response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    //  We should expect a 200 response if successful.
    if resp.statusCode.intValue != 200 {
        print("Response StatusCode = \(resp.statusCode.intValue)")
        print("Response StatusLine: \(resp.statusLine!)")
        print("Response Header:")
        print("\(resp.header!)")
        print("\(resp.bodyStr!)")
        return
    }

    let xmlResponse = CkoXml()!
    success = xmlResponse.load(xmlData: resp.bodyStr)
    print("\(xmlResponse.getXml()!)")

    //  A successful response is shown below.
    //  To parse a successful response:
    var reference: String? = xmlResponse.chilkatPath(cmd: "soap:Body|SaveDataResponse|SaveDataResult|Statuses|IntegrationStatusResponse|Reference|*")
    print("Reference = \(reference!)")
    var status: String? = xmlResponse.chilkatPath(cmd: "soap:Body|SaveDataResponse|SaveDataResult|Statuses|IntegrationStatusResponse|Status|*")
    print("Status = \(status!)")

    //  <?xml version="1.0" encoding="utf-8" ?>
    //  <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    //      <soap:Body>
    //          <SaveDataResponse xmlns="http://www.peoplevox.net/">
    //              <SaveDataResult>
    //                  <ResponseId>0</ResponseId>
    //                  <TotalCount>1</TotalCount>
    //                  <Detail />
    //                  <Statuses>
    //                      <IntegrationStatusResponse>
    //                          <Reference>D0001</Reference>
    //                          <Status>Success</Status>
    //                          <LineNo>0</LineNo>
    //                      </IntegrationStatusResponse>
    //                  </Statuses>
    //                  <ImportingQueueId>0</ImportingQueueId>
    //                  <SalesOrdersToDespatchIds />
    //              </SaveDataResult>
    //          </SaveDataResponse>
    //      </soap:Body>
    //  </soap:Envelope>

}